PageRenderTime 91ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Doctrine/ORM/UnitOfWork.php

https://github.com/kadryjanek/doctrine2
PHP | 3192 lines | 1627 code | 512 blank | 1053 comment | 305 complexity | eb17729e4b30c53af577e21b07903adf MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\ORM;
  20. use Exception;
  21. use InvalidArgumentException;
  22. use UnexpectedValueException;
  23. use Doctrine\Common\Collections\ArrayCollection;
  24. use Doctrine\Common\Collections\Collection;
  25. use Doctrine\Common\NotifyPropertyChanged;
  26. use Doctrine\Common\PropertyChangedListener;
  27. use Doctrine\Common\Persistence\ObjectManagerAware;
  28. use Doctrine\ORM\Mapping\ClassMetadata;
  29. use Doctrine\ORM\Proxy\Proxy;
  30. use Doctrine\ORM\Event\LifecycleEventArgs;
  31. use Doctrine\ORM\Event\PreUpdateEventArgs;
  32. use Doctrine\ORM\Event\PreFlushEventArgs;
  33. use Doctrine\ORM\Event\OnFlushEventArgs;
  34. use Doctrine\ORM\Event\PostFlushEventArgs;
  35. use Doctrine\ORM\Event\ListenersInvoker;
  36. /**
  37. * The UnitOfWork is responsible for tracking changes to objects during an
  38. * "object-level" transaction and for writing out changes to the database
  39. * in the correct order.
  40. *
  41. * @since 2.0
  42. * @author Benjamin Eberlei <kontakt@beberlei.de>
  43. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  44. * @author Jonathan Wage <jonwage@gmail.com>
  45. * @author Roman Borschel <roman@code-factory.org>
  46. * @internal This class contains highly performance-sensitive code.
  47. */
  48. class UnitOfWork implements PropertyChangedListener
  49. {
  50. /**
  51. * An entity is in MANAGED state when its persistence is managed by an EntityManager.
  52. */
  53. const STATE_MANAGED = 1;
  54. /**
  55. * An entity is new if it has just been instantiated (i.e. using the "new" operator)
  56. * and is not (yet) managed by an EntityManager.
  57. */
  58. const STATE_NEW = 2;
  59. /**
  60. * A detached entity is an instance with persistent state and identity that is not
  61. * (or no longer) associated with an EntityManager (and a UnitOfWork).
  62. */
  63. const STATE_DETACHED = 3;
  64. /**
  65. * A removed entity instance is an instance with a persistent identity,
  66. * associated with an EntityManager, whose persistent state will be deleted
  67. * on commit.
  68. */
  69. const STATE_REMOVED = 4;
  70. /**
  71. * The identity map that holds references to all managed entities that have
  72. * an identity. The entities are grouped by their class name.
  73. * Since all classes in a hierarchy must share the same identifier set,
  74. * we always take the root class name of the hierarchy.
  75. *
  76. * @var array
  77. */
  78. private $identityMap = array();
  79. /**
  80. * Map of all identifiers of managed entities.
  81. * Keys are object ids (spl_object_hash).
  82. *
  83. * @var array
  84. */
  85. private $entityIdentifiers = array();
  86. /**
  87. * Map of the original entity data of managed entities.
  88. * Keys are object ids (spl_object_hash). This is used for calculating changesets
  89. * at commit time.
  90. *
  91. * @var array
  92. * @internal Note that PHPs "copy-on-write" behavior helps a lot with memory usage.
  93. * A value will only really be copied if the value in the entity is modified
  94. * by the user.
  95. */
  96. private $originalEntityData = array();
  97. /**
  98. * Map of entity changes. Keys are object ids (spl_object_hash).
  99. * Filled at the beginning of a commit of the UnitOfWork and cleaned at the end.
  100. *
  101. * @var array
  102. */
  103. private $entityChangeSets = array();
  104. /**
  105. * The (cached) states of any known entities.
  106. * Keys are object ids (spl_object_hash).
  107. *
  108. * @var array
  109. */
  110. private $entityStates = array();
  111. /**
  112. * Map of entities that are scheduled for dirty checking at commit time.
  113. * This is only used for entities with a change tracking policy of DEFERRED_EXPLICIT.
  114. * Keys are object ids (spl_object_hash).
  115. *
  116. * @var array
  117. * @todo rename: scheduledForSynchronization
  118. */
  119. private $scheduledForDirtyCheck = array();
  120. /**
  121. * A list of all pending entity insertions.
  122. *
  123. * @var array
  124. */
  125. private $entityInsertions = array();
  126. /**
  127. * A list of all pending entity updates.
  128. *
  129. * @var array
  130. */
  131. private $entityUpdates = array();
  132. /**
  133. * Any pending extra updates that have been scheduled by persisters.
  134. *
  135. * @var array
  136. */
  137. private $extraUpdates = array();
  138. /**
  139. * A list of all pending entity deletions.
  140. *
  141. * @var array
  142. */
  143. private $entityDeletions = array();
  144. /**
  145. * All pending collection deletions.
  146. *
  147. * @var array
  148. */
  149. private $collectionDeletions = array();
  150. /**
  151. * All pending collection updates.
  152. *
  153. * @var array
  154. */
  155. private $collectionUpdates = array();
  156. /**
  157. * List of collections visited during changeset calculation on a commit-phase of a UnitOfWork.
  158. * At the end of the UnitOfWork all these collections will make new snapshots
  159. * of their data.
  160. *
  161. * @var array
  162. */
  163. private $visitedCollections = array();
  164. /**
  165. * The EntityManager that "owns" this UnitOfWork instance.
  166. *
  167. * @var \Doctrine\ORM\EntityManager
  168. */
  169. private $em;
  170. /**
  171. * The calculator used to calculate the order in which changes to
  172. * entities need to be written to the database.
  173. *
  174. * @var \Doctrine\ORM\Internal\CommitOrderCalculator
  175. */
  176. private $commitOrderCalculator;
  177. /**
  178. * The entity persister instances used to persist entity instances.
  179. *
  180. * @var array
  181. */
  182. private $persisters = array();
  183. /**
  184. * The collection persister instances used to persist collections.
  185. *
  186. * @var array
  187. */
  188. private $collectionPersisters = array();
  189. /**
  190. * The EventManager used for dispatching events.
  191. *
  192. * @var \Doctrine\Common\EventManager
  193. */
  194. private $evm;
  195. /**
  196. * The ListenersInvoker used for dispatching events.
  197. *
  198. * @var \Doctrine\ORM\Event\ListenersInvoker
  199. */
  200. private $listenersInvoker;
  201. /**
  202. * Orphaned entities that are scheduled for removal.
  203. *
  204. * @var array
  205. */
  206. private $orphanRemovals = array();
  207. /**
  208. * Read-Only objects are never evaluated
  209. *
  210. * @var array
  211. */
  212. private $readOnlyObjects = array();
  213. /**
  214. * Map of Entity Class-Names and corresponding IDs that should eager loaded when requested.
  215. *
  216. * @var array
  217. */
  218. private $eagerLoadingEntities = array();
  219. /**
  220. * Initializes a new UnitOfWork instance, bound to the given EntityManager.
  221. *
  222. * @param \Doctrine\ORM\EntityManager $em
  223. */
  224. public function __construct(EntityManager $em)
  225. {
  226. $this->em = $em;
  227. $this->evm = $em->getEventManager();
  228. $this->listenersInvoker = new ListenersInvoker($em);
  229. }
  230. /**
  231. * Commits the UnitOfWork, executing all operations that have been postponed
  232. * up to this point. The state of all managed entities will be synchronized with
  233. * the database.
  234. *
  235. * The operations are executed in the following order:
  236. *
  237. * 1) All entity insertions
  238. * 2) All entity updates
  239. * 3) All collection deletions
  240. * 4) All collection updates
  241. * 5) All entity deletions
  242. *
  243. * @param null|object|array $entity
  244. *
  245. * @return void
  246. *
  247. * @throws \Exception
  248. */
  249. public function commit($entity = null)
  250. {
  251. // Raise preFlush
  252. if ($this->evm->hasListeners(Events::preFlush)) {
  253. $this->evm->dispatchEvent(Events::preFlush, new PreFlushEventArgs($this->em));
  254. }
  255. // Compute changes done since last commit.
  256. if ($entity === null) {
  257. $this->computeChangeSets();
  258. } elseif (is_object($entity)) {
  259. $this->computeSingleEntityChangeSet($entity);
  260. } elseif (is_array($entity)) {
  261. foreach ($entity as $object) {
  262. $this->computeSingleEntityChangeSet($object);
  263. }
  264. }
  265. if ( ! ($this->entityInsertions ||
  266. $this->entityDeletions ||
  267. $this->entityUpdates ||
  268. $this->collectionUpdates ||
  269. $this->collectionDeletions ||
  270. $this->orphanRemovals)) {
  271. $this->dispatchOnFlushEvent();
  272. $this->dispatchPostFlushEvent();
  273. return; // Nothing to do.
  274. }
  275. if ($this->orphanRemovals) {
  276. foreach ($this->orphanRemovals as $orphan) {
  277. $this->remove($orphan);
  278. }
  279. }
  280. $this->dispatchOnFlushEvent();
  281. // Now we need a commit order to maintain referential integrity
  282. $commitOrder = $this->getCommitOrder();
  283. $conn = $this->em->getConnection();
  284. $conn->beginTransaction();
  285. try {
  286. if ($this->entityInsertions) {
  287. foreach ($commitOrder as $class) {
  288. $this->executeInserts($class);
  289. }
  290. }
  291. if ($this->entityUpdates) {
  292. foreach ($commitOrder as $class) {
  293. $this->executeUpdates($class);
  294. }
  295. }
  296. // Extra updates that were requested by persisters.
  297. if ($this->extraUpdates) {
  298. $this->executeExtraUpdates();
  299. }
  300. // Collection deletions (deletions of complete collections)
  301. foreach ($this->collectionDeletions as $collectionToDelete) {
  302. $this->getCollectionPersister($collectionToDelete->getMapping())->delete($collectionToDelete);
  303. }
  304. // Collection updates (deleteRows, updateRows, insertRows)
  305. foreach ($this->collectionUpdates as $collectionToUpdate) {
  306. $this->getCollectionPersister($collectionToUpdate->getMapping())->update($collectionToUpdate);
  307. }
  308. // Entity deletions come last and need to be in reverse commit order
  309. if ($this->entityDeletions) {
  310. for ($count = count($commitOrder), $i = $count - 1; $i >= 0; --$i) {
  311. $this->executeDeletions($commitOrder[$i]);
  312. }
  313. }
  314. $conn->commit();
  315. } catch (Exception $e) {
  316. $this->em->close();
  317. $conn->rollback();
  318. throw $e;
  319. }
  320. // Take new snapshots from visited collections
  321. foreach ($this->visitedCollections as $coll) {
  322. $coll->takeSnapshot();
  323. }
  324. $this->dispatchPostFlushEvent();
  325. // Clear up
  326. $this->entityInsertions =
  327. $this->entityUpdates =
  328. $this->entityDeletions =
  329. $this->extraUpdates =
  330. $this->entityChangeSets =
  331. $this->collectionUpdates =
  332. $this->collectionDeletions =
  333. $this->visitedCollections =
  334. $this->scheduledForDirtyCheck =
  335. $this->orphanRemovals = array();
  336. }
  337. /**
  338. * Computes the changesets of all entities scheduled for insertion.
  339. *
  340. * @return void
  341. */
  342. private function computeScheduleInsertsChangeSets()
  343. {
  344. foreach ($this->entityInsertions as $entity) {
  345. $class = $this->em->getClassMetadata(get_class($entity));
  346. $this->computeChangeSet($class, $entity);
  347. }
  348. }
  349. /**
  350. * Only flushes the given entity according to a ruleset that keeps the UoW consistent.
  351. *
  352. * 1. All entities scheduled for insertion, (orphan) removals and changes in collections are processed as well!
  353. * 2. Read Only entities are skipped.
  354. * 3. Proxies are skipped.
  355. * 4. Only if entity is properly managed.
  356. *
  357. * @param object $entity
  358. *
  359. * @return void
  360. *
  361. * @throws \InvalidArgumentException
  362. */
  363. private function computeSingleEntityChangeSet($entity)
  364. {
  365. if ( $this->getEntityState($entity) !== self::STATE_MANAGED) {
  366. throw new \InvalidArgumentException("Entity has to be managed for single computation " . self::objToStr($entity));
  367. }
  368. $class = $this->em->getClassMetadata(get_class($entity));
  369. if ($class->isChangeTrackingDeferredImplicit()) {
  370. $this->persist($entity);
  371. }
  372. // Compute changes for INSERTed entities first. This must always happen even in this case.
  373. $this->computeScheduleInsertsChangeSets();
  374. if ($class->isReadOnly) {
  375. return;
  376. }
  377. // Ignore uninitialized proxy objects
  378. if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
  379. return;
  380. }
  381. // Only MANAGED entities that are NOT SCHEDULED FOR INSERTION are processed here.
  382. $oid = spl_object_hash($entity);
  383. if ( ! isset($this->entityInsertions[$oid]) && isset($this->entityStates[$oid])) {
  384. $this->computeChangeSet($class, $entity);
  385. }
  386. }
  387. /**
  388. * Executes any extra updates that have been scheduled.
  389. */
  390. private function executeExtraUpdates()
  391. {
  392. foreach ($this->extraUpdates as $oid => $update) {
  393. list ($entity, $changeset) = $update;
  394. $this->entityChangeSets[$oid] = $changeset;
  395. $this->getEntityPersister(get_class($entity))->update($entity);
  396. }
  397. }
  398. /**
  399. * Gets the changeset for an entity.
  400. *
  401. * @param object $entity
  402. *
  403. * @return array
  404. */
  405. public function getEntityChangeSet($entity)
  406. {
  407. $oid = spl_object_hash($entity);
  408. if (isset($this->entityChangeSets[$oid])) {
  409. return $this->entityChangeSets[$oid];
  410. }
  411. return array();
  412. }
  413. /**
  414. * Computes the changes that happened to a single entity.
  415. *
  416. * Modifies/populates the following properties:
  417. *
  418. * {@link _originalEntityData}
  419. * If the entity is NEW or MANAGED but not yet fully persisted (only has an id)
  420. * then it was not fetched from the database and therefore we have no original
  421. * entity data yet. All of the current entity data is stored as the original entity data.
  422. *
  423. * {@link _entityChangeSets}
  424. * The changes detected on all properties of the entity are stored there.
  425. * A change is a tuple array where the first entry is the old value and the second
  426. * entry is the new value of the property. Changesets are used by persisters
  427. * to INSERT/UPDATE the persistent entity state.
  428. *
  429. * {@link _entityUpdates}
  430. * If the entity is already fully MANAGED (has been fetched from the database before)
  431. * and any changes to its properties are detected, then a reference to the entity is stored
  432. * there to mark it for an update.
  433. *
  434. * {@link _collectionDeletions}
  435. * If a PersistentCollection has been de-referenced in a fully MANAGED entity,
  436. * then this collection is marked for deletion.
  437. *
  438. * @ignore
  439. *
  440. * @internal Don't call from the outside.
  441. *
  442. * @param ClassMetadata $class The class descriptor of the entity.
  443. * @param object $entity The entity for which to compute the changes.
  444. *
  445. * @return void
  446. */
  447. public function computeChangeSet(ClassMetadata $class, $entity)
  448. {
  449. $oid = spl_object_hash($entity);
  450. if (isset($this->readOnlyObjects[$oid])) {
  451. return;
  452. }
  453. if ( ! $class->isInheritanceTypeNone()) {
  454. $class = $this->em->getClassMetadata(get_class($entity));
  455. }
  456. $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::preFlush);
  457. if ($invoke !== ListenersInvoker::INVOKE_NONE) {
  458. $this->listenersInvoker->invoke($class, Events::preFlush, $entity, new PreFlushEventArgs($this->em), $invoke);
  459. }
  460. $actualData = array();
  461. foreach ($class->reflFields as $name => $refProp) {
  462. $value = $refProp->getValue($entity);
  463. if ($class->isCollectionValuedAssociation($name) && $value !== null && ! ($value instanceof PersistentCollection)) {
  464. // If $value is not a Collection then use an ArrayCollection.
  465. if ( ! $value instanceof Collection) {
  466. $value = new ArrayCollection($value);
  467. }
  468. $assoc = $class->associationMappings[$name];
  469. // Inject PersistentCollection
  470. $value = new PersistentCollection(
  471. $this->em, $this->em->getClassMetadata($assoc['targetEntity']), $value
  472. );
  473. $value->setOwner($entity, $assoc);
  474. $value->setDirty( ! $value->isEmpty());
  475. $class->reflFields[$name]->setValue($entity, $value);
  476. $actualData[$name] = $value;
  477. continue;
  478. }
  479. if (( ! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity()) && ($name !== $class->versionField)) {
  480. $actualData[$name] = $value;
  481. }
  482. }
  483. if ( ! isset($this->originalEntityData[$oid])) {
  484. // Entity is either NEW or MANAGED but not yet fully persisted (only has an id).
  485. // These result in an INSERT.
  486. $this->originalEntityData[$oid] = $actualData;
  487. $changeSet = array();
  488. foreach ($actualData as $propName => $actualValue) {
  489. if ( ! isset($class->associationMappings[$propName])) {
  490. $changeSet[$propName] = array(null, $actualValue);
  491. continue;
  492. }
  493. $assoc = $class->associationMappings[$propName];
  494. if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) {
  495. $changeSet[$propName] = array(null, $actualValue);
  496. }
  497. }
  498. $this->entityChangeSets[$oid] = $changeSet;
  499. } else {
  500. // Entity is "fully" MANAGED: it was already fully persisted before
  501. // and we have a copy of the original data
  502. $originalData = $this->originalEntityData[$oid];
  503. $isChangeTrackingNotify = $class->isChangeTrackingNotify();
  504. $changeSet = ($isChangeTrackingNotify && isset($this->entityChangeSets[$oid]))
  505. ? $this->entityChangeSets[$oid]
  506. : array();
  507. foreach ($actualData as $propName => $actualValue) {
  508. // skip field, its a partially omitted one!
  509. if ( ! (isset($originalData[$propName]) || array_key_exists($propName, $originalData))) {
  510. continue;
  511. }
  512. $orgValue = $originalData[$propName];
  513. // skip if value havent changed
  514. if ($orgValue === $actualValue) {
  515. continue;
  516. }
  517. // if regular field
  518. if ( ! isset($class->associationMappings[$propName])) {
  519. if ($isChangeTrackingNotify) {
  520. continue;
  521. }
  522. $changeSet[$propName] = array($orgValue, $actualValue);
  523. continue;
  524. }
  525. $assoc = $class->associationMappings[$propName];
  526. // Persistent collection was exchanged with the "originally"
  527. // created one. This can only mean it was cloned and replaced
  528. // on another entity.
  529. if ($actualValue instanceof PersistentCollection) {
  530. $owner = $actualValue->getOwner();
  531. if ($owner === null) { // cloned
  532. $actualValue->setOwner($entity, $assoc);
  533. } else if ($owner !== $entity) { // no clone, we have to fix
  534. if (!$actualValue->isInitialized()) {
  535. $actualValue->initialize(); // we have to do this otherwise the cols share state
  536. }
  537. $newValue = clone $actualValue;
  538. $newValue->setOwner($entity, $assoc);
  539. $class->reflFields[$propName]->setValue($entity, $newValue);
  540. }
  541. }
  542. if ($orgValue instanceof PersistentCollection) {
  543. // A PersistentCollection was de-referenced, so delete it.
  544. $coid = spl_object_hash($orgValue);
  545. if (isset($this->collectionDeletions[$coid])) {
  546. continue;
  547. }
  548. $this->collectionDeletions[$coid] = $orgValue;
  549. $changeSet[$propName] = $orgValue; // Signal changeset, to-many assocs will be ignored.
  550. continue;
  551. }
  552. if ($assoc['type'] & ClassMetadata::TO_ONE) {
  553. if ($assoc['isOwningSide']) {
  554. $changeSet[$propName] = array($orgValue, $actualValue);
  555. }
  556. if ($orgValue !== null && $assoc['orphanRemoval']) {
  557. $this->scheduleOrphanRemoval($orgValue);
  558. }
  559. }
  560. }
  561. if ($changeSet) {
  562. $this->entityChangeSets[$oid] = $changeSet;
  563. $this->originalEntityData[$oid] = $actualData;
  564. $this->entityUpdates[$oid] = $entity;
  565. }
  566. }
  567. // Look for changes in associations of the entity
  568. foreach ($class->associationMappings as $field => $assoc) {
  569. if (($val = $class->reflFields[$field]->getValue($entity)) !== null) {
  570. $this->computeAssociationChanges($assoc, $val);
  571. if (!isset($this->entityChangeSets[$oid]) &&
  572. $assoc['isOwningSide'] &&
  573. $assoc['type'] == ClassMetadata::MANY_TO_MANY &&
  574. $val instanceof PersistentCollection &&
  575. $val->isDirty()) {
  576. $this->entityChangeSets[$oid] = array();
  577. $this->originalEntityData[$oid] = $actualData;
  578. $this->entityUpdates[$oid] = $entity;
  579. }
  580. }
  581. }
  582. }
  583. /**
  584. * Computes all the changes that have been done to entities and collections
  585. * since the last commit and stores these changes in the _entityChangeSet map
  586. * temporarily for access by the persisters, until the UoW commit is finished.
  587. *
  588. * @return void
  589. */
  590. public function computeChangeSets()
  591. {
  592. // Compute changes for INSERTed entities first. This must always happen.
  593. $this->computeScheduleInsertsChangeSets();
  594. // Compute changes for other MANAGED entities. Change tracking policies take effect here.
  595. foreach ($this->identityMap as $className => $entities) {
  596. $class = $this->em->getClassMetadata($className);
  597. // Skip class if instances are read-only
  598. if ($class->isReadOnly) {
  599. continue;
  600. }
  601. // If change tracking is explicit or happens through notification, then only compute
  602. // changes on entities of that type that are explicitly marked for synchronization.
  603. switch (true) {
  604. case ($class->isChangeTrackingDeferredImplicit()):
  605. $entitiesToProcess = $entities;
  606. break;
  607. case (isset($this->scheduledForDirtyCheck[$className])):
  608. $entitiesToProcess = $this->scheduledForDirtyCheck[$className];
  609. break;
  610. default:
  611. $entitiesToProcess = array();
  612. }
  613. foreach ($entitiesToProcess as $entity) {
  614. // Ignore uninitialized proxy objects
  615. if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
  616. continue;
  617. }
  618. // Only MANAGED entities that are NOT SCHEDULED FOR INSERTION are processed here.
  619. $oid = spl_object_hash($entity);
  620. if ( ! isset($this->entityInsertions[$oid]) && isset($this->entityStates[$oid])) {
  621. $this->computeChangeSet($class, $entity);
  622. }
  623. }
  624. }
  625. }
  626. /**
  627. * Computes the changes of an association.
  628. *
  629. * @param array $assoc
  630. * @param mixed $value The value of the association.
  631. *
  632. * @throws ORMInvalidArgumentException
  633. * @throws ORMException
  634. *
  635. * @return void
  636. */
  637. private function computeAssociationChanges($assoc, $value)
  638. {
  639. if ($value instanceof Proxy && ! $value->__isInitialized__) {
  640. return;
  641. }
  642. if ($value instanceof PersistentCollection && $value->isDirty()) {
  643. $coid = spl_object_hash($value);
  644. if ($assoc['isOwningSide']) {
  645. $this->collectionUpdates[$coid] = $value;
  646. }
  647. $this->visitedCollections[$coid] = $value;
  648. }
  649. // Look through the entities, and in any of their associations,
  650. // for transient (new) entities, recursively. ("Persistence by reachability")
  651. // Unwrap. Uninitialized collections will simply be empty.
  652. $unwrappedValue = ($assoc['type'] & ClassMetadata::TO_ONE) ? array($value) : $value->unwrap();
  653. $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
  654. foreach ($unwrappedValue as $key => $entry) {
  655. $state = $this->getEntityState($entry, self::STATE_NEW);
  656. if ( ! ($entry instanceof $assoc['targetEntity'])) {
  657. throw new ORMException(
  658. sprintf(
  659. 'Found entity of type %s on association %s#%s, but expecting %s',
  660. get_class($entry),
  661. $assoc['sourceEntity'],
  662. $assoc['fieldName'],
  663. $targetClass->name
  664. )
  665. );
  666. }
  667. switch ($state) {
  668. case self::STATE_NEW:
  669. if ( ! $assoc['isCascadePersist']) {
  670. throw ORMInvalidArgumentException::newEntityFoundThroughRelationship($assoc, $entry);
  671. }
  672. $this->persistNew($targetClass, $entry);
  673. $this->computeChangeSet($targetClass, $entry);
  674. break;
  675. case self::STATE_REMOVED:
  676. // Consume the $value as array (it's either an array or an ArrayAccess)
  677. // and remove the element from Collection.
  678. if ($assoc['type'] & ClassMetadata::TO_MANY) {
  679. unset($value[$key]);
  680. }
  681. break;
  682. case self::STATE_DETACHED:
  683. // Can actually not happen right now as we assume STATE_NEW,
  684. // so the exception will be raised from the DBAL layer (constraint violation).
  685. throw ORMInvalidArgumentException::detachedEntityFoundThroughRelationship($assoc, $entry);
  686. break;
  687. default:
  688. // MANAGED associated entities are already taken into account
  689. // during changeset calculation anyway, since they are in the identity map.
  690. }
  691. }
  692. }
  693. /**
  694. * @param \Doctrine\ORM\Mapping\ClassMetadata $class
  695. * @param object $entity
  696. *
  697. * @return void
  698. */
  699. private function persistNew($class, $entity)
  700. {
  701. $oid = spl_object_hash($entity);
  702. $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::prePersist);
  703. if ($invoke !== ListenersInvoker::INVOKE_NONE) {
  704. $this->listenersInvoker->invoke($class, Events::prePersist, $entity, new LifecycleEventArgs($entity, $this->em), $invoke);
  705. }
  706. $idGen = $class->idGenerator;
  707. if ( ! $idGen->isPostInsertGenerator()) {
  708. $idValue = $idGen->generate($this->em, $entity);
  709. if ( ! $idGen instanceof \Doctrine\ORM\Id\AssignedGenerator) {
  710. $idValue = array($class->identifier[0] => $idValue);
  711. $class->setIdentifierValues($entity, $idValue);
  712. }
  713. $this->entityIdentifiers[$oid] = $idValue;
  714. }
  715. $this->entityStates[$oid] = self::STATE_MANAGED;
  716. $this->scheduleForInsert($entity);
  717. }
  718. /**
  719. * INTERNAL:
  720. * Computes the changeset of an individual entity, independently of the
  721. * computeChangeSets() routine that is used at the beginning of a UnitOfWork#commit().
  722. *
  723. * The passed entity must be a managed entity. If the entity already has a change set
  724. * because this method is invoked during a commit cycle then the change sets are added.
  725. * whereby changes detected in this method prevail.
  726. *
  727. * @ignore
  728. *
  729. * @param ClassMetadata $class The class descriptor of the entity.
  730. * @param object $entity The entity for which to (re)calculate the change set.
  731. *
  732. * @return void
  733. *
  734. * @throws ORMInvalidArgumentException If the passed entity is not MANAGED.
  735. */
  736. public function recomputeSingleEntityChangeSet(ClassMetadata $class, $entity)
  737. {
  738. $oid = spl_object_hash($entity);
  739. if ( ! isset($this->entityStates[$oid]) || $this->entityStates[$oid] != self::STATE_MANAGED) {
  740. throw ORMInvalidArgumentException::entityNotManaged($entity);
  741. }
  742. // skip if change tracking is "NOTIFY"
  743. if ($class->isChangeTrackingNotify()) {
  744. return;
  745. }
  746. if ( ! $class->isInheritanceTypeNone()) {
  747. $class = $this->em->getClassMetadata(get_class($entity));
  748. }
  749. $actualData = array();
  750. foreach ($class->reflFields as $name => $refProp) {
  751. if ( ! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity()) {
  752. $actualData[$name] = $refProp->getValue($entity);
  753. }
  754. }
  755. $originalData = $this->originalEntityData[$oid];
  756. $changeSet = array();
  757. foreach ($actualData as $propName => $actualValue) {
  758. $orgValue = isset($originalData[$propName]) ? $originalData[$propName] : null;
  759. if (is_object($orgValue) && $orgValue !== $actualValue) {
  760. $changeSet[$propName] = array($orgValue, $actualValue);
  761. } else if ($orgValue != $actualValue || ($orgValue === null ^ $actualValue === null)) {
  762. $changeSet[$propName] = array($orgValue, $actualValue);
  763. }
  764. }
  765. if ($changeSet) {
  766. if (isset($this->entityChangeSets[$oid])) {
  767. $this->entityChangeSets[$oid] = array_merge($this->entityChangeSets[$oid], $changeSet);
  768. }
  769. $this->originalEntityData[$oid] = $actualData;
  770. }
  771. }
  772. /**
  773. * Executes all entity insertions for entities of the specified type.
  774. *
  775. * @param \Doctrine\ORM\Mapping\ClassMetadata $class
  776. *
  777. * @return void
  778. */
  779. private function executeInserts($class)
  780. {
  781. $entities = array();
  782. $className = $class->name;
  783. $persister = $this->getEntityPersister($className);
  784. $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postPersist);
  785. foreach ($this->entityInsertions as $oid => $entity) {
  786. if ($this->em->getClassMetadata(get_class($entity))->name !== $className) {
  787. continue;
  788. }
  789. $persister->addInsert($entity);
  790. unset($this->entityInsertions[$oid]);
  791. if ($invoke !== ListenersInvoker::INVOKE_NONE) {
  792. $entities[] = $entity;
  793. }
  794. }
  795. $postInsertIds = $persister->executeInserts();
  796. if ($postInsertIds) {
  797. // Persister returned post-insert IDs
  798. foreach ($postInsertIds as $id => $entity) {
  799. $oid = spl_object_hash($entity);
  800. $idField = $class->identifier[0];
  801. $class->reflFields[$idField]->setValue($entity, $id);
  802. $this->entityIdentifiers[$oid] = array($idField => $id);
  803. $this->entityStates[$oid] = self::STATE_MANAGED;
  804. $this->originalEntityData[$oid][$idField] = $id;
  805. $this->addToIdentityMap($entity);
  806. }
  807. }
  808. foreach ($entities as $entity) {
  809. $this->listenersInvoker->invoke($class, Events::postPersist, $entity, new LifecycleEventArgs($entity, $this->em), $invoke);
  810. }
  811. }
  812. /**
  813. * Executes all entity updates for entities of the specified type.
  814. *
  815. * @param \Doctrine\ORM\Mapping\ClassMetadata $class
  816. *
  817. * @return void
  818. */
  819. private function executeUpdates($class)
  820. {
  821. $className = $class->name;
  822. $persister = $this->getEntityPersister($className);
  823. $preUpdateInvoke = $this->listenersInvoker->getSubscribedSystems($class, Events::preUpdate);
  824. $postUpdateInvoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postUpdate);
  825. foreach ($this->entityUpdates as $oid => $entity) {
  826. if ($this->em->getClassMetadata(get_class($entity))->name !== $className) {
  827. continue;
  828. }
  829. if ($preUpdateInvoke != ListenersInvoker::INVOKE_NONE) {
  830. $this->listenersInvoker->invoke($class, Events::preUpdate, $entity, new PreUpdateEventArgs($entity, $this->em, $this->entityChangeSets[$oid]), $preUpdateInvoke);
  831. $this->recomputeSingleEntityChangeSet($class, $entity);
  832. }
  833. if ( ! empty($this->entityChangeSets[$oid])) {
  834. $persister->update($entity);
  835. }
  836. unset($this->entityUpdates[$oid]);
  837. if ($postUpdateInvoke != ListenersInvoker::INVOKE_NONE) {
  838. $this->listenersInvoker->invoke($class, Events::postUpdate, $entity, new LifecycleEventArgs($entity, $this->em), $postUpdateInvoke);
  839. }
  840. }
  841. }
  842. /**
  843. * Executes all entity deletions for entities of the specified type.
  844. *
  845. * @param \Doctrine\ORM\Mapping\ClassMetadata $class
  846. *
  847. * @return void
  848. */
  849. private function executeDeletions($class)
  850. {
  851. $className = $class->name;
  852. $persister = $this->getEntityPersister($className);
  853. $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postRemove);
  854. foreach ($this->entityDeletions as $oid => $entity) {
  855. if ($this->em->getClassMetadata(get_class($entity))->name !== $className) {
  856. continue;
  857. }
  858. $persister->delete($entity);
  859. unset(
  860. $this->entityDeletions[$oid],
  861. $this->entityIdentifiers[$oid],
  862. $this->originalEntityData[$oid],
  863. $this->entityStates[$oid]
  864. );
  865. // Entity with this $oid after deletion treated as NEW, even if the $oid
  866. // is obtained by a new entity because the old one went out of scope.
  867. //$this->entityStates[$oid] = self::STATE_NEW;
  868. if ( ! $class->isIdentifierNatural()) {
  869. $class->reflFields[$class->identifier[0]]->setValue($entity, null);
  870. }
  871. if ($invoke !== ListenersInvoker::INVOKE_NONE) {
  872. $this->listenersInvoker->invoke($class, Events::postRemove, $entity, new LifecycleEventArgs($entity, $this->em), $invoke);
  873. }
  874. }
  875. }
  876. /**
  877. * Gets the commit order.
  878. *
  879. * @param array|null $entityChangeSet
  880. *
  881. * @return array
  882. */
  883. private function getCommitOrder(array $entityChangeSet = null)
  884. {
  885. if ($entityChangeSet === null) {
  886. $entityChangeSet = array_merge($this->entityInsertions, $this->entityUpdates, $this->entityDeletions);
  887. }
  888. $calc = $this->getCommitOrderCalculator();
  889. // See if there are any new classes in the changeset, that are not in the
  890. // commit order graph yet (dont have a node).
  891. // We have to inspect changeSet to be able to correctly build dependencies.
  892. // It is not possible to use IdentityMap here because post inserted ids
  893. // are not yet available.
  894. $newNodes = array();
  895. foreach ($entityChangeSet as $entity) {
  896. $className = $this->em->getClassMetadata(get_class($entity))->name;
  897. if ($calc->hasClass($className)) {
  898. continue;
  899. }
  900. $class = $this->em->getClassMetadata($className);
  901. $calc->addClass($class);
  902. $newNodes[] = $class;
  903. }
  904. // Calculate dependencies for new nodes
  905. while ($class = array_pop($newNodes)) {
  906. foreach ($class->associationMappings as $assoc) {
  907. if ( ! ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) {
  908. continue;
  909. }
  910. $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
  911. if ( ! $calc->hasClass($targetClass->name)) {
  912. $calc->addClass($targetClass);
  913. $newNodes[] = $targetClass;
  914. }
  915. $calc->addDependency($targetClass, $class);
  916. // If the target class has mapped subclasses, these share the same dependency.
  917. if ( ! $targetClass->subClasses) {
  918. continue;
  919. }
  920. foreach ($targetClass->subClasses as $subClassName) {
  921. $targetSubClass = $this->em->getClassMetadata($subClassName);
  922. if ( ! $calc->hasClass($subClassName)) {
  923. $calc->addClass($targetSubClass);
  924. $newNodes[] = $targetSubClass;
  925. }
  926. $calc->addDependency($targetSubClass, $class);
  927. }
  928. }
  929. }
  930. return $calc->getCommitOrder();
  931. }
  932. /**
  933. * Schedules an entity for insertion into the database.
  934. * If the entity already has an identifier, it will be added to the identity map.
  935. *
  936. * @param object $entity The entity to schedule for insertion.
  937. *
  938. * @return void
  939. *
  940. * @throws ORMInvalidArgumentException
  941. * @throws \InvalidArgumentException
  942. */
  943. public function scheduleForInsert($entity)
  944. {
  945. $oid = spl_object_hash($entity);
  946. if (isset($this->entityUpdates[$oid])) {
  947. throw new InvalidArgumentException("Dirty entity can not be scheduled for insertion.");
  948. }
  949. if (isset($this->entityDeletions[$oid])) {
  950. throw ORMInvalidArgumentException::scheduleInsertForRemovedEntity($entity);
  951. }
  952. if (isset($this->originalEntityData[$oid]) && ! isset($this->entityInsertions[$oid])) {
  953. throw ORMInvalidArgumentException::scheduleInsertForManagedEntity($entity);
  954. }
  955. if (isset($this->entityInsertions[$oid])) {
  956. throw ORMInvalidArgumentException::scheduleInsertTwice($entity);
  957. }
  958. $this->entityInsertions[$oid] = $entity;
  959. if (isset($this->entityIdentifiers[$oid])) {
  960. $this->addToIdentityMap($entity);
  961. }
  962. if ($entity instanceof NotifyPropertyChanged) {
  963. $entity->addPropertyChangedListener($this);
  964. }
  965. }
  966. /**
  967. * Checks whether an entity is scheduled for insertion.
  968. *
  969. * @param object $entity
  970. *
  971. * @return boolean
  972. */
  973. public function isScheduledForInsert($entity)
  974. {
  975. return isset($this->entityInsertions[spl_object_hash($entity)]);
  976. }
  977. /**
  978. * Schedules an entity for being updated.
  979. *
  980. * @param object $entity The entity to schedule for being updated.
  981. *
  982. * @return void
  983. *
  984. * @throws ORMInvalidArgumentException
  985. */
  986. public function scheduleForUpdate($entity)
  987. {
  988. $oid = spl_object_hash($entity);
  989. if ( ! isset($this->entityIdentifiers[$oid])) {
  990. throw ORMInvalidArgumentException::entityHasNoIdentity($entity, "scheduling for update");
  991. }
  992. if (isset($this->entityDeletions[$oid])) {
  993. throw ORMInvalidArgumentException::entityIsRemoved($entity, "schedule for update");
  994. }
  995. if ( ! isset($this->entityUpdates[$oid]) && ! isset($this->entityInsertions[$oid])) {
  996. $this->entityUpdates[$oid] = $entity;
  997. }
  998. }
  999. /**
  1000. * INTERNAL:
  1001. * Schedules an extra update that will be executed immediately after the
  1002. * regular entity updates within the currently running commit cycle.
  1003. *
  1004. * Extra updates for entities are stored as (entity, changeset) tuples.
  1005. *
  1006. * @ignore
  1007. *
  1008. * @param object $entity The entity for which to schedule an extra update.
  1009. * @param array $changeset The changeset of the entity (what to update).
  1010. *
  1011. * @return void
  1012. */
  1013. public function scheduleExtraUpdate($entity, array $changeset)
  1014. {
  1015. $oid = spl_object_hash($entity);
  1016. $extraUpdate = array($entity, $changeset);
  1017. if (isset($this->extraUpdates[$oid])) {
  1018. list($ignored, $changeset2) = $this->extraUpdates[$oid];
  1019. $extraUpdate = array($entity, $changeset + $changeset2);
  1020. }
  1021. $this->extraUpdates[$oid] = $extraUpdate;
  1022. }
  1023. /**
  1024. * Checks whether an entity is registered as dirty in the unit of work.
  1025. * Note: Is not very useful currently as dirty entities are only registered
  1026. * at commit time.
  1027. *
  1028. * @param object $entity
  1029. *
  1030. * @return boolean
  1031. */
  1032. public function isScheduledForUpdate($entity)
  1033. {
  1034. return isset($this->entityUpdates[spl_object_hash($entity)]);
  1035. }
  1036. /**
  1037. * Checks whether an entity is registered to be checked in the unit of work.
  1038. *
  1039. * @param object $entity
  1040. *
  1041. * @return boolean
  1042. */
  1043. public function isScheduledForDirtyCheck($entity)
  1044. {
  1045. $rootEntityName = $this->em->getClassMetadata(get_class($entity))->rootEntityName;
  1046. return isset($this->scheduledForDirtyCheck[$rootEntityName][spl_object_hash($entity)]);
  1047. }
  1048. /**
  1049. * INTERNAL:
  1050. * Schedules an entity for deletion.
  1051. *
  1052. * @param object $entity
  1053. *
  1054. * @return void
  1055. */
  1056. public function scheduleForDelete($entity)
  1057. {
  1058. $oid = spl_object_hash($entity);
  1059. if (isset($this->entityInsertions[$oid])) {
  1060. if ($this->isInIdentityMap($entity)) {
  1061. $this->removeFromIdentityMap($entity);
  1062. }
  1063. unset($this->entityInsertions[$oid], $this->entityStates[$oid]);
  1064. return; // entity has not been persisted yet, so nothing more to do.
  1065. }
  1066. if ( ! $this->isInIdentityMap($entity)) {
  1067. return;
  1068. }
  1069. $this->removeFromIdentityMap($entity);
  1070. if (isset($this->entityUpdates[$oid])) {
  1071. unset($this->entityUpdates[$oid]);
  1072. }
  1073. if ( ! isset($this->entityDeletions[$oid])) {
  1074. $this->entityDeletions[$oid] = $entity;
  1075. $this->entityStates[$oid] = self::STATE_REMOVED;
  1076. }
  1077. }
  1078. /**
  1079. * Checks whether an entity is registered as removed/deleted with the unit
  1080. * of work.
  1081. *
  1082. * @param object $entity
  1083. *
  1084. * @return boolean
  1085. */
  1086. public function isScheduledForDelete($entity)
  1087. {
  1088. return isset($this->entityDeletions[spl_object_hash($entity)]);
  1089. }
  1090. /**
  1091. * Checks whether an entity is scheduled for insertion, update or deletion.
  1092. *
  1093. * @param object $entity
  1094. *
  1095. * @return boolean
  1096. */
  1097. public function isEntityScheduled($entity)
  1098. {
  1099. $oid = spl_object_hash($entity);
  1100. return isset($this->entityInsertions[$oid])
  1101. || isset($this->entityUpdates[$oid])
  1102. || isset($this->entityDeletions[$oid]);
  1103. }
  1104. /**
  1105. * INTERNAL:
  1106. * Registers an entity in the identity map.
  1107. * Note that entities in a hierarchy are registered with the class name of
  1108. * the root entity.
  1109. *
  1110. * @ignore
  1111. *
  1112. * @param object $entity The entity to register.
  1113. *
  1114. * @return boolean TRUE if the registration was successful, FALSE if the identity of
  1115. * the entity in question is already managed.
  1116. *
  1117. * @throws ORMInvalidArgumentException
  1118. */
  1119. public function addToIdentityMap($entity)
  1120. {
  1121. $classMetadata = $this->em->getClassMetadata(get_class($entity));
  1122. $idHash = implode(' ', $this->entityIdentifiers[spl_object_hash($entity)]);
  1123. if ($idHash === '') {
  1124. throw ORMInvalidArgumentException::entityWithoutIdentity($classMetadata->name, $entity);
  1125. }
  1126. $className = $classMetadata->rootEntityName;
  1127. if (isset($this->identityMap[$className][$idHash])) {
  1128. return false;
  1129. }
  1130. $this->identityMap[$className][$idHash] = $entity;
  1131. return true;
  1132. }
  1133. /**
  1134. * Gets the state of an entity with regard to the current unit of work.
  1135. *
  1136. * @param object $entity
  1137. * @param int|null $assume The state to assume if the state is not yet known (not MANAGED or REMOVED).
  1138. * This parameter can be set to improve performance of entity state detection
  1139. * by potentially avoiding a database lookup if the distinction between NEW and DETACHED
  1140. * is either known or does not matter for the caller of the method.
  1141. *
  1142. * @return int The entity state.
  1143. */
  1144. public function getEntityState($entity, $assume = null)
  1145. {
  1146. $oid = spl_object_hash($entity);
  1147. if (isset($this->entityStates[$oid])) {
  1148. return $this->entityStates[$oid];
  1149. }
  1150. if ($assume !== null) {
  1151. return $assume;
  1152. }
  1153. // State can only be NEW or DETACHED, because MANAGED/REMOVED states are known.
  1154. // Note that you can not remember the NEW or DETACHED state in _entityStates since
  1155. // the UoW does not hold references to such objects and the object hash can be reused.
  1156. // More generally because the state may "change" between NEW/DETACHED without the UoW being aware of it.
  1157. $class = $this->em->getClassMetadata(get_class($entity));
  1158. $id = $class->getIdentifierValues($entity);
  1159. if ( ! $id) {
  1160. return self::STATE_NEW;
  1161. }
  1162. if ($class->containsForeignIdentifier) {
  1163. $id = $this->flattenIdentifier($class, $id);
  1164. }
  1165. switch (true) {
  1166. case ($class->isIdentifierNatural());
  1167. // Check for a version field, if available, to avoid a db lookup.
  1168. if ($class->isVersioned) {
  1169. return ($class->getFieldValue($entity, $class->versionField))
  1170. ? self::STATE_DETACHED
  1171. : self::STATE_NEW;
  1172. }
  1173. // Last try before db lookup: check the identity map.
  1174. if ($this->tryGetById($id, $class->rootEntityName)) {
  1175. return self::STATE_DETACHED;
  1176. }
  1177. // db lookup
  1178. if ($this->getEntityPersister($class->name)->exists($entity)) {
  1179. return self::STATE_DETACHED;
  1180. }
  1181. return self::STATE_NEW;
  1182. case ( ! $class->idGenerator->isPostInsertGenerator()):
  1183. // if we have a pre insert generator we can't be sure that having an id
  1184. // really means that the entity exists. We have to verify this through
  1185. // the last resort: a db lookup
  1186. // Last try before db lookup: check the identity map.
  1187. if ($this->tryGetById($id, $class->rootEntityName)) {
  1188. return self::STATE_DETACHED;
  1189. }
  1190. // db lookup
  1191. if ($this->getEntityPersister($class->name)->exists($entity)) {
  1192. return self::STATE_DETACHED;
  1193. }
  1194. return self::STATE_NEW;
  1195. default:
  1196. return self::STATE_DETACHED;
  1197. }
  1198. }
  1199. /**
  1200. * INTERNAL:
  1201. * Removes an entity from the identity map. This effectively detaches the
  1202. * entity from the persistence management of Doctrine.
  1203. *
  1204. * @ignore
  1205. *
  1206. * @param object $entity
  1207. *
  1208. * @return boolean
  1209. *
  1210. * @throws ORMInvalidArgumentException
  1211. */
  1212. public function removeFromIdentityMap($entity)
  1213. {
  1214. $oid = spl_object_hash($entity);
  1215. $classMetadata = $this->em->getClassMetadata(get_class($entity));
  1216. $idHash = implode(' ', $this->entityIdentifiers[$oid]);
  1217. if ($idHash === '') {
  1218. throw ORMInvalidArgumentException::entityHasNoIdentity($entity, "remove from identity map");
  1219. }
  1220. $className = $classMetadata->rootEntityName;
  1221. if (isset($this->identityMap[$className][$idHash])) {
  1222. unset($this->identityMap[$className][$idHash]);
  1223. unset($this->readOnlyObjects[$oid]);
  1224. //$this->entityStates[$oid] = self::STATE_DETACHED;
  1225. return true;
  1226. }
  1227. return false;
  1228. }
  1229. /**
  1230. * INTERNAL:
  1231. * Gets an entity in the identity map by its id…

Large files files are truncated, but you can click here to view the full file