getDocumentMediaFileId example

$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));

        $fileName = $documentMedia->getFileName() . '.' . $documentMedia->getFileExtension();
        
'documentMediaFileId' => null,
                'static' => false,
            ]]$this->context);
        }

        $this->documentGenerator->upload($documentId$this->context, $uploadFileRequest);

        /** @var DocumentEntity $document */
        $document = $this->documentRepository->search(new Criteria([$documentId])$this->context)->get($documentId);

        static::assertNotNull($document);
        static::assertNotNull($document->getDocumentMediaFileId());

        $savedContent = $this->getContainer()->get(MediaService::class)->loadFile($document->getDocumentMediaFileId()$this->context);
        static::assertEquals($uploadFileRequest->getContent()$savedContent);
    }

    public static function uploadDataProvider(): \Generator
    {
        yield 'upload successfully' => [
            false,
            new Request([
                'extension' => FileTypes::PDF,
                
$renderedDocument = new RenderedDocument('', '', $fileName);

        $renderedDocument->setContent($this->fpdi->Output($fileName, 'S'));
        $renderedDocument->setContentType(PdfRenderer::FILE_CONTENT_TYPE);
        $renderedDocument->setName($fileName);

        return $renderedDocument;
    }

    private function ensureDocumentMediaFileGenerated(DocumentEntity $document, Context $context): ?string
    {
        $documentMediaId = $document->getDocumentMediaFileId();

        if ($documentMediaId !== null || $document->isStatic()) {
            return $documentMediaId;
        }

        $operation = new DocumentGenerateOperation(
            $document->getOrderId(),
            FileTypes::PDF,
            $document->getConfig(),
            $document->getReferencedDocumentId()
        );

        
static::assertCount(1, $attachments);
        static::assertIsArray($attachments[0]);
        static::assertArrayHasKey('content', $attachments[0]);

        $criteria = new Criteria([$document->getId()]);
        $criteria->addAssociation('documentMediaFile');

        /** @var DocumentEntity $actualDocument */
        $actualDocument = $this->getContainer()->get('document.repository')->search($criteria$this->context)->first();

        static::assertNotNull($actualDocument);
        static::assertNotNull($actualDocument->getDocumentMediaFileId());
        static::assertNotNull($actualDocument->getDocumentMediaFile());

        $content = $this->getContainer()->get(MediaService::class)->loadFile($actualDocument->getDocumentMediaFileId()$this->context);

        $fileName = $actualDocument->getDocumentMediaFile()->getFileName() . '.' . $actualDocument->getDocumentMediaFile()->getFileExtension();
        static::assertNotNull($content);
        static::assertSame($content$attachments[0]['content']);
        static::assertArrayHasKey('fileName', $attachments[0]);
        static::assertSame($fileName$attachments[0]['fileName']);
        static::assertArrayHasKey('mimeType', $attachments[0]);
        static::assertSame(PdfRenderer::FILE_CONTENT_TYPE, $attachments[0]['mimeType']);
    }
Home | Imprint | This part of the site doesn't use cookies.