getDeleted example

return $event;
    }

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

        $affected = $this->versionManager->delete($this->definition, $ids, WriteContext::createFromContext($context));
        $event = EntityWrittenContainerEvent::createWithDeletedEvents($affected->getDeleted()$context$affected->getNotFound());

        if ($affected->getWritten()) {
            $updates = EntityWrittenContainerEvent::createWithWrittenEvents($affected->getWritten()$context[]);

            if ($updates->getEvents() !== null) {
                $event->addEvent(...$updates->getEvents());
            }
        }

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

        
return $result;
    }

    /** * @param array<array<string, mixed|null>> $ids */
    public function delete(EntityDefinition $definition, array $ids, WriteContext $writeContext): WriteResult
    {
        $result = $this->entityWriter->delete($definition$ids$writeContext);

        $this->writeAuditLog($result->getDeleted()$writeContext);

        return $result;
    }

    public function createVersion(EntityDefinition $definition, string $id, WriteContext $context, ?string $name = null, ?string $versionId = null): string
    {
        $versionId = $versionId ?? Uuid::randomHex();
        $versionData = ['id' => $versionId];

        if ($name) {
            $versionData['name'] = $name;
        }
$children = $this->connection->fetchAllAssociative('SELECT * FROM set_null_on_delete_child');
        static::assertCount(1, $children);

        $result = $this->writer->delete(
            $this->getContainer()->get(SetNullOnDeleteParentDefinition::class),
            [
                ['id' => $ids->get('parent')],
            ],
            WriteContext::createFromContext(Context::createDefaultContext())
        );

        $deleted = $result->getDeleted();
        static::assertCount(1, $deleted);
        static::assertArrayHasKey(SetNullOnDeleteParentDefinition::ENTITY_NAME, $deleted);

        static::assertCount(1, $deleted[SetNullOnDeleteParentDefinition::ENTITY_NAME]);
        static::assertEquals($ids->get('parent')$deleted[SetNullOnDeleteParentDefinition::ENTITY_NAME][0]->getPrimaryKey());

        $updated = $result->getWritten();
        static::assertCount(1, $updated);
        static::assertArrayHasKey(SetNullOnDeleteChildDefinition::ENTITY_NAME, $updated);

        static::assertCount(1, $updated[SetNullOnDeleteChildDefinition::ENTITY_NAME]);
        
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);

        
$deleteResult = $this->getWriter()->delete(
            $this->getContainer()->get(CategoryDefinition::class),
            [
                ['id' => $id],
            ],
            $context
        );

        $exists = $this->connection->fetchAllAssociative('SELECT * FROM category WHERE id = :id', ['id' => Uuid::fromHexToBytes($id)]);
        static::assertEmpty($exists);
        static::assertEmpty($deleteResult->getNotFound());
        static::assertNotEmpty($deleteResult->getDeleted());
    }

    public function testMultiDelete(): void
    {
        $id = Uuid::randomHex();
        $id2 = Uuid::randomHex();

        $context = $this->createWriteContext();

        $this->getWriter()->insert(
            $this->getContainer()->get(CategoryDefinition::class),
            [
'id' => '1'],
            ['id' => '2'],
        ]);

        $behavior = new SyncBehavior('disable-indexing', ['product.indexer']);
        $result = $service->sync([$upsert$delete], Context::createDefaultContext()$behavior);

        static::assertSame([
            'product' => [
                'deleted-id',
            ],
        ]$result->getDeleted());

        static::assertSame([
            'product' => [
                'created-id',
            ],
        ]$result->getData());

        static::assertSame([]$result->getNotFound());
    }

    public function testWildcardDeleteForMappingEntities(): void
    {
Home | Imprint | This part of the site doesn't use cookies.