Skip to content

Commit

Permalink
#1447. On preInsert object in TimestampableBehavior we get different…
Browse files Browse the repository at this point in the history
… dataTime. (#1457)

For solve this situation we need available set same time on create and update field.
  • Loading branch information
eugenekurasov authored and marcj committed Feb 12, 2018
1 parent 80cda8a commit 3dde104
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ public function preUpdate($builder)
*/
public function preInsert($builder)
{
$script = '';
$script = '$time = time();
$highPrecision = \\Propel\\Runtime\\Util\\PropelDateTime::createHighPrecision();';

if ($this->withCreatedAt()) {
$valueSource = strtoupper($this->getTable()->getColumn($this->getParameter('create_column'))->getType()) === 'INTEGER'
? 'time()'
: '\\Propel\\Runtime\\Util\\PropelDateTime::createHighPrecision()'
? '$time'
: '$highPrecision'
;
$script .= "
if (!\$this->isColumnModified(" . $this->getColumnConstant('create_column', $builder) . ")) {
Expand All @@ -117,8 +118,8 @@ public function preInsert($builder)

if ($this->withUpdatedAt()) {
$valueSource = strtoupper($this->getTable()->getColumn($this->getParameter('update_column'))->getType()) === 'INTEGER'
? 'time()'
: '\\Propel\\Runtime\\Util\\PropelDateTime::createHighPrecision()'
? '$time'
: '$highPrecision'
;
$script .= "
if (!\$this->isColumnModified(" . $this->getColumnConstant('update_column', $builder) . ")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ public function testPreSave()
{
$t1 = new Table2();
$this->assertNull($t1->getUpdatedAt());
$tsave = time();
$t1->save();
$this->assertTimeEquals($tsave, $t1->getUpdatedAt('U'), 'Timestampable sets updated_column to time() on creation');
$this->assertEquals(
$t1->getUpdatedAt(),
$t1->getCreatedAt(),
'Timestampable sets updated_column same created_column on creation'
);
sleep(1);
$t1->setTitle('foo');
$tupdate = time();
Expand Down

0 comments on commit 3dde104

Please sign in to comment.