setMediaIds example

/** * @param RepositoryIterator<MediaCollection> $mediaIterator */
    private function generateAsynchronous(RepositoryIterator $mediaIterator, Context $context): void
    {
        $batchCount = 0;
        $this->io->comment('Generating batch jobs...');
        while (($result = $mediaIterator->fetch()) !== null) {
            $msg = new UpdateThumbnailsMessage();
            $msg->setIsStrict($this->isStrict);
            $msg->setMediaIds($result->getEntities()->getIds());

            if (Feature::isActive('v6.6.0.0')) {
                $msg->setContext($context);
            } else {
                $msg->withContext($context);
            }

            $this->messageBus->dispatch($msg);
            ++$batchCount;
        }
        $this->io->success(sprintf('Generated %d Batch jobs!', $batchCount));
    }
$blogs = [];
        foreach ($data as $row) {
            $id = (int) $row['__blog_id'];

            $blog = $this->blogHydrator->hydrate($row);

            if (\array_key_exists($id$articles)) {
                $blog->setProductNumbers($articles[$id]);
            }

            if (\array_key_exists($id$medias)) {
                $blog->setMediaIds($medias[$id]);
            }

            $blogs[$id] = $blog;
        }

        return $blogs;
    }

    /** * @param int[] $ids */
    
$affectedMediaIds = [...array_combine($this->initialMediaIds, $this->initialMediaIds), ...$newMedia->getIds()];

        $expectedMessageStrict = new UpdateThumbnailsMessage();

        if (Feature::isActive('v6.6.0.0')) {
            $expectedMessageStrict->setContext($this->context);
        } else {
            $expectedMessageStrict->withContext($this->context);
        }

        $expectedMessageStrict->setIsStrict(true);
        $expectedMessageStrict->setMediaIds($affectedMediaIds);

        $expectedMessageNonStrict = new UpdateThumbnailsMessage();

        if (Feature::isActive('v6.6.0.0')) {
            $expectedMessageNonStrict->setContext($this->context);
        } else {
            $expectedMessageNonStrict->withContext($this->context);
        }

        $expectedMessageNonStrict->setIsStrict(false);
        $expectedMessageNonStrict->setMediaIds($affectedMediaIds);

        
$mediaFile,
            $destination,
            $currentMedia,
            $metaData,
            $mediaType,
            $context
        );

        $this->saveFileToMediaDir($mediaFile$media);

        $message = new GenerateThumbnailsMessage();
        $message->setMediaIds([$mediaId]);

        if (Feature::isActive('v6.6.0.0')) {
            $message->setContext($context);
        } else {
            $message->withContext($context);
        }

        $this->messageBus->dispatch($message);
    }

    public function renameMedia(string $mediaId, string $destination, Context $context): void
    {
$this->mediaRepository->method('search')->willReturn($mediaSearchResult);

        $file = tmpfile();
        static::assertIsResource($file);
        $tempMeta = stream_get_meta_data($file);
        $mediaFile = new MediaFile($tempMeta['uri'], 'image/png', 'png', 0);

        $context = Context::createDefaultContext(new AdminApiSource(Uuid::randomHex()));
        $mediaId = Uuid::randomHex();

        $message = new GenerateThumbnailsMessage();
        $message->setMediaIds([$mediaId]);

        if (Feature::isActive('v6.6.0.0')) {
            $message->setContext($context);
        } else {
            $message->withContext($context);
        }

        $this->mediaRepository
            ->expects(static::once())
            ->method('update')
            ->with(static::callback(static fn (array $payload) => $payload[0]['id'] === $currentMedia->getId() && $payload[0]['fileName'] === 'foo'));

        
 $this->context);

        /** @var MediaEntity $media */
        $media = $this->mediaRepository->search(new Criteria([$media->getId()])$this->context)->get($media->getId());

        $this->getPublicFilesystem()->writeStream(
            $this->urlGenerator->getRelativeMediaUrl($media),
            fopen(__DIR__ . '/../fixtures/shopware-logo.png', 'rb')
        );

        $msg = new GenerateThumbnailsMessage();
        $msg->setMediaIds([$media->getId()]);

        if (Feature::isActive('v6.6.0.0')) {
            $msg->setContext($this->context);
        } else {
            $msg->withContext($this->context);
        }

        $this->handler->__invoke($msg);

        $criteria = new Criteria([$media->getId()]);
        $criteria->addAssociation('thumbnails');

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