ensureDocumentMediaFileGenerated example

/** @var DocumentEntity|null $document */
        $document = $this->documentRepository->search($criteria$context)->get($documentId);

        if (!$document instanceof DocumentEntity) {
            if (Feature::isActive('v6.6.0.0')) {
                throw DocumentException::documentNotFound($documentId);
            }

            throw new InvalidDocumentException($documentId);
        }

        $document = $this->ensureDocumentMediaFileGenerated($document$context);
        $documentMediaId = $document->getDocumentMediaFileId();

        if ($documentMediaId === null) {
            return null;
        }

        /** @var MediaEntity $documentMedia */
        $documentMedia = $document->getDocumentMediaFile();

        $fileBlob = $context->scope(Context::SYSTEM_SCOPE, fn (Context $context): string => $this->mediaService->loadFile($documentMediaId$context));

        
if ($documents->count() === 0) {
            return null;
        }

        $fileName = Random::getAlphanumericString(32) . '.' . PdfRenderer::FILE_EXTENSION;

        if ($documents->count() === 1) {
            /** @var DocumentEntity $document */
            $document = $documents->first();

            $documentMediaId = $this->ensureDocumentMediaFileGenerated($document$context);

            if ($documentMediaId === null) {
                return null;
            }

            $fileBlob = $context->scope(Context::SYSTEM_SCOPE, fn (Context $context): string => $this->mediaService->loadFile($documentMediaId$context));

            $renderedDocument = new RenderedDocument('', '', $fileName);
            $renderedDocument->setContent($fileBlob);

            return $renderedDocument;
        }
Home | Imprint | This part of the site doesn't use cookies.