Deletes removed elements from a list of PersistentCollection instances.

This method is intended to be used with the "pushAll" and "addToSet" strategies.

@param PersistentCollectionInterface[] $collections
@param array                           $options
425269
private function deleteElements(object $parent, array $collections, array $options) : void
    {
        $pathCollMap   = [];
        $paths         = [];
        $deleteDiffMap = [];

        foreach ($collections as $coll) {
            $coll->initialize();
            if (! $this->uow->isCollectionScheduledForUpdate($coll)) {
                continue;
            }
            $deleteDiff = $coll->getDeleteDiff();

            if (empty($deleteDiff)) {
                continue;
            }
            [$propertyPath ] = $this->getPathAndParent($coll);

            $pathCollMap[$propertyPath]   = $coll;
            $paths[]                      = $propertyPath;
            $deleteDiffMap[$propertyPath] = $deleteDiff;
        }

        $paths        = $this->excludeSubPaths($paths);
        $deleteColls  = array_intersect_key($pathCollMap, array_flip($paths));
        $unsetPayload = [];
        $pullPayload  = [];
        foreach ($deleteColls as $propertyPath => $coll) {
            $deleteDiff = $deleteDiffMap[$propertyPath];
            foreach ($deleteDiff as $key => $document) {
                $unsetPayload[$propertyPath . '.' . $key] = true;
            }
            $pullPayload[$propertyPath] = null;
        }

        if (! empty($unsetPayload)) {
            $this->executeQuery($parent, ['$unset' => $unsetPayload], $options);
        }
        if (empty($pullPayload)) {
            return;
        }

        /**
         * @todo This is a hack right now because we don't have a proper way to
         * remove an element from an array by its key. Unsetting the key results
         * in the element being left in the array as null so we have to pull
         * null values.
         */
        $this->executeQuery($parent, ['$pull' => $pullPayload], $options);
    }
279002
public static <D extends DestroyInterface> void
    cleanUp(Collection<D> destroyCollection) {
        JMOptional.getOptional(destroyCollection).ifPresent(
                collection -> collection.forEach(Destroyer::cleanUp));
    }
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();
    }
1240690
public function listCollections(array $options = [])
    {
        $collections = [];
        foreach ($this->collections as $name => $collection) {
            $collections[] = [
                'name' => $this->name . '.' . $name,
                'options' => $collection['options']
            ];
        }

        return new CollectionInfoLegacyIterator(new ArrayIterator($collections));
    }
895902
public function drop(array $options = [])
    {
        try {
            $cursor = $this->executeCommand(['drop' => $this->collectionName], $options);
        } catch (MongoDBRuntimeException $e) {
            if ('ns not found' === $e->getMessage()) {
                return ['ok' => 0, 'errmsg' => $e->getMessage()];
            }

            throw $e;
        }

        return $cursor->current();
    }
429993
public function setCollectionOptions(array $collectionOptions)
    {
        if ($this->nested) {
            throw new LogicException(
                sprintf(
                    'Collection options cannot be set for nested document class "%s".',
                    $this->documentClass
                )
            );
        }

        $this->collectionOptions = $collectionOptions;

        return $this;
    }
1151720
public function scheduleCollectionDeletion(PersistentCollectionInterface $coll) : void
    {
        $oid = spl_object_hash($coll);
        unset($this->collectionUpdates[$oid]);
        if (isset($this->collectionDeletions[$oid])) {
            return;
        }

        $this->collectionDeletions[$oid] = $coll;
        $this->scheduleCollectionOwner($coll);
    }
1097889
public function scheduleCollectionUpdate(PersistentCollectionInterface $coll) : void
    {
        $mapping = $coll->getMapping();
        if (CollectionHelper::usesSet($mapping['strategy'])) {
            /* There is no need to $unset collection if it will be $set later
             * This is NOP if collection is not scheduled for deletion
             */
            $this->unscheduleCollectionDeletion($coll);
        }
        $oid = spl_object_hash($coll);
        if (isset($this->collectionUpdates[$oid])) {
            return;
        }

        $this->collectionUpdates[$oid] = $coll;
        $this->scheduleCollectionOwner($coll);
    }
373713
public function setCollections($collections)
    {
        if (!is_array($collections) && !$collections instanceof Traversable) {
            throw new Exception\InvalidArgumentException(sprintf(
                '%s: expects an array or Traversable, received "%s"',
                __METHOD__,
                (is_object($collections) ? get_class($collections) : gettype($collections))
            ));
        }

        if ($collections instanceof Traversable) {
            $collections = ArrayUtils::iteratorToArray($collections);
        }

        $this->collections = $collections;
    }
682300
public function deleteMany($filter, $options = [])
    {
        $filter = $this->castQuery($filter);
        $result = $this->collection->deleteMany($filter, $options);

        if ($result->isAcknowledged()) {
            return true;
        } else {
            return false;
        }
    }
1165608
protected function evictCollectionCache(PersistentCollection $collection)
    {
        $key = new CollectionCacheKey(
            $this->sourceEntity->getRootClassName(),
            $this->association->getName(),
            $this->uow->getEntityIdentifier($collection->getOwner())
        );

        $this->region->evict($key);

        if ($this->cacheLogger) {
            $this->cacheLogger->collectionCachePut($this->regionName, $key);
        }
    }
1293340
public function deleteMany(array $filter, array $options = [])
    {
        $this->writeModels[] = [BulkWrite::DELETE_MANY => [$filter, $options]];

        return $this;
    }
1370093
protected function saveCollection(Collection $collection, array $options = []) {
		if ($collection->isInsertForced()) {
			unset($collection->_id);
			$collection->unforceInsert();
		}
		
		$result = true;
		
		foreach ($collection as $model) {
			if (! $this->saveModel($model, $options)) {
				$result = false;
			}
		}
		
		return $result;
	}
359664
public function collectionItem(array &$submitted, array $options = array())
    {
        $this->options = $options;
        $this->submitted = &$submitted;

        $this->validateCollectionItem();
        $this->validateBool('status');
        $this->validateWeight();
        $this->validateUrlCollectionItem();
        $this->validateCollectionCollectionItem();
        $this->validateEntityIdCollectionItem();
        $this->validateEntityCollectionItem();
        $this->validateData();

        $this->unsetSubmitted('update');
        $this->unsetSubmitted('collection');

        return $this->getResult();
    }
920680
public function deleteRegistrationsOnCollection(\collection $collection)
    {
        $qb = $this->repository->createQueryBuilder('d');
        $qb->delete('Phraseanet:Registration', 'd');
        $qb->where($qb->expr()->eq('d.baseId', ':base'));
        $qb->setParameter(':base', $collection->get_base_id());
        $qb->getQuery()->execute();
    }
576333
private function forgetCollection(Collection $collection)
    {
        $query_builder = $this->manager->createQueryBuilder();
        $query_builder
            ->delete(StackUsageRecord::class, 'r')
            ->where('r.collection_id = :collection_id')
            ->setParameter('collection_id', $collection->getCollectionID())
            ->getQuery()->execute();
    }
616027
public static final <T> void remove(Collection<T> collection, T... items)
    {
        for (T t : items)
        {
            collection.remove(t);
        }
    }