From 678f47f494539019c8349de420c38dd489860c67 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Tue, 13 Jan 2015 02:52:31 +0000 Subject: [PATCH] More deprecated code removal. --- .../ORM/Persisters/OneToManyPersister.php | 92 ++++++------------- 1 file changed, 26 insertions(+), 66 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php index 5727111a1..239477edb 100644 --- a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php @@ -70,55 +70,6 @@ class OneToManyPersister extends AbstractCollectionPersister return $persister->load(array($mapping['mappedBy'] => $coll->getOwner(), $mapping['indexBy'] => $index), null, null, array(), null, 1); } - /** - * Generates the SQL UPDATE that updates a particular row's foreign - * key to null. - * - * @param \Doctrine\ORM\PersistentCollection $coll - * - * @return string - * - * @override - */ - protected function getDeleteRowSQL(PersistentCollection $coll) - { - $mapping = $coll->getMapping(); - $class = $this->em->getClassMetadata($mapping['targetEntity']); - $tableName = $this->quoteStrategy->getTableName($class, $this->platform); - $idColumns = $class->getIdentifierColumnNames(); - - return 'DELETE FROM ' . $tableName - . ' WHERE ' . implode('= ? AND ', $idColumns) . ' = ?'; - } - - /** - * {@inheritdoc} - */ - protected function getDeleteRowSQLParameters(PersistentCollection $coll, $element) - { - return array_values($this->uow->getEntityIdentifier($element)); - } - - /** - * {@inheritdoc} - * - * @throws \BadMethodCallException Not used for OneToManyPersister. - */ - protected function getInsertRowSQL(PersistentCollection $coll) - { - throw new \BadMethodCallException("Insert Row SQL is not used for OneToManyPersister"); - } - - /** - * {@inheritdoc} - * - * @throws \BadMethodCallException Not used for OneToManyPersister. - */ - protected function getInsertRowSQLParameters(PersistentCollection $coll, $element) - { - throw new \BadMethodCallException("Insert Row SQL is not used for OneToManyPersister"); - } - /** * {@inheritdoc} */ @@ -170,14 +121,7 @@ class OneToManyPersister extends AbstractCollectionPersister */ public function contains(PersistentCollection $coll, $element) { - $entityState = $this->uow->getEntityState($element, UnitOfWork::STATE_NEW); - - if ($entityState === UnitOfWork::STATE_NEW) { - return false; - } - - // Entity is scheduled for inclusion - if ($entityState === UnitOfWork::STATE_MANAGED && $this->uow->isScheduledForInsert($element)) { + if ( ! $this->isValidEntityState($element)) { return false; } @@ -197,15 +141,7 @@ class OneToManyPersister extends AbstractCollectionPersister */ public function removeElement(PersistentCollection $coll, $element) { - $entityState = $this->uow->getEntityState($element, UnitOfWork::STATE_NEW); - - if ($entityState === UnitOfWork::STATE_NEW) { - return false; - } - - // If Entity is scheduled for inclusion, it is not in this collection. - // We can assure that because it would have return true before on array check - if ($entityState === UnitOfWork::STATE_MANAGED && $this->uow->isScheduledForInsert($element)) { + if ( ! $this->isValidEntityState($element)) { return false; } @@ -222,4 +158,28 @@ class OneToManyPersister extends AbstractCollectionPersister { throw new \BadMethodCallException("Filtering a collection by Criteria is not supported by this CollectionPersister."); } + + /** + * Check if entity is in a valid state for operations. + * + * @param $entity + * + * @return bool + */ + private function isValidEntityState($entity) + { + $entityState = $this->uow->getEntityState($entity, UnitOfWork::STATE_NEW); + + if ($entityState === UnitOfWork::STATE_NEW) { + return false; + } + + // If Entity is scheduled for inclusion, it is not in this collection. + // We can assure that because it would have return true before on array check + if ($entityState === UnitOfWork::STATE_MANAGED && $this->uow->isScheduledForInsert($entity)) { + return false; + } + + return true; + } }