Commit 435acc91 authored by romanb's avatar romanb

[2.0][DDC-24] Fixed (together with some small misc. refactorings).

parent 8f2d59c2
...@@ -1551,6 +1551,13 @@ abstract class AbstractPlatform ...@@ -1551,6 +1551,13 @@ abstract class AbstractPlatform
* @param array $field * @param array $field
*/ */
abstract public function getVarcharTypeDeclarationSql(array $field); abstract public function getVarcharTypeDeclarationSql(array $field);
/**
* Gets the SQL snippet used to declare a CLOB column type.
*
* @param array $field
*/
abstract public function getClobTypeDeclarationSql(array $field);
/** /**
* Gets the name of the platform. * Gets the name of the platform.
......
...@@ -365,6 +365,12 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -365,6 +365,12 @@ class MsSqlPlatform extends AbstractPlatform
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)') return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT'); : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
} }
/** @override */
public function getClobTypeDeclarationSql(array $field)
{
return 'TEXT';
}
/** /**
* @override * @override
......
...@@ -231,7 +231,8 @@ class MySqlPlatform extends AbstractPlatform ...@@ -231,7 +231,8 @@ class MySqlPlatform extends AbstractPlatform
: ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)'); : ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
} }
public function getClobDeclarationSql(array $field) /** @override */
public function getClobTypeDeclarationSql(array $field)
{ {
if ( ! empty($field['length'])) { if ( ! empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
......
...@@ -223,6 +223,12 @@ class OraclePlatform extends AbstractPlatform ...@@ -223,6 +223,12 @@ class OraclePlatform extends AbstractPlatform
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(2000)') return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(2000)')
: ($length ? 'VARCHAR2(' . $length . ')' : 'VARCHAR2(4000)'); : ($length ? 'VARCHAR2(' . $length . ')' : 'VARCHAR2(4000)');
} }
/** @override */
public function getClobTypeDeclarationSql(array $field)
{
return 'CLOB';
}
public function getListDatabasesSql() public function getListDatabasesSql()
{ {
......
...@@ -742,6 +742,12 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -742,6 +742,12 @@ class PostgreSqlPlatform extends AbstractPlatform
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)') return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT'); : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
} }
/** @override */
public function getClobTypeDeclarationSql(array $field)
{
return 'TEXT';
}
/** /**
* Get the platform name for this instance * Get the platform name for this instance
......
...@@ -370,6 +370,11 @@ class SqlitePlatform extends AbstractPlatform ...@@ -370,6 +370,11 @@ class SqlitePlatform extends AbstractPlatform
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)') return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT'); : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
} }
public function getClobTypeDeclarationSql(array $field)
{
return 'CLOB';
}
public function getListSequencesSql($database) public function getListSequencesSql($database)
{ {
......
...@@ -172,6 +172,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -172,6 +172,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$length = 1; $length = 1;
break; break;
case 'text': case 'text':
$fixed = false;
$type = 'text';
break;
case 'varchar': case 'varchar':
case 'interval': case 'interval':
case '_varchar': case '_varchar':
...@@ -186,7 +189,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -186,7 +189,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$type = 'boolean'; $type = 'boolean';
} }
} elseif (strstr($dbType, 'text')) { } elseif (strstr($dbType, 'text')) {
$type = 'clob'; $type = 'text';
} }
if ($fixed !== false) { if ($fixed !== false) {
$fixed = true; $fixed = true;
......
...@@ -138,6 +138,9 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -138,6 +138,9 @@ class SqliteSchemaManager extends AbstractSchemaManager
$length = 8; $length = 8;
break; break;
case 'clob': case 'clob':
$fixed = false;
$type = 'text';
break;
case 'tinytext': case 'tinytext':
case 'mediumtext': case 'mediumtext':
case 'longtext': case 'longtext':
......
...@@ -11,7 +11,7 @@ class ObjectType extends Type ...@@ -11,7 +11,7 @@ class ObjectType extends Type
{ {
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform) public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{ {
return $platform->getClobDeclarationSql($fieldDeclaration); return $platform->getClobTypeDeclarationSql($fieldDeclaration);
} }
public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform) public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
......
...@@ -12,7 +12,7 @@ class TextType extends Type ...@@ -12,7 +12,7 @@ class TextType extends Type
/** @override */ /** @override */
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform) public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{ {
return $platform->getClobDeclarationSql($fieldDeclaration); return $platform->getClobTypeDeclarationSql($fieldDeclaration);
} }
public function getName() public function getName()
......
...@@ -134,7 +134,7 @@ class EntityRepository ...@@ -134,7 +134,7 @@ class EntityRepository
$by = substr($method, 9, strlen($method)); $by = substr($method, 9, strlen($method));
$method = 'findOneBy'; $method = 'findOneBy';
} else { } else {
throw new BadMethodCallException("Undefined method '$method'."); throw new \BadMethodCallException("Undefined method '$method'.");
} }
if ( ! isset($arguments[0])) { if ( ! isset($arguments[0])) {
......
...@@ -340,7 +340,7 @@ class ObjectHydrator extends AbstractHydrator ...@@ -340,7 +340,7 @@ class ObjectHydrator extends AbstractHydrator
} else { } else {
// Single-valued association // Single-valued association
$reflFieldValue = $reflField->getValue($baseElement); $reflFieldValue = $reflField->getValue($baseElement);
if ( ! $reflFieldValue) { if ( ! $reflFieldValue /* || doctrine.refresh hint set */) {
if (isset($nonemptyComponents[$dqlAlias])) { if (isset($nonemptyComponents[$dqlAlias])) {
$element = $this->_getEntity($data, $dqlAlias); $element = $this->_getEntity($data, $dqlAlias);
$reflField->setValue($baseElement, $element); $reflField->setValue($baseElement, $element);
...@@ -350,7 +350,7 @@ class ObjectHydrator extends AbstractHydrator ...@@ -350,7 +350,7 @@ class ObjectHydrator extends AbstractHydrator
// If there is an inverse mapping on the target class its bidirectional // If there is an inverse mapping on the target class its bidirectional
if (isset($targetClass->inverseMappings[$relation->sourceEntityName][$relationField])) { if (isset($targetClass->inverseMappings[$relation->sourceEntityName][$relationField])) {
$sourceProp = $targetClass->inverseMappings[$relation->sourceEntityName][$relationField]->sourceFieldName; $sourceProp = $targetClass->inverseMappings[$relation->sourceEntityName][$relationField]->sourceFieldName;
$targetClass->reflFields[$sourceProp]->setValue($element, $base); $targetClass->reflFields[$sourceProp]->setValue($element, $baseElement);
} else if ($this->_ce[$parentClass] === $targetClass && $relation->mappedByFieldName) { } else if ($this->_ce[$parentClass] === $targetClass && $relation->mappedByFieldName) {
// Special case: bi-directional self-referencing one-one on the same class // Special case: bi-directional self-referencing one-one on the same class
$targetClass->reflFields[$relationField]->setValue($element, $baseElement); $targetClass->reflFields[$relationField]->setValue($element, $baseElement);
......
...@@ -109,19 +109,25 @@ class ProxyClassGenerator ...@@ -109,19 +109,25 @@ class ProxyClassGenerator
$methods = $this->_generateMethods($class); $methods = $this->_generateMethods($class);
$sleepImpl = $this->_generateSleep($class); $sleepImpl = $this->_generateSleep($class);
$constructorInv = $class->reflClass->hasMethod('__construct') ? 'parent::__construct();' : '';
$placeholders = array( $placeholders = array(
'<proxyClassName>', '<className>', '<proxyClassName>', '<className>',
'<methods>', '<sleepImpl>' '<methods>', '<sleepImpl>',
'<constructorInvocation>'
); );
$replacements = array( $replacements = array(
$proxyClassName, $originalClassName, $methods, $sleepImpl $proxyClassName, $originalClassName,
$methods, $sleepImpl,
$constructorInv
); );
$file = str_replace($placeholders, $replacements, $file); $file = str_replace($placeholders, $replacements, $file);
file_put_contents($fileName, $file); file_put_contents($fileName, $file);
require $fileName; require $fileName;
return $proxyFullyQualifiedClassName; return $proxyFullyQualifiedClassName;
} }
...@@ -130,7 +136,7 @@ class ProxyClassGenerator ...@@ -130,7 +136,7 @@ class ProxyClassGenerator
$methods = ''; $methods = '';
foreach ($class->reflClass->getMethods() as $method) { foreach ($class->reflClass->getMethods() as $method) {
if ($method->getName() == '__construct') { if ($method->isConstructor()) {
continue; continue;
} }
...@@ -205,6 +211,7 @@ namespace Doctrine\Generated\Proxies { ...@@ -205,6 +211,7 @@ namespace Doctrine\Generated\Proxies {
public function __construct($entityPersister, $identifier) { public function __construct($entityPersister, $identifier) {
$this->_entityPersister = $entityPersister; $this->_entityPersister = $entityPersister;
$this->_identifier = $identifier; $this->_identifier = $identifier;
<constructorInvocation>
} }
private function _load() { private function _load() {
if ( ! $this->_loaded) { if ( ! $this->_loaded) {
...@@ -241,6 +248,7 @@ namespace Doctrine\Generated\Proxies { ...@@ -241,6 +248,7 @@ namespace Doctrine\Generated\Proxies {
$this->_assoc = $assoc; $this->_assoc = $assoc;
$this->_owner = $owner; $this->_owner = $owner;
$this->_joinColumnValues = $joinColumnValues; $this->_joinColumnValues = $joinColumnValues;
<constructorInvocation>
} }
private function _load() { private function _load() {
if ( ! $this->_loaded) { if ( ! $this->_loaded) {
......
...@@ -1427,6 +1427,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1427,6 +1427,7 @@ class UnitOfWork implements PropertyChangedListener
array_combine($class->identifier, $this->_entityIdentifiers[$oid]), array_combine($class->identifier, $this->_entityIdentifiers[$oid]),
$entity $entity
); );
//TODO: refresh (initialized) associations
break; break;
default: default:
throw new \InvalidArgumentException("Entity is not MANAGED."); throw new \InvalidArgumentException("Entity is not MANAGED.");
...@@ -1656,7 +1657,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1656,7 +1657,7 @@ class UnitOfWork implements PropertyChangedListener
if (isset($this->_identityMap[$class->rootEntityName][$idHash])) { if (isset($this->_identityMap[$class->rootEntityName][$idHash])) {
$entity = $this->_identityMap[$class->rootEntityName][$idHash]; $entity = $this->_identityMap[$class->rootEntityName][$idHash];
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
$overrideLocalChanges = isset($hints[Query::HINT_REFRESH]); $overrideLocalValues = isset($hints[Query::HINT_REFRESH]);
} else { } else {
$entity = new $className; $entity = new $className;
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
...@@ -1667,10 +1668,10 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1667,10 +1668,10 @@ class UnitOfWork implements PropertyChangedListener
if ($entity instanceof \Doctrine\Common\NotifyPropertyChanged) { if ($entity instanceof \Doctrine\Common\NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this); $entity->addPropertyChangedListener($this);
} }
$overrideLocalChanges = true; $overrideLocalValues = true;
} }
if ($overrideLocalChanges) { if ($overrideLocalValues) {
if ($this->_useCExtension) { if ($this->_useCExtension) {
doctrine_populate_data($entity, $data); doctrine_populate_data($entity, $data);
} else { } else {
...@@ -1680,20 +1681,6 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1680,20 +1681,6 @@ class UnitOfWork implements PropertyChangedListener
} }
} }
} }
} else {
foreach ($data as $field => $value) {
if (isset($class->reflFields[$field])) {
$currentValue = $class->reflFields[$field]->getValue($entity);
// Only override the current value if:
// a) There was no original value yet (nothing in _originalEntityData)
// or
// b) The original value is the same as the current value (it was not changed).
if ( ! isset($this->_originalEntityData[$oid][$field]) ||
$currentValue == $this->_originalEntityData[$oid][$field]) {
$class->reflFields[$field]->setValue($entity, $value);
}
}
}
} }
if (isset($class->lifecycleCallbacks[Events::postLoad])) { if (isset($class->lifecycleCallbacks[Events::postLoad])) {
......
...@@ -16,6 +16,12 @@ class MockPlatform extends \Doctrine\DBAL\Platforms\AbstractPlatform ...@@ -16,6 +16,12 @@ class MockPlatform extends \Doctrine\DBAL\Platforms\AbstractPlatform
{ {
return "DUMMYVARCHAR()"; return "DUMMYVARCHAR()";
} }
/** @override */
public function getClobTypeDeclarationSql(array $field)
{
return 'DUMMYCLOB';
}
public function getVarcharDefaultLength() public function getVarcharDefaultLength()
{ {
......
...@@ -57,6 +57,9 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform ...@@ -57,6 +57,9 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
/** @override */ /** @override */
public function getVarcharTypeDeclarationSql(array $field) {} public function getVarcharTypeDeclarationSql(array $field) {}
/** @override */
public function getClobTypeDeclarationSql(array $field) {}
/* MOCK API */ /* MOCK API */
......
...@@ -54,4 +54,11 @@ class CmsAddress ...@@ -54,4 +54,11 @@ class CmsAddress
public function getCity() { public function getCity() {
return $this->city; return $this->city;
} }
public function setUser(CmsUser $user) {
if ($this->user !== $user) {
$this->user = $user;
$user->setAddress($this);
}
}
} }
\ No newline at end of file
...@@ -107,4 +107,11 @@ class CmsUser ...@@ -107,4 +107,11 @@ class CmsUser
} }
return false; return false;
} }
public function setAddress(CmsAddress $address) {
if ($this->address !== $address) {
$this->address = $address;
$address->setUser($this);
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment