Skip to content

Commit 3dde104

Browse files
eugenekurasovmarcj
authored andcommitted
#1447. On preInsert object in TimestampableBehavior we get different dataTime. (#1457)
For solve this situation we need available set same time on create and update field.
1 parent 80cda8a commit 3dde104

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Propel/Generator/Behavior/Timestampable/TimestampableBehavior.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,13 @@ public function preUpdate($builder)
102102
*/
103103
public function preInsert($builder)
104104
{
105-
$script = '';
105+
$script = '$time = time();
106+
$highPrecision = \\Propel\\Runtime\\Util\\PropelDateTime::createHighPrecision();';
106107

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

118119
if ($this->withUpdatedAt()) {
119120
$valueSource = strtoupper($this->getTable()->getColumn($this->getParameter('update_column'))->getType()) === 'INTEGER'
120-
? 'time()'
121-
: '\\Propel\\Runtime\\Util\\PropelDateTime::createHighPrecision()'
121+
? '$time'
122+
: '$highPrecision'
122123
;
123124
$script .= "
124125
if (!\$this->isColumnModified(" . $this->getColumnConstant('update_column', $builder) . ")) {

tests/Propel/Tests/Generator/Behavior/Timestampable/TimestampableBehaviorTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ public function testPreSave()
6565
{
6666
$t1 = new Table2();
6767
$this->assertNull($t1->getUpdatedAt());
68-
$tsave = time();
6968
$t1->save();
70-
$this->assertTimeEquals($tsave, $t1->getUpdatedAt('U'), 'Timestampable sets updated_column to time() on creation');
69+
$this->assertEquals(
70+
$t1->getUpdatedAt(),
71+
$t1->getCreatedAt(),
72+
'Timestampable sets updated_column same created_column on creation'
73+
);
7174
sleep(1);
7275
$t1->setTitle('foo');
7376
$tupdate = time();

0 commit comments

Comments
 (0)