DDC-870 - Fix several bugs with optimistic locking, conversion of types, multiple updating of values and inheritance related stuff.
This commit is contained in:
parent
53e8b8f32d
commit
ac85584e9b
@ -251,6 +251,8 @@ class BasicEntityPersister
|
|||||||
$sql = "SELECT " . $versionFieldColumnName . " FROM " . $class->getQuotedTableName($this->_platform)
|
$sql = "SELECT " . $versionFieldColumnName . " FROM " . $class->getQuotedTableName($this->_platform)
|
||||||
. " WHERE " . implode(' = ? AND ', $identifier) . " = ?";
|
. " WHERE " . implode(' = ? AND ', $identifier) . " = ?";
|
||||||
$value = $this->_conn->fetchColumn($sql, array_values((array)$id));
|
$value = $this->_conn->fetchColumn($sql, array_values((array)$id));
|
||||||
|
|
||||||
|
$value = Type::getType($class->fieldMappings[$versionField]['type'])->convertToPHPValue($value, $this->_platform);
|
||||||
$this->_class->setFieldValue($entity, $versionField, $value);
|
$this->_class->setFieldValue($entity, $versionField, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,6 +279,11 @@ class BasicEntityPersister
|
|||||||
$entity, $this->_class->getQuotedTableName($this->_platform),
|
$entity, $this->_class->getQuotedTableName($this->_platform),
|
||||||
$updateData[$tableName], $this->_class->isVersioned
|
$updateData[$tableName], $this->_class->isVersioned
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($this->_class->isVersioned) {
|
||||||
|
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
|
||||||
|
$this->_assignDefaultVersionValue($this->_class, $entity, $id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,7 +320,7 @@ class BasicEntityPersister
|
|||||||
|
|
||||||
if ($versioned) {
|
if ($versioned) {
|
||||||
$versionField = $this->_class->versionField;
|
$versionField = $this->_class->versionField;
|
||||||
$versionFieldType = $this->_class->getTypeOfField($versionField);
|
$versionFieldType = $this->_class->fieldMappings[$versionField]['type'];
|
||||||
$versionColumn = $this->_class->getQuotedColumnName($versionField, $this->_platform);
|
$versionColumn = $this->_class->getQuotedColumnName($versionField, $this->_platform);
|
||||||
if ($versionFieldType == Type::INTEGER) {
|
if ($versionFieldType == Type::INTEGER) {
|
||||||
$set[] = $versionColumn . ' = ' . $versionColumn . ' + 1';
|
$set[] = $versionColumn . ' = ' . $versionColumn . ' + 1';
|
||||||
|
@ -205,6 +205,9 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
|||||||
// table were affected.
|
// table were affected.
|
||||||
if ($isVersioned && ! isset($updateData[$versionedTable])) {
|
if ($isVersioned && ! isset($updateData[$versionedTable])) {
|
||||||
$this->_updateTable($entity, $versionedClass->getQuotedTableName($this->_platform), array(), true);
|
$this->_updateTable($entity, $versionedClass->getQuotedTableName($this->_platform), array(), true);
|
||||||
|
|
||||||
|
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
|
||||||
|
$this->_assignDefaultVersionValue($this->_class, $entity, $id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,20 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMultipleFlushesDoIncrementalUpdates()
|
||||||
|
{
|
||||||
|
$test = new OptimisticStandard();
|
||||||
|
|
||||||
|
for ($i = 0; $i < 5; $i++) {
|
||||||
|
$test->name = 'test' . $i;
|
||||||
|
$this->_em->persist($test);
|
||||||
|
$this->_em->flush();
|
||||||
|
|
||||||
|
$this->assertType('int', $test->getVersion());
|
||||||
|
$this->assertEquals($i + 1, $test->getVersion());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testStandardInsertSetsInitialVersionValue()
|
public function testStandardInsertSetsInitialVersionValue()
|
||||||
{
|
{
|
||||||
$test = new OptimisticStandard();
|
$test = new OptimisticStandard();
|
||||||
@ -107,6 +121,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->_em->persist($test);
|
$this->_em->persist($test);
|
||||||
$this->_em->flush();
|
$this->_em->flush();
|
||||||
|
|
||||||
|
$this->assertType('int', $test->getVersion());
|
||||||
$this->assertEquals(1, $test->getVersion());
|
$this->assertEquals(1, $test->getVersion());
|
||||||
|
|
||||||
return $test;
|
return $test;
|
||||||
@ -139,10 +154,13 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
{
|
{
|
||||||
$test = new OptimisticTimestamp();
|
$test = new OptimisticTimestamp();
|
||||||
$test->name = 'Testing';
|
$test->name = 'Testing';
|
||||||
|
|
||||||
|
$this->assertNull($test->version, "Pre-Condition");
|
||||||
|
|
||||||
$this->_em->persist($test);
|
$this->_em->persist($test);
|
||||||
$this->_em->flush();
|
$this->_em->flush();
|
||||||
|
|
||||||
$this->assertTrue(strtotime($test->version) > 0);
|
$this->assertType('DateTime', $test->version);
|
||||||
|
|
||||||
return $test;
|
return $test;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user