getRandomFile example

$context->getConsole()->progressStart($numberOfItems);
        $this->faker = $context->getFaker();

        $writeContext = WriteContext::createFromContext($context->getContext());

        $mediaFolderId = $this->getOrCreateDefaultFolder($context);
        $downloadFolderId = $this->getOrCreateDefaultFolder($context, true);
        $tags = $this->getIds('tag');

        for ($i = 0; $i < $numberOfItems; ++$i) {
            $isDownloadFile = $i % 30 === 0;
            $file = $this->getRandomFile($context);

            $mediaId = Uuid::randomHex();
            $this->writer->insert(
                $this->mediaDefinition,
                [
                    [
                        'id' => $mediaId,
                        'title' => "File #{$i}: {$file}",
                        'mediaFolderId' => $isDownloadFile ? $downloadFolderId : $mediaFolderId,
                        'private' => $isDownloadFile,
                        'tags' => $this->getTags($tags),
                    ],
Home | Imprint | This part of the site doesn't use cookies.