mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5725dd6bb | ||
|
|
b59cd047ff | ||
|
|
019094655b | ||
|
|
88e817660c | ||
|
|
aee75d8f25 | ||
|
|
50132ddc18 | ||
|
|
f05bcbc17c | ||
|
|
f94b6c07c7 | ||
|
|
b68c6b3d2d | ||
|
|
0425e8452d | ||
|
|
c120700d89 | ||
|
|
22dc20c320 | ||
|
|
6d89875306 | ||
|
|
b666a62979 | ||
|
|
f2f8c4f2dd | ||
|
|
59aef2ca95 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "doctrine/orm",
|
||||
"type": "library","version":"2.3.1",
|
||||
"type": "library","version":"2.3.2",
|
||||
"description": "Object-Relational-Mapper for PHP",
|
||||
"keywords": ["orm", "database"],
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
|
||||
@@ -230,12 +230,21 @@ class XmlDriver extends FileDriver
|
||||
if (isset($xmlRoot->field)) {
|
||||
foreach ($xmlRoot->field as $fieldMapping) {
|
||||
$mapping = $this->columnToArray($fieldMapping);
|
||||
|
||||
if (isset($mapping['version'])) {
|
||||
$metadata->setVersionMapping($mapping);
|
||||
}
|
||||
|
||||
$metadata->mapField($mapping);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($mappings as $mapping) {
|
||||
$metadata->mapField($mapping);
|
||||
if (isset($mapping['version'])) {
|
||||
$metadata->setVersionMapping($mapping);
|
||||
}
|
||||
|
||||
$metadata->mapField($mapping);
|
||||
}
|
||||
|
||||
// Evaluate <id ...> mappings
|
||||
|
||||
@@ -297,6 +297,10 @@ class YamlDriver extends FileDriver
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($mapping['version'])) {
|
||||
$metadata->setVersionMapping($mapping);
|
||||
}
|
||||
|
||||
$metadata->mapField($mapping);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,8 +227,10 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
|
||||
// Make sure the table with the version column is updated even if no columns on that
|
||||
// table were affected.
|
||||
if ($isVersioned && ! isset($updateData[$versionedTable])) {
|
||||
$this->_updateTable($entity, $this->quoteStrategy->getTableName($versionedClass, $this->_platform), array(), true);
|
||||
if ($isVersioned) {
|
||||
if ( ! isset($updateData[$versionedTable])) {
|
||||
$this->_updateTable($entity, $this->quoteStrategy->getTableName($versionedClass, $this->_platform), array(), true);
|
||||
}
|
||||
|
||||
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
|
||||
$this->assignDefaultVersionValue($entity, $id);
|
||||
|
||||
@@ -63,6 +63,9 @@ class Setup
|
||||
* Use this method to register all autoloaders for a setup where Doctrine is installed
|
||||
* though {@link http://pear.doctrine-project.org}.
|
||||
*
|
||||
* This method registers autoloaders for both Doctrine and Symfony top
|
||||
* level namespaces.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function registerAutoloadPEAR()
|
||||
@@ -74,15 +77,8 @@ class Setup
|
||||
$loader = new ClassLoader("Doctrine");
|
||||
$loader->register();
|
||||
|
||||
$parts = explode(PATH_SEPARATOR, get_include_path());
|
||||
|
||||
foreach ($parts as $includePath) {
|
||||
if ($includePath != "." && file_exists($includePath . "/Doctrine")) {
|
||||
$loader = new ClassLoader("Symfony\Component", $includePath . "/Doctrine");
|
||||
$loader->register();
|
||||
return;
|
||||
}
|
||||
}
|
||||
$loader = new ClassLoader("Symfony");
|
||||
$loader->register();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2571,6 +2571,10 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$newValueOid = spl_object_hash($newValue);
|
||||
$this->entityIdentifiers[$newValueOid] = $associatedId;
|
||||
$this->identityMap[$targetClass->rootEntityName][$relatedIdHash] = $newValue;
|
||||
|
||||
if ($newValue instanceof NotifyPropertyChanged) {
|
||||
$newValue->addPropertyChangedListener($this);
|
||||
}
|
||||
$this->entityStates[$newValueOid] = self::STATE_MANAGED;
|
||||
// make sure that when an proxy is then finally loaded, $this->originalEntityData is set also!
|
||||
break;
|
||||
|
||||
@@ -36,7 +36,7 @@ class Version
|
||||
/**
|
||||
* Current Doctrine Version
|
||||
*/
|
||||
const VERSION = '2.3.1';
|
||||
const VERSION = '2.3.2';
|
||||
|
||||
/**
|
||||
* Compares a Doctrine version with the current one.
|
||||
|
||||
2
lib/vendor/doctrine-dbal
vendored
2
lib/vendor/doctrine-dbal
vendored
Submodule lib/vendor/doctrine-dbal updated: 256a610961...e59abccfe8
153
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php
Normal file
153
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Common\NotifyPropertyChanged,
|
||||
Doctrine\Common\PropertyChangedListener;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class DDC1690Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
try {
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1690Parent'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1690Child')
|
||||
));
|
||||
} catch (\Exception $e) {
|
||||
// Swallow all exceptions. We do not test the schema tool here.
|
||||
}
|
||||
}
|
||||
|
||||
public function testChangeTracking()
|
||||
{
|
||||
$parent = new DDC1690Parent();
|
||||
$child = new DDC1690Child();
|
||||
$parent->setName('parent');
|
||||
$child->setName('child');
|
||||
|
||||
$parent->setChild($child);
|
||||
$child->setParent($parent);
|
||||
|
||||
$this->_em->persist($parent);
|
||||
$this->_em->persist($child);
|
||||
|
||||
$this->assertEquals(1, count($parent->listeners));
|
||||
$this->assertEquals(1, count($child->listeners));
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$this->assertEquals(1, count($parent->listeners));
|
||||
$this->assertEquals(1, count($child->listeners));
|
||||
|
||||
$parentId = $parent->getId();
|
||||
$childId = $child->getId();
|
||||
unset($parent, $child);
|
||||
|
||||
$parent = $this->_em->find(__NAMESPACE__.'\DDC1690Parent', $parentId);
|
||||
$child = $this->_em->find(__NAMESPACE__.'\DDC1690Child', $childId);
|
||||
|
||||
$this->assertEquals(1, count($parent->listeners));
|
||||
$this->assertEquals(1, count($child->listeners));
|
||||
unset($parent, $child);
|
||||
|
||||
$parent = $this->_em->find(__NAMESPACE__.'\DDC1690Parent', $parentId);
|
||||
$child = $parent->getChild();
|
||||
|
||||
$this->assertEquals(1, count($parent->listeners));
|
||||
$this->assertEquals(1, count($child->listeners));
|
||||
unset($parent, $child);
|
||||
|
||||
$child = $this->_em->find(__NAMESPACE__.'\DDC1690Child', $childId);
|
||||
$parent = $child->getParent();
|
||||
|
||||
$this->assertEquals(1, count($parent->listeners));
|
||||
$this->assertEquals(1, count($child->listeners));
|
||||
}
|
||||
}
|
||||
|
||||
class NotifyBaseEntity implements NotifyPropertyChanged {
|
||||
public $listeners = array();
|
||||
|
||||
public function addPropertyChangedListener(PropertyChangedListener $listener) {
|
||||
if (!in_array($listener, $this->listeners)) {
|
||||
$this->listeners[] = $listener;
|
||||
}
|
||||
}
|
||||
|
||||
protected function onPropertyChanged($propName, $oldValue, $newValue) {
|
||||
if ($this->listeners) {
|
||||
foreach ($this->listeners as $listener) {
|
||||
$listener->propertyChanged($this, $propName, $oldValue, $newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @Entity @ChangeTrackingPolicy("NOTIFY") */
|
||||
class DDC1690Parent extends NotifyBaseEntity {
|
||||
/** @Id @Column(type="integer") @GeneratedValue */
|
||||
private $id;
|
||||
|
||||
/** @Column */
|
||||
private $name;
|
||||
|
||||
/** @OneToOne(targetEntity="DDC1690Child") */
|
||||
private $child;
|
||||
|
||||
function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function setName($name) {
|
||||
$this->onPropertyChanged('name', $this->name, $name);
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
function setChild($child) {
|
||||
$this->child = $child;
|
||||
}
|
||||
|
||||
function getChild() {
|
||||
return $this->child;
|
||||
}
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class DDC1690Child extends NotifyBaseEntity {
|
||||
/** @Id @Column(type="integer") @GeneratedValue */
|
||||
private $id;
|
||||
|
||||
/** @Column */
|
||||
private $name;
|
||||
|
||||
/** @OneToOne(targetEntity="DDC1690Parent", mappedBy="child") */
|
||||
private $parent;
|
||||
|
||||
function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function setName($name) {
|
||||
$this->onPropertyChanged('name', $this->name, $name);
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
function setParent($parent) {
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
function getParent() {
|
||||
return $this->parent;
|
||||
}
|
||||
}
|
||||
62
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php
Normal file
62
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
/**
|
||||
* @group DDC-2175
|
||||
*/
|
||||
class DDC2175Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2175Entity'),
|
||||
));
|
||||
}
|
||||
|
||||
public function testIssue()
|
||||
{
|
||||
$entity = new DDC2175Entity();
|
||||
$entity->field = "foo";
|
||||
|
||||
$this->_em->persist($entity);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertEquals(1, $entity->version);
|
||||
|
||||
$entity->field = "bar";
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertEquals(2, $entity->version);
|
||||
|
||||
$entity->field = "baz";
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertEquals(3, $entity->version);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @InheritanceType("JOINED")
|
||||
* @DiscriminatorMap({"entity": "DDC2175Entity"})
|
||||
*/
|
||||
class DDC2175Entity
|
||||
{
|
||||
/**
|
||||
* @Id @GeneratedValue @Column(type="integer")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @Column(type="string")
|
||||
*/
|
||||
public $field;
|
||||
|
||||
/**
|
||||
* @Version
|
||||
* @Column(type="integer")
|
||||
*/
|
||||
public $version;
|
||||
}
|
||||
@@ -19,8 +19,8 @@ class DDC2182Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2182OptionChild'),
|
||||
));
|
||||
|
||||
$this->assertEquals("CREATE TABLE DDC2182OptionParent (id INT UNSIGNED NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB", $sql[0]);
|
||||
$this->assertEquals("CREATE TABLE DDC2182OptionChild (id VARCHAR(255) NOT NULL, parent_id INT UNSIGNED DEFAULT NULL, INDEX IDX_B314D4AD727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB", $sql[1]);
|
||||
$this->assertEquals("CREATE TABLE DDC2182OptionParent (id INT UNSIGNED NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[0]);
|
||||
$this->assertEquals("CREATE TABLE DDC2182OptionChild (id VARCHAR(255) NOT NULL, parent_id INT UNSIGNED DEFAULT NULL, INDEX IDX_B314D4AD727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[1]);
|
||||
$this->assertEquals("ALTER TABLE DDC2182OptionChild ADD CONSTRAINT FK_B314D4AD727ACA70 FOREIGN KEY (parent_id) REFERENCES DDC2182OptionParent (id)", $sql[2]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,14 +139,25 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||
*/
|
||||
public function testFieldMappings($class)
|
||||
{
|
||||
$this->assertEquals(3, count($class->fieldMappings));
|
||||
$this->assertEquals(4, count($class->fieldMappings));
|
||||
$this->assertTrue(isset($class->fieldMappings['id']));
|
||||
$this->assertTrue(isset($class->fieldMappings['name']));
|
||||
$this->assertTrue(isset($class->fieldMappings['email']));
|
||||
$this->assertTrue(isset($class->fieldMappings['version']));
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testFieldMappings
|
||||
* @param ClassMetadata $class
|
||||
*/
|
||||
public function testVersionedField($class)
|
||||
{
|
||||
$this->assertTrue($class->isVersioned);
|
||||
$this->assertEquals("version", $class->versionField);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testEntityTableNameAndInheritance
|
||||
* @param ClassMetadata $class
|
||||
@@ -793,6 +804,12 @@ class User
|
||||
*/
|
||||
public $groups;
|
||||
|
||||
/**
|
||||
* @Column(type="integer")
|
||||
* @Version
|
||||
*/
|
||||
public $version;
|
||||
|
||||
|
||||
/**
|
||||
* @PrePersist
|
||||
@@ -847,6 +864,9 @@ class User
|
||||
'columnName' => 'user_email',
|
||||
'columnDefinition' => 'CHAR(32) NOT NULL',
|
||||
));
|
||||
$mapping = array('fieldName' => 'version', 'type' => 'integer');
|
||||
$metadata->setVersionMapping($mapping);
|
||||
$metadata->mapField($mapping);
|
||||
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
|
||||
$metadata->mapOneToOne(array(
|
||||
'fieldName' => 'address',
|
||||
|
||||
@@ -35,6 +35,9 @@ $metadata->mapField(array(
|
||||
'columnName' => 'user_email',
|
||||
'columnDefinition' => 'CHAR(32) NOT NULL',
|
||||
));
|
||||
$mapping = array('fieldName' => 'version', 'type' => 'integer');
|
||||
$metadata->setVersionMapping($mapping);
|
||||
$metadata->mapField($mapping);
|
||||
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
|
||||
$metadata->mapOneToOne(array(
|
||||
'fieldName' => 'address',
|
||||
@@ -121,4 +124,4 @@ $metadata->setSequenceGeneratorDefinition(array(
|
||||
'sequenceName' => 'tablename_seq',
|
||||
'allocationSize' => 100,
|
||||
'initialValue' => 1,
|
||||
));
|
||||
));
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
|
||||
<entity name="Doctrine\Tests\ORM\Mapping\User" table="cms_users">
|
||||
<options>
|
||||
<option name="foo">bar</option>
|
||||
@@ -36,7 +36,7 @@
|
||||
<generator strategy="AUTO"/>
|
||||
<sequence-generator sequence-name="tablename_seq" allocation-size="100" initial-value="1" />
|
||||
</id>
|
||||
|
||||
|
||||
<field name="name" column="name" type="string" length="50" nullable="true" unique="true">
|
||||
<options>
|
||||
<option name="foo">bar</option>
|
||||
@@ -46,12 +46,14 @@
|
||||
</options>
|
||||
</field>
|
||||
<field name="email" column="user_email" type="string" column-definition="CHAR(32) NOT NULL" />
|
||||
|
||||
|
||||
<field name="version" type="integer" version="true" />
|
||||
|
||||
<one-to-one field="address" target-entity="Address" inversed-by="user">
|
||||
<cascade><cascade-remove /></cascade>
|
||||
<join-column name="address_id" referenced-column-name="id" on-delete="CASCADE" on-update="CASCADE"/>
|
||||
</one-to-one>
|
||||
|
||||
|
||||
<one-to-many field="phonenumbers" target-entity="Phonenumber" mapped-by="user" index-by="number" orphan-removal="true">
|
||||
<cascade>
|
||||
<cascade-persist/>
|
||||
@@ -60,7 +62,7 @@
|
||||
<order-by-field name="number" direction="ASC" />
|
||||
</order-by>
|
||||
</one-to-many>
|
||||
|
||||
|
||||
<many-to-many field="groups" target-entity="Group">
|
||||
<cascade>
|
||||
<cascade-all/>
|
||||
@@ -74,7 +76,7 @@
|
||||
</inverse-join-columns>
|
||||
</join-table>
|
||||
</many-to-many>
|
||||
|
||||
|
||||
</entity>
|
||||
|
||||
</doctrine-mapping>
|
||||
|
||||
@@ -30,6 +30,9 @@ Doctrine\Tests\ORM\Mapping\User:
|
||||
type: string
|
||||
column: user_email
|
||||
columnDefinition: CHAR(32) NOT NULL
|
||||
version:
|
||||
type: integer
|
||||
version: true
|
||||
oneToOne:
|
||||
address:
|
||||
targetEntity: Address
|
||||
@@ -73,4 +76,4 @@ Doctrine\Tests\ORM\Mapping\User:
|
||||
name_idx:
|
||||
columns: name
|
||||
0:
|
||||
columns: user_email
|
||||
columns: user_email
|
||||
|
||||
Reference in New Issue
Block a user