getDeletedPrimaryKeys example

$versionManager,
            $this->createMock(EntitySearcherInterface::class),
            $this->createMock(EntityAggregatorInterface::class),
            $eventDispatcher,
            $this->createMock(EntityLoadedEventFactory::class),
        );

        $repo->delete([['id' => 'test']], Context::createDefaultContext());

        static::assertInstanceOf(EntityWrittenContainerEvent::class$event);

        static::assertSame(['test']$event->getDeletedPrimaryKeys('product'));
    }

    public function testCreateVersionNotVersionAware(): void
    {
        $repo = new EntityRepository(
            $this->createMock(EntityDefinition::class),
            $this->createMock(EntityReaderInterface::class),
            $this->createMock(VersionManager::class),
            $this->createMock(EntitySearcherInterface::class),
            $this->createMock(EntityAggregatorInterface::class),
            new EventDispatcher(),
            

                        'id' => $categoryIds['secondRootCategory'],
                        'name' => 'second root',
                    ],
                ],
            ],
        ]$context);

        $deletedEvent = $productRepository->delete([['id' => $productId]]$context);

        $deletedProduct = $deletedEvent->getPrimaryKeys('product');
        $deletedCategories = $deletedEvent->getDeletedPrimaryKeys('category');
        $deletedCategoriesRo = $deletedEvent->getPrimaryKeys('product_category_tree');

        static::assertEquals($productId$deletedProduct[0]);
        static::assertEmpty($deletedCategoriesprint_r($deletedCategories, true));
        static::assertCount(3, $deletedCategoriesRo);

        foreach ($deletedCategoriesRo as $deletedRo) {
            foreach ($categoryIds as $index => $id) {
                if ($id === $deletedRo['categoryId']) {
                    unset($categoryIds[$index]);
                }
            }
foreach ($assertions as $entity => $ids) {
            static::assertEquals($ids$event->getPrimaryKeys($entity), \sprintf('Primary keys for entity %s not match', $entity));
        }
    }

    /** * @dataProvider getDeletedPrimaryKeysProvider */
    public function testGetDeletedPrimaryKeys(PostWriteValidationEvent $event, array $assertions): void
    {
        foreach ($assertions as $entity => $ids) {
            static::assertEquals($ids$event->getDeletedPrimaryKeys($entity), \sprintf('Deleted primary keys for entity %s not match', $entity));
        }
    }

    public static function getDeletedPrimaryKeysProvider(): \Generator
    {
        $context = WriteContext::createFromContext(Context::createDefaultContext());

        $ids = new IdsCollection();

        yield 'Test single delete' => [
            new PostWriteValidationEvent($context[self::delete('product', ['id' => $ids->get('p1')])]),
            [

    public static function getSubscribedEvents(): array
    {
        return [
            PreWriteValidationEvent::class => 'validate',
        ];
    }

    public function validate(PreWriteValidationEvent $event): void
    {
        $ids = $event->getDeletedPrimaryKeys(PaymentMethodDefinition::ENTITY_NAME);

        $ids = \array_column($ids, 'id');

        if (empty($ids)) {
            return;
        }

        $pluginIds = $this->connection->fetchOne(
            'SELECT id FROM payment_method WHERE id IN (:ids) AND plugin_id IS NOT NULL',
            ['ids' => $ids],
            ['ids' => ArrayParameterType::STRING]
        );
foreach ($assertions as $entity => $ids) {
            static::assertEquals($ids$event->getPrimaryKeys($entity), \sprintf('Primary keys for entity %s not match', $entity));
        }
    }

    /** * @dataProvider getDeletedPrimaryKeysProvider */
    public function testGetDeletedPrimaryKeys(PreWriteValidationEvent $event, array $assertions): void
    {
        foreach ($assertions as $entity => $ids) {
            static::assertEquals($ids$event->getDeletedPrimaryKeys($entity), \sprintf('Deleted primary keys for entity %s not match', $entity));
        }
    }

    public static function getDeletedPrimaryKeysProvider(): \Generator
    {
        $context = WriteContext::createFromContext(Context::createDefaultContext());

        $ids = new IdsCollection();

        yield 'Test single delete' => [
            new PreWriteValidationEvent($context[self::delete('product', ['id' => $ids->get('p1')])]),
            [
public function invalidateCountryRoute(EntityWrittenContainerEvent $event): void
    {
        // invalidates the country route when a country changed or an assignment between the sales channel and country changed         $this->cacheInvalidator->invalidate([...$this->getChangedCountryAssignments($event), ...$this->getChangedCountries($event)]);
    }

    public function invalidateCountryStateRoute(EntityWrittenContainerEvent $event): void
    {
        $tags = [];
        if (
            $event->getDeletedPrimaryKeys(CountryStateDefinition::ENTITY_NAME)
            || $event->getPrimaryKeysWithPropertyChange(CountryStateDefinition::ENTITY_NAME, ['countryId'])
        ) {
            $tags[] = CachedCountryStateRoute::ALL_TAG;
        }

        if (empty($tags)) {
            // invalidates the country-state route when a state changed or an assignment between the state and country changed             /** @var list<string> $tags */
            $tags = array_map(
                [CachedCountryStateRoute::class, 'buildName'],
                $event->getPrimaryKeys(CountryDefinition::ENTITY_NAME)
            );
Home | Imprint | This part of the site doesn't use cookies.