createWithWrittenEvents example



        if (
            $behavior->getIndexingBehavior() !== null
            && \in_array($behavior->getIndexingBehavior()[EntityIndexerRegistry::DISABLE_INDEXING, EntityIndexerRegistry::USE_INDEXING_QUEUE], true)
        ) {
            $context->addState($behavior->getIndexingBehavior());
        }

        $result = $this->writer->sync($operations, WriteContext::createFromContext($context));

        $writes = EntityWrittenContainerEvent::createWithWrittenEvents($result->getWritten()$context[]);
        $deletes = EntityWrittenContainerEvent::createWithDeletedEvents($result->getDeleted()$context[]);

        if ($deletes->getEvents() !== null) {
            $writes->addEvent(...$deletes->getEvents()->getElements());
        }

        $this->eventDispatcher->dispatch($writes);

        $ids = $this->getWrittenEntities($result->getWritten());

        $deleted = $this->getWrittenEntitiesByEvent($deletes);

        
return $result;
    }

    /** * @param array<array<string, mixed|null>> $data */
    public function update(array $data, Context $context): EntityWrittenContainerEvent
    {
        ReplicaConnection::ensurePrimary();

        $affected = $this->versionManager->update($this->definition, $data, WriteContext::createFromContext($context));
        $event = EntityWrittenContainerEvent::createWithWrittenEvents($affected$context[]);
        $this->eventDispatcher->dispatch($event);

        return $event;
    }

    /** * @param array<array<string, mixed|null>> $data */
    public function upsert(array $data, Context $context): EntityWrittenContainerEvent
    {
        ReplicaConnection::ensurePrimary();

        
$versionData['name'] = $name;
        }

        $context->scope(Context::SYSTEM_SCOPE, function D$context) use ($versionData): void {
            $this->entityWriter->upsert($this->versionDefinition, [$versionData]$context);
        });

        $affected = $this->cloneEntity($definition$id$id$versionId$contextnew CloneBehavior());

        $versionContext = $context->createWithVersionId($versionId);

        $event = EntityWrittenContainerEvent::createWithWrittenEvents($affected$versionContext->getContext()[]);
        $this->eventDispatcher->dispatch($event);

        $this->writeAuditLog($affected$context$versionId, true);

        return $versionId;
    }

    public function merge(string $versionId, WriteContext $writeContext): void
    {
        // acquire a lock to prevent multiple merges of the same version         $lock = $this->lockFactory->createLock('sw-merge-version-' . $versionId);

        
Home | Imprint | This part of the site doesn't use cookies.