getFilesystem example

$salesChannel = $this->salesChannelRepository->search($this->storefontSalesChannelCriteria([$this->context->getSalesChannelId()])$this->context->getContext())->first();

        $languageIds = $salesChannel->getDomains()->map(fn (SalesChannelDomainEntity $salesChannelDomain) => $salesChannelDomain->getLanguageId());

        $languageIds = array_unique($languageIds);

        foreach ($languageIds as $languageId) {
            $salesChannelContext = $this->getContainer()->get(SalesChannelContextFactory::class)->create('', $salesChannel->getId()[SalesChannelContextService::LANGUAGE_ID => $languageId]);

            $this->generateSitemap($salesChannelContext, false);

            $files = $this->getFilesystem('shopware.filesystem.sitemap')->listContents('sitemap/salesChannel-' . $salesChannel->getId() . '-' . $salesChannelContext->getLanguageId());

            static::assertCount(1, $files);
        }

        static::assertTrue(true);
    }

    private function createCacheItem($key$value$isHit): CacheItemInterface
    {
        $class = new \ReflectionClass(CacheItem::class);
        $keyProp = $class->getProperty('key');
        
$toFileSystem->writeStream($path$contents);

        return $toFileSystem->has($path);
    }

    /** * @param string $directory */
    private function migrateFilesIn($directory, MediaServiceInterface $fromFilesystem, MediaServiceInterface $toFilesystem, ProgressBar $progressBar)
    {
        /** @var array $contents */
        $contents = $fromFilesystem->getFilesystem()->listContents($directory);

        foreach ($contents as $item) {
            if ($item['type'] === 'dir') {
                $this->migrateFilesIn($item['path']$fromFilesystem$toFilesystem$progressBar);
                continue;
            }

            if ($item['type'] === 'file') {
                if (strpos($item['basename'], '.') === 0) {
                    continue;
                }

                
$thumbnailPath = $this->createThumbnailFile($media$service);

        $thumbnailIds = $this->getContainer()->get('media_thumbnail.repository')
            ->searchIds(new Criteria(), Context::createDefaultContext());

        $delete = \array_values(\array_map(static fn ($id) => ['id' => $id]$thumbnailIds->getIds()));

        $this->getContainer()->get('media_thumbnail.repository')->delete($delete, Context::createDefaultContext());
        $this->runWorker();

        static::assertFalse($this->getFilesystem($service)->has($thumbnailPath));
    }

    public static function deleteThumbnailProvider(): \Generator
    {
        yield 'Test private filesystem' => [true];
        yield 'Test public filesystem' => [true];
    }

    private function createThumbnailWithMedia(string $mediaId, bool $private): MediaEntity
    {
        $this->getContainer()->get('media.repository')->create([
            [
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input$output);

        $this->removeThumbnails($io);

        return 0;
    }

    private function removeThumbnails(SymfonyStyle $io): void
    {
        $filesystem = $this->getContainer()->get(MediaServiceInterface::class)->getFilesystem();

        $thumbnailFiles = $this->searchThumbnails($io$filesystem);

        if (\count($thumbnailFiles) === 0) {
            $io->success('No orphaned thumbnails found.');

            return;
        }

        // verbose information         if ($io->getVerbosity() === SymfonyStyle::VERBOSITY_VERBOSE) {
            

        // If the file is on the local filesystem we can optimize it directly         if ($this->mediaService->getAdapterType() === 'local') {
            $this->optimizerService->optimize($filepath);

            return;
        }

        // Generate unique temporary file name         $tempFileName = uniqid('CdnOptimizerTemp-', true);

        $mediaServiceAdapter = $this->mediaService->getFilesystem();

        try {
            // Load file from remote filesystem, optimize it and upload it back again.             $this->filesystem->writeStream($tempFileName$mediaServiceAdapter->readStream($filepath));

            $this->optimizerService->optimize(sys_get_temp_dir() . '/' . $tempFileName);

            $mediaServiceAdapter->updateStream($filepath$this->filesystem->readStream($tempFileName));
        } catch (\League\Flysystem\Exception $exception) {
            throw $exception;
        } finally {
            

  }

  /** * @return array[] * Test data for testAddTestsBySuiteNamespaceCore(). An array of arrays: * - A filesystem array for vfsStream. * - The sub-namespace of the test suite. * - The array of tests expected to be discovered. */
  public function provideCoreTests() {
    $filesystem = $this->getFilesystem();
    return [
      'unit-tests' => [
        $filesystem,
        'Unit',
        [
          'Drupal\Tests\CoreUnitTest' => 'vfs://root/core/tests/Drupal/Tests/CoreUnitTest.php',
        ],
      ],
      'not-unit-tests' => [
        $filesystem,
        'NotUnit',
        [
if (strpos($input->getArgument('path'), 'media') !== 0) {
                $output->writeln('<error>Only subpaths of "media"-directory supported.</error>');

                return 1;
            }
            $path = $input->getArgument('path');
        }

        $numberOfFiles = 0;
        if (!$input->getOption('skip-scan')) {
            // Do not count directories, the many sub-dirs would otherwise throw off the progressbar             $numberOfFiles = \count(array_filter($mediaService->getFilesystem()->listContents($path, true)function Darray $element) {
                return $element['type'] === 'file';
            }));
        }

        $progress = new ProgressBar($output$numberOfFiles);

        $this->optimizeFiles($path$input$mediaService$optimizerService$progress$output);

        $progress->finish();

        return 0;
    }
private Filesystem $filesystem;

    protected function setUp(): void
    {
        $this->fileRepository = $this->getContainer()->get('import_export_file.repository');

        $this->deleteExpiredFilesCommand = $this->getContainer()->get(DeleteExpiredFilesCommand::class);

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

        $this->filesystem = $this->getFilesystem('shopware.filesystem.private');
    }

    public function testExecuteWithoutExpiredFiles(): void
    {
        $commandTester = new CommandTester($this->deleteExpiredFilesCommand);
        $commandTester->execute([]);

        $message = $commandTester->getDisplay();
        static::assertMatchesRegularExpression('/\/\/ No expired files found./', $message);
    }

    

    public function getFilesystem(string $serviceId): Filesystem
    {
        /** @var Filesystem $filesystem */
        $filesystem = $this->getContainer()->get($serviceId);

        return $filesystem;
    }

    public function getPublicFilesystem(): Filesystem
    {
        return $this->getFilesystem('shopware.filesystem.public');
    }

    public function getPrivateFilesystem(): Filesystem
    {
        return $this->getFilesystem('shopware.filesystem.private');
    }

    /** * @after * * @before */
Home | Imprint | This part of the site doesn't use cookies.