ChangeSet example

$idA = Uuid::randomHex();
        $idB = Uuid::randomBytes();
        $idC = Uuid::randomBytes();
        $idD = Uuid::randomBytes();

        $event = new EntityWrittenContainerEvent($contextnew NestedEventCollection([
            new EntityWrittenEvent('many_to_one', [
                new EntityWriteResult($idA[], 'many_to_one', EntityWriteResult::OPERATION_INSERT),
            ]$context[]),
            new EntityWrittenEvent('one_to_many', [
                new EntityWriteResult($idA['ruleId' => $idA], 'one_to_many', EntityWriteResult::OPERATION_INSERT),
                new EntityWriteResult($idA[], 'one_to_many', EntityWriteResult::OPERATION_UPDATE, null, new ChangeSet(
                    ['rule_id' => $idB],
                    ['rule_id' => $idC],
                    false
                )),
                new EntityWriteResult($idA[], 'one_to_many', EntityWriteResult::OPERATION_DELETE, null, new ChangeSet(
                    ['rule_id' => $idD],
                    ['rule_id' => null],
                    true
                )),
            ]$context[]),
        ])[]);

        
/** * @param list<array<string, mixed>> $states */
    private function calculateChangeSet(WriteCommand $command, array $states): ChangeSet
    {
        foreach ($states as $state) {
            // check if current loop matches the command primary key             $primaryKey = array_intersect($command->getPrimaryKey()$state);

            if (\count(array_diff_assoc($command->getPrimaryKey()$primaryKey)) === 0) {
                return new ChangeSet($state$command->getPayload()$command instanceof DeleteCommand);
            }
        }

        return new ChangeSet([][]$command instanceof DeleteCommand);
    }

    private function getPlaceholders(int $columnCount, int $tupleCount): string
    {
        if ($columnCount > 1) {
            // multi column pk. Example: (product_id, language_id) IN ((p1, l1), (p2, l2), (px,lx),...)             $tupleStr = '(?' . str_repeat(',?', $columnCount - 1) . ')';
        }
public function testOnReviewDeleted(): void
    {
        $event = new EntityDeletedEvent(
            ProductReviewDefinition::ENTITY_NAME,
            [
                new EntityWriteResult(
                    'id',
                    ['id' => 'id'],
                    ProductReviewDefinition::ENTITY_NAME,
                    EntityWriteResult::OPERATION_DELETE,
                    new EntityExistence(ProductReviewDefinition::ENTITY_NAME, ['id' => 'id'], true, false, false, []),
                    new ChangeSet(['customer_id' => 'customer_id'][], true)
                ),
                // should not trigger update as it has empty changeset                 new EntityWriteResult(
                    'id',
                    ['id' => 'id'],
                    ProductReviewDefinition::ENTITY_NAME,
                    EntityWriteResult::OPERATION_DELETE,
                    new EntityExistence(ProductReviewDefinition::ENTITY_NAME, ['id' => 'id'], true, false, false, []),
                    new ChangeSet([][], true)
                ),
                // should not trigger update as it has wrong entity
Home | Imprint | This part of the site doesn't use cookies.