1
0
mirror of synced 2025-02-20 22:23:14 +03:00

More deprecated code removal.

This commit is contained in:
Guilherme Blanco 2015-01-13 02:52:31 +00:00
parent 965cdbdbbb
commit 678f47f494

View File

@ -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;
}
}