diff --git a/src/Importer/PageImporter.php b/src/Importer/PageImporter.php index 93a04a700..ad4e20841 100644 --- a/src/Importer/PageImporter.php +++ b/src/Importer/PageImporter.php @@ -24,6 +24,7 @@ use Doctrine\ORM\EntityManagerInterface; use Sylius\Component\Locale\Context\LocaleContextInterface; use Sylius\Component\Resource\Factory\FactoryInterface; +use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\Validator\Validator\ValidatorInterface; use Webmozart\Assert\Assert; @@ -110,9 +111,10 @@ public function import(array $row): void $page->setDescriptionWhenLinked($this->getTranslatableColumnValue(self::DESCRIPTION_WHEN_LINKED_COLUMN, $locale, $row)); $url = $this->getTranslatableColumnValue(self::IMAGE_COLUMN, $locale, $row); + $imageCode = $this->getTranslatableColumnValue(self::IMAGE_CODE_COLUMN, $locale, $row); if (null !== $url) { - $this->resolveImage($page, $url ?? '', $locale); + $this->resolveImage($page, $url ?? '', $locale, $imageCode); } } @@ -131,13 +133,15 @@ public function getResourceCode(): string return 'page'; } - private function resolveImage(PageInterface $page, string $url, string $locale): void + private function resolveImage(PageInterface $page, string $url, string $locale, string $imageCode): void { $downloadedImage = $this->imageDownloader->download($url); /** @var MediaInterface $image */ $image = $this->mediaFactory->createNew(); $image->setFile($downloadedImage); + $image->setType($this->getFileType($downloadedImage)); + $image->setCode($imageCode); /** @var PageTranslationInterface $pageTranslation */ $pageTranslation = $page->getTranslation($locale); @@ -147,12 +151,27 @@ private function resolveImage(PageInterface $page, string $url, string $locale): $this->entityManager->persist($image); } + private function getFileType(File $file): string + { + switch ($file->getExtension()) { + case 'png': + case 'jpg': + case 'jpeg': + case 'gif': + return MediaInterface::IMAGE_TYPE; + case 'mp4': + return MediaInterface::VIDEO_TYPE; + } + return MediaInterface::FILE_TYPE; + } + private function getTranslatableColumns(): array { return [ self::SLUG_COLUMN, self::NAME_COLUMN, self::IMAGE_COLUMN, + self::IMAGE_CODE_COLUMN, self::META_KEYWORDS_COLUMN, self::META_DESCRIPTION_COLUMN, self::CONTENT_COLUMN, diff --git a/src/Importer/PageImporterInterface.php b/src/Importer/PageImporterInterface.php index d63e52883..4c8f30a1c 100644 --- a/src/Importer/PageImporterInterface.php +++ b/src/Importer/PageImporterInterface.php @@ -28,15 +28,17 @@ interface PageImporterInterface extends ImporterInterface public const IMAGE_COLUMN = 'image__locale__'; - public const META_KEYWORDS_COLUMN = 'meta_keywords__locale__'; + public const IMAGE_CODE_COLUMN = 'imagecode__locale__'; - public const META_DESCRIPTION_COLUMN = 'meta_description__locale__'; + public const META_KEYWORDS_COLUMN = 'metakeywords__locale__'; + + public const META_DESCRIPTION_COLUMN = 'metadescription__locale__'; public const CONTENT_COLUMN = 'content__locale__'; public const BREADCRUMB_COLUMN = 'breadcrumb__locale__'; - public const NAME_WHEN_LINKED_COLUMN = 'name_when_linked__locale__'; + public const NAME_WHEN_LINKED_COLUMN = 'namewhenlinked__locale__'; - public const DESCRIPTION_WHEN_LINKED_COLUMN = 'description_when_linked__locale__'; + public const DESCRIPTION_WHEN_LINKED_COLUMN = 'descriptionwhenlinked__locale__'; }