runWorker example

$mediaPath = $this->getContainer()->get(UrlGeneratorInterface::class)->getRelativeMediaUrl($media);

        $file = fopen(self::FIXTURE_FILE, 'rb');
        static::assertIsResource($file);
        $this->getPublicFilesystem()->writeStream($mediaPath$file);

        $this->folderRepository->delete([['id' => $folderId]]$this->context);

        static::assertEquals(0, $this->folderRepository->search(new Criteria([$folderId])$this->context)->getTotal());
        static::assertEquals(0, $this->mediaRepository->search(new Criteria([$mediaId])$this->context)->getTotal());

        $this->runWorker();

        static::assertFalse($this->getPublicFilesystem()->has($mediaPath));
    }

    public function testDeleteFolderAlsoDeletesSubFoldersWithMedia(): void
    {
        $childFolderId = Uuid::randomHex();
        $parentFolderId = Uuid::randomHex();
        $childMediaId = Uuid::randomHex();
        $parentMediaId = Uuid::randomHex();

        


    /** * @param array<string, mixed> $input */
    public function indexElasticSearch(array $input = []): void
    {
        $this->getDiContainer()
            ->get(ElasticsearchAdminIndexingCommand::class)
            ->run(new ArrayInput([...$input, '--no-queue' => true])new NullOutput());

        $this->runWorker();

        $this->refreshIndex();
    }

    public function refreshIndex(): void
    {
        $this->getDiContainer()->get(Client::class)
            ->indices()
            ->refresh(['index' => '_all']);
    }

    
$resource = fopen(__DIR__ . '/../fixtures/shopware-logo.png', 'rb');

        \assert($resource !== false);
        $this->getPublicFilesystem()->writeStream($filePath$resource);

        $this->thumbnailService->updateThumbnails(
            $media,
            $this->context,
            false
        );

        $this->runWorker();

        $searchCriteria = new Criteria();
        $searchCriteria->setLimit(1);
        $searchCriteria->addFilter(new EqualsFilter('media.id', $media->getId()));
        $searchCriteria->addAssociation('mediaFolder.configuration.mediaThumbnailSizes');

        $mediaResult = $this->mediaRepository->search($searchCriteria$this->context);

        /** @var MediaEntity $updatedMedia */
        $updatedMedia = $mediaResult->getEntities()->first();

        
$this->getDiContainer()
            ->get(ElasticsearchHelper::class)
            ->setEnabled(false);
    }

    public function indexElasticSearch(): void
    {
        $this->getDiContainer()
            ->get(ElasticsearchIndexingCommand::class)
            ->run(new ArrayInput([])new NullOutput());

        $this->runWorker();

        $this->refreshIndex();
    }

    public function refreshIndex(): void
    {
        $this->getDiContainer()->get(Client::class)
            ->indices()
            ->refresh(['index' => '_all']);
    }

    
use QueueTestBehaviour;

    public function testIndexingHappensAfterPluginLifecycle(): void
    {
        $connection = $this->getContainer()->get(Connection::class);

        $connection->executeStatement('UPDATE `flow` SET `payload` = null, `invalid` = 0');

        $indexer = $this->getContainer()->get(FlowIndexerSubscriber::class);
        $indexer->refreshPlugin();

        $this->runWorker();

        static::assertGreaterThan(1, (int) $connection->fetchOne('SELECT COUNT(*) FROM flow WHERE payload IS NOT NULL'));
    }
}
$commandTester = new CommandTester($this->deleteExpiredFilesCommand);
        $commandTester->setInputs(['y']);
        $commandTester->execute([]);

        $message = $commandTester->getDisplay();
        static::assertMatchesRegularExpression(
            sprintf('/Are you sure that you want to delete %d expired files\? \(yes\/no\) \[no\]:/', $num),
            $message
        );
        static::assertMatchesRegularExpression(sprintf('/\[OK\] Successfully deleted %d expired files./', $num)$message);

        $this->runWorker();

        // Check files are deleted in FS.         foreach ($filePathes as $filePath) {
            static::assertFalse($this->filesystem->has($filePath));
        }
    }

    public function testExecuteWithSomeFilesExpired(): void
    {
        $num = 25;
        $data = $this->prepareImportExportFileTestData($num);
        
$firstPath = $urlGenerator->getRelativeMediaUrl($txt);
        $secondPath = $urlGenerator->getRelativeMediaUrl($png);
        $thirdPath = $urlGenerator->getRelativeMediaUrl($withProduct);
        $fourthPath = $urlGenerator->getRelativeMediaUrl($withManufacturer);

        $this->getPublicFilesystem()->writeStream($firstPathfopen(self::FIXTURE_FILE, 'rb'));
        $this->getPublicFilesystem()->writeStream($secondPathfopen(self::FIXTURE_FILE, 'rb'));
        $this->getPublicFilesystem()->writeStream($thirdPathfopen(self::FIXTURE_FILE, 'rb'));
        $this->getPublicFilesystem()->writeStream($fourthPathfopen(self::FIXTURE_FILE, 'rb'));

        $this->deleteMediaService->deleteNotUsedMedia($this->context);
        $this->runWorker();

        $result = $this->mediaRepo->search(
            new Criteria([
                $txt->getId(),
                $png->getId(),
                $withProduct->getId(),
                $withManufacturer->getId(),
            ]),
            $this->context
        );

        
$bus = $this->getContainer()->get('messenger.bus.test_shopware');

        $bus->dispatch(new FooMessage());
        $bus->dispatch(new BarMessage());
        $bus->dispatch(new BarMessage());
        $bus->dispatch(new BarMessage());

        $stats = $pool->list('message_queue_stats');
        static::assertEquals(1, $stats[FooMessage::class]['count']);
        static::assertEquals(3, $stats[BarMessage::class]['count']);

        $this->runWorker();

        $stats = $pool->list('message_queue_stats');
        static::assertEquals(0, $stats[FooMessage::class]['count']);
        static::assertEquals(0, $stats[BarMessage::class]['count']);

        $bus->dispatch(new NoHandlerMessage());

        $stats = $pool->list('message_queue_stats');
        static::assertEquals(1, $stats[NoHandlerMessage::class]['count']);

        $this->runWorker();
        

                'id' => $child2Id,
                'parentId' => $parentId,
                'productNumber' => 'C2',
                'stock' => 0,
            ],
        ];

        $context = Context::createDefaultContext();
        $this->productRepository->upsert($products$context);

        $this->runWorker();

        // update parent         $update = [
            'id' => $parentId,
            'name' => 'updated',
        ];

        $this->productRepository->update([$update], Context::createDefaultContext());
        $this->runWorker();

        $this->runWorker();

        
'id' => $childAId,
                    'name' => 'a',
                    'children' => [
                        [
                            'id' => $childA1Id,
                            'name' => '1',
                        ],
                    ],
                ],
            ],
        ]], Context::createDefaultContext());
        $this->runWorker();

        $context = $salesChannelContext->getContext();

        $cases = [
            ['expected' => null, 'categoryId' => $childAId],
            ['expected' => null, 'categoryId' => $childA1Id],
        ];

        $this->runChecks($cases$categoryRepository$context$salesChannelId);
    }

    
$firstPath = $urlGenerator->getRelativeMediaUrl($txt);
        $secondPath = $urlGenerator->getRelativeMediaUrl($png);
        $thirdPath = $urlGenerator->getRelativeMediaUrl($withProduct);
        $fourthPath = $urlGenerator->getRelativeMediaUrl($withManufacturer);

        $this->getPublicFilesystem()->writeStream($firstPath, \fopen(self::FIXTURE_FILE, 'rb'));
        $this->getPublicFilesystem()->writeStream($secondPath, \fopen(self::FIXTURE_FILE, 'rb'));
        $this->getPublicFilesystem()->writeStream($thirdPath, \fopen(self::FIXTURE_FILE, 'rb'));
        $this->getPublicFilesystem()->writeStream($fourthPath, \fopen(self::FIXTURE_FILE, 'rb'));

        $this->unusedMediaPurger->deleteNotUsedMedia();
        $this->runWorker();

        $result = $this->mediaRepo->search(
            new Criteria([
                $txt->getId(),
                $png->getId(),
                $withProduct->getId(),
                $withManufacturer->getId(),
            ]),
            $this->context
        );

        


                // break the loop if all messages are consumed                 if (0 === \count($envelopes)) {
                    break;
                }

                $this->retrySpecificEnvelopes($envelopes$failureTransportName$io$shouldForce);
            }
        } else {
            // get() and ask messages one-by-one             $count = $this->runWorker($failureTransportName$receiver$io$shouldForce);
        }

        // avoid success message if nothing was processed         if (1 <= $count) {
            $io->success('All failed messages have been handled or removed!');
        }
    }

    private function runWorker(string $failureTransportName, ReceiverInterface $receiver, SymfonyStyle $io, bool $shouldForce): int
    {
        $count = 0;
        
static::assertInstanceOf(MediaEntity::class$media);

        $mediaPath = $this->getContainer()->get(UrlGeneratorInterface::class)->getRelativeMediaUrl($media);

        $resource = fopen(self::FIXTURE_FILE, 'rb');
        static::assertNotFalse($resource);

        $this->getPublicFilesystem()->writeStream($mediaPath$resource);

        $this->mediaRepository->delete([['id' => $mediaId]]$this->context);

        $this->runWorker();

        static::assertFalse($this->getPublicFilesystem()->has($mediaPath));
    }

    public function testDeleteMediaEntityWithThumbnails(): void
    {
        $mediaId = Uuid::randomHex();

        $this->mediaRepository->create(
            [
                [
                    
'parentId' => $this->productId,
                'options' => [
                    ['id' => $this->optionIds['green']],
                    ['id' => $this->optionIds['l']],
                    ['id' => $this->optionIds['steel']],
                ],
            ],
        ];

        $this->repository->create($data, Context::createDefaultContext());

        $this->runWorker();
    }

    private function fetchListing(): Listing
    {
        $listing = $this->connection->fetchAllAssociative(
            'SELECT LOWER(HEX(id)) as id, option_ids FROM product WHERE product.parent_id = :parentId AND display_group IS NOT NULL GROUP BY display_group',
            ['parentId' => Uuid::fromHexToBytes($this->productId)]
        );
$categories = [
            ['id' => $ids->create('root'), 'name' => 'root', 'active' => true],
            ['id' => $ids->create('a'), 'name' => 'a', 'parentId' => $ids->get('root'), 'active' => true],
            ['id' => $ids->create('b'), 'name' => 'b', 'parentId' => $ids->get('a'), 'active' => true],
        ];

        $this->categoryRepository->create($categories, Context::createDefaultContext());

        $this->createSalesChannel($ids->create('sales-channel')$ids->get('root'));

        // sales channel navigation id switch detected, seo urls are generated by message queue         $this->runWorker();

        $urls = $this->getSeoUrls($ids->getList(['root', 'a', 'b'])$ids->get('sales-channel'));

        static::assertCount(2, $urls);
        static::assertArrayHasKey('a/', $urls);
        static::assertArrayHasKey('a/b/', $urls);

        $this->salesChannelRepository->update([
            ['id' => $ids->get('sales-channel'), 'navigationCategoryId' => $ids->get('a')],
        ], Context::createDefaultContext());

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