Updates a PersistentCollection instance deleting removed rows and
inserting new rows.

@param PersistentCollectionInterface $coll
974889
public function update(PersistentCollectionInterface $coll)
    {
        $mapping = $coll->getMapping();

        if ($mapping->isInverseSide) {
            return; // ignore inverse side
        }

        switch ($mapping->strategy) {
            case PropertyMetadata::STORAGE_STRATEGY_ATOMIC_SET:
                throw new \UnexpectedValueException(sprintf('%s update collection strategy should have been handled by DocumentPersister. Please report a bug in issue tracker', $mapping->strategy));

            case PropertyMetadata::STORAGE_STRATEGY_SET:
                $this->setCollection($coll);
                break;

            case PropertyMetadata::STORAGE_STRATEGY_ADD_TO_SET:
            case PropertyMetadata::STORAGE_STRATEGY_LIST_APPEND:
                $coll->initialize();
                $this->deleteElements($coll);
                $this->insertElements($coll);
                break;

            default:
                throw new \UnexpectedValueException(sprintf('Unsupported collection strategy: %s', $mapping->strategy));
        }
    }
1214870
public function delete(PersistenceContext $context, Delete $parentDelete)
    {
        $this->mode->removeRelationsQuery(
            $context,
            $this->mapper,
            $parentDelete,
            $this->childrenTable,
            $this->foreignKeyToParent,
            $parentDelete->getTable()->getPrimaryKeyColumn()
        );
    }
1345290
protected function basePostUpdate($affectedRows, ConnectionInterface $con)
    {
        // aggregate_column_relation_aggregate_column behavior
        $this->updateRelatedGroupSkillCounts($con);

        return $this->postUpdate($affectedRows, $con);
    }
291520
public function intersect(ICollection $coll){
		
		//array_intersect does not work on \Closure objects
	
		$arr = array();
		$coll->copyTo($arr);
		
		$ret = array();
		
		foreach($this->_Arr as $outerItem){
			foreach($arr as $innerItem){
				
				if($innerItem === $outerItem){
					$ret[] = $outerItem;
					break;
				}
				
			}
		}
		
		return new static($ret);
		
	}
15221
public function updateDataCollection($entries)
    {
        $process = false;
        $data = [];
        $start = ($this->currentPage - 1) * $this->dataCollection->getPageSize();
        foreach ($entries as $key => $value) {
            if (substr($key, 0, 6) == "entry_") {
                $array = explode("_", str_replace("entry_", "", $key));
                setType($value, $array[1]);
                $data[$array[0]] = $value;
                $process = true;
            }
        }
        if ($process) {
            $lines = $this->dataCollection->getData($this->currentPage);
            $counter = 0;
            foreach ($lines as $i => $lineData) {
                $newData = $lineData;
                foreach ($this->columns as $columnData) {
                    if ($columnData instanceof InputColumn) {
                        $newData[$columnData->getKey()] = $data[$counter];
                    }
                }
                $this->dataCollection->setDataByIndex($start + $counter, $newData);
                $counter++;
            }
        }
    }
617376
protected function basePostUpdate($affectedRows, ConnectionInterface $con)
    {
        // aggregate_column_relation_aggregate_column behavior
        $this->updateRelatedObjectSkillCounts($con);

        return $this->postUpdate($affectedRows, $con);
    }
793182
public function loadCollection(PersistentCollectionInterface $collection)
    {
        $mapping = $collection->getMapping();
        switch ($mapping->association) {
            case PropertyMetadata::ASSOCIATION_TYPE_EMBED_MANY:
                $this->loadEmbedManyCollection($collection);
                break;

            case PropertyMetadata::ASSOCIATION_TYPE_REFERENCE_MANY:
                if ($mapping->repositoryMethod !== null) {
                    $this->loadReferenceManyWithRepositoryMethod($collection);
                } else {
                    if ($mapping->isOwningSide) {
                        $this->loadReferenceManyCollectionOwningSide($collection);
                    } else {
                        $this->loadReferenceManyCollectionInverseSide($collection);
                    }
                }
                break;
        }
    }
205675
protected function getDeleteSQLParameters(PersistentCollection $collection)
    {
        $mapping    = $collection->getMapping();
        $identifier = $this->uow->getEntityIdentifier($collection->getOwner());

        // Optimization for single column identifier
        if (count($mapping['relationToSourceKeyColumns']) === 1) {
            return array(reset($identifier));
        }

        // Composite identifier
        $sourceClass = $this->em->getClassMetadata($mapping['sourceEntity']);
        $params      = array();

        foreach ($mapping['relationToSourceKeyColumns'] as $columnName => $refColumnName) {
            $params[] = isset($sourceClass->fieldNames[$refColumnName])
                ? $identifier[$sourceClass->fieldNames[$refColumnName]]
                : $identifier[$sourceClass->getFieldForColumn($columnName)];
        }

        return $params;
    }
1110172
protected function persistObjects()
    {
        $this->visitedDuringPersistence = new \SplObjectStorage();
        foreach ($this->aggregateRootObjects as $object) {
            $this->persistObject($object, null);
        }
        foreach ($this->changedEntities as $object) {
            $this->persistObject($object, null);
        }
    }
20438
final public function updateCollectionObject() {
		if (!empty($this->collection_object) && !empty($this->collection)) {
			$this->collection_object->data = array_merge_hard($this->collection_object->data, $this->collection);
		}
	}
353890
public function deleteCollection($collectionId, ?int $status = null): void
    {
        // Delete all connections between blocks and collections

        $query = $this->connection->createQueryBuilder();
        $query
            ->delete('ngbm_block_collection')
            ->where(
                $query->expr()->eq('collection_id', ':collection_id')
            )
            ->setParameter('collection_id', $collectionId, Type::INTEGER);

        if ($status !== null) {
            $this->applyStatusCondition($query, $status, 'collection_status');
        }

        $query->execute();

        // Then delete the collection itself

        $query = $this->connection->createQueryBuilder();
        $query->delete('ngbm_collection')
            ->where(
                $query->expr()->eq('id', ':id')
            )
            ->setParameter('id', $collectionId, Type::INTEGER);

        if ($status !== null) {
            $this->applyStatusCondition($query, $status);
        }

        $query->execute();
    }
1088845
public function persistAll($onlyWhitelistedObjects = false)
    {
        if ($onlyWhitelistedObjects) {
            foreach ($this->changedObjects as $object) {
                $this->throwExceptionIfObjectIsNotWhitelisted($object);
            }
            foreach ($this->removedObjects as $object) {
                $this->throwExceptionIfObjectIsNotWhitelisted($object);
            }
            foreach ($this->addedObjects as $object) {
                $this->throwExceptionIfObjectIsNotWhitelisted($object);
            }
        }

        // hand in only aggregate roots, leaving handling of subobjects to
        // the underlying storage layer
        // reconstituted entities must be fetched from the session and checked
        // for changes by the underlying backend as well!
        $this->backend->setAggregateRootObjects($this->addedObjects);
        $this->backend->setChangedEntities($this->changedObjects);
        $this->backend->setDeletedEntities($this->removedObjects);
        $this->backend->commit();

        $this->addedObjects = new \SplObjectStorage();
        $this->removedObjects = new \SplObjectStorage();
        $this->changedObjects = new \SplObjectStorage();

        $this->emitAllObjectsPersisted();
        $this->hasUnpersistedChanges = false;
    }
773822
protected function updateCollectionItem()
    {
        $this->controlAccess('collection_item_edit');

        if ($this->collection_item->update($this->data_collection_item['collection_item_id'], $this->getSubmitted())) {
            $url = "admin/content/collection-item/{$this->data_collection['collection_id']}";
            $this->redirect($url, $this->text('Collection item has been updated'), 'success');
        }

        $this->redirect('', $this->text('Collection item has not been updated'), 'warning');
    }
660072
protected function getDeleteRowSQL(PersistentCollection $collection)
    {
        $association = $collection->getMapping();
        $class       = $this->em->getClassMetadata($association->getSourceEntity());
        $targetClass = $this->em->getClassMetadata($association->getTargetEntity());
        $columns     = [];
        $types       = [];

        $joinTable     = $association->getJoinTable();
        $joinTableName = $joinTable->getQuotedQualifiedName($this->platform);

        foreach ($joinTable->getJoinColumns() as $joinColumn) {
            /** @var JoinColumnMetadata $joinColumn */
            $quotedColumnName     = $this->platform->quoteIdentifier($joinColumn->getColumnName());
            $referencedColumnName = $joinColumn->getReferencedColumnName();

            if (! $joinColumn->getType()) {
                $joinColumn->setType(PersisterHelper::getTypeOfColumn($referencedColumnName, $class, $this->em));
            }

            $columns[] = $quotedColumnName;
            $types[]   = $joinColumn->getType();
        }

        foreach ($joinTable->getInverseJoinColumns() as $joinColumn) {
            /** @var JoinColumnMetadata $joinColumn */
            $quotedColumnName     = $this->platform->quoteIdentifier($joinColumn->getColumnName());
            $referencedColumnName = $joinColumn->getReferencedColumnName();

            if (! $joinColumn->getType()) {
                $joinColumn->setType(PersisterHelper::getTypeOfColumn($referencedColumnName, $targetClass, $this->em));
            }

            $columns[] = $quotedColumnName;
            $types[]   = $joinColumn->getType();
        }

        return [
            sprintf('DELETE FROM %s WHERE %s = ?', $joinTableName, implode(' = ? AND ', $columns)),
            $types,
        ];
    }
1348301
public function scheduleCollectionDeletion(PersistentCollection $coll)
    {
        $coid = spl_object_hash($coll);

        // TODO: if $coll is already scheduled for recreation ... what to do?
        // Just remove $coll from the scheduled recreations?
        if (isset($this->collectionUpdates[$coid])) {
            unset($this->collectionUpdates[$coid]);
        }

        $this->collectionDeletions[$coid] = $coll;
    }
1265673
private function loadReferenceManyCollectionOwningSide(PersistentCollectionInterface $collection)
    {
        $mapping = $collection->getMapping();

        /** @var Identifier[] $identifiers */
        $identifiers = array_map(
            function ($referenceData) use ($mapping) {
                return $this->ap->loadReference($mapping, $referenceData);
            },
            $collection->getRawData()
        );

        //reverse + limit must be applied here rather than on the query,
        //since we are potentially performing multiple queries
        if ($mapping->reverse) {
            $identifiers = array_reverse($identifiers);
        }
        if ($mapping->limit !== null) {
            $identifiers = array_slice($identifiers, 0, $mapping->limit);
        }

        //build document proxies and group by class
        $groupedIds = [];
        foreach ($identifiers as $key => $identifier) {
            //create a reference to the class+id and add it to the collection
            $reference = $identifier->getDocument($this->dm);

            if ($mapping->type === Type::MAP) {
                $collection->set($key, $reference);
            } else {
                $collection->add($reference);
            }

            //only query for the referenced object if it is not already initialized
            if ($reference instanceof Proxy && !$reference->__isInitialized__) {
                $className                = $identifier->class->name;
                $groupedIds[$className][] = $identifier;
            }
        }

        //load documents
        foreach ($groupedIds as $className => $batch) {
            $class   = $this->dm->getClassMetadata($className);
            $filters = array_merge(
                [(array)$mapping->criteria],
                $this->dm->getFilterCollection()->getFilterCriteria($class)
            );

            $qb = $this->dm->createQueryBuilder($className);

            if (!empty($filters)) {
                //filters require a full table scan
                //TODO: needs documentation

                //add identifiers to the query as OR conditions
                /** @var Identifier $identifier */
                foreach ($batch as $identifier) {
                    $expr = $qb->expr();
                    $identifier->addToQueryCondition($expr);
                    $qb->addOr($expr);
                }

                //add any other filter criteria
                foreach ($filters as $filter) {
                    $qb->addCriteria($filter);
                }

                $query = $qb->getQuery();
            } else {
                //load using batchgetitem
                foreach ($batch as $identifier) {
                    $qb->get()->setIdentifier($identifier)->batch();
                }

                $query = $qb->getBatch();
            }

            foreach ($query->getMarshalledResult() as $documentData) {
                $identifier = $class->createIdentifier($documentData);
                $document   = $this->uow->getByIdentifier($identifier);

                if ($document instanceof Proxy && !$document->__isInitialized()) {
                    $data = $this->hydratorFactory->hydrate($document, $documentData);
                    $this->uow->setOriginalDocumentData($document, $data);
                    $document->__isInitialized__ = true;
                }
            }
        }
    }
1347327
private function loadReferenceManyCollectionInverseSide(PersistentCollectionInterface $collection)
    {
        $query     = $this->createReferenceInverseSideQuery($collection->getMapping(), $collection->getOwner());
        $documents = $query->execute()->toArray();

        foreach ($documents as $key => $document) {
            $collection->add($document);
        }
    }