From da7719d607e2f2fc4a35142350a880d12386fb6d Mon Sep 17 00:00:00 2001 From: albacodina <48245111+albacodina@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:29:47 +0100 Subject: [PATCH] TTK-27357: Migrate command to pmk5 (#130) --- .../ImportYouTubeExternalPlayerCommand.php | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/Command/ImportYouTubeExternalPlayerCommand.php b/Command/ImportYouTubeExternalPlayerCommand.php index 84592d1..69a7384 100644 --- a/Command/ImportYouTubeExternalPlayerCommand.php +++ b/Command/ImportYouTubeExternalPlayerCommand.php @@ -5,7 +5,15 @@ namespace Pumukit\YoutubeBundle\Command; use Doctrine\ODM\MongoDB\DocumentManager; +use Pumukit\CoreBundle\Services\i18nService; +use Pumukit\SchemaBundle\Document\MediaType\External; +use Pumukit\SchemaBundle\Document\MediaType\MediaInterface; +use Pumukit\SchemaBundle\Document\MediaType\Metadata\Generic; +use Pumukit\SchemaBundle\Document\MediaType\Storage; use Pumukit\SchemaBundle\Document\MultimediaObject; +use Pumukit\SchemaBundle\Document\ValueObject\i18nText; +use Pumukit\SchemaBundle\Document\ValueObject\StorageUrl; +use Pumukit\SchemaBundle\Document\ValueObject\Tags; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; @@ -14,10 +22,12 @@ final class ImportYouTubeExternalPlayerCommand extends Command { private $documentManager; + private i18nService $i18nService; - public function __construct(DocumentManager $documentManager) + public function __construct(DocumentManager $documentManager, i18nService $i18nService) { $this->documentManager = $documentManager; + $this->i18nService = $i18nService; parent::__construct(); } @@ -75,8 +85,24 @@ private function obtainMultimediaObjects() private function updateMultimediaObject(MultimediaObject $multimediaObject): void { - $externalPlayer = 'https://www.youtube.com/embed/'.$multimediaObject->getProperty('youtube_import_id'); - $multimediaObject->setProperty('externalplayer', $externalPlayer); - $multimediaObject->setType(MultimediaObject::TYPE_EXTERNAL); + $externalLink = 'https://www.youtube.com/embed/'.$multimediaObject->getProperty('youtube_import_id'); + $externalMedia = $this->createExternalMedia($externalLink); + $multimediaObject->addExternal($externalMedia); + } + + private function createExternalMedia(string $externalLink): MediaInterface + { + $originalName = ''; + $description = i18nText::create($this->i18nService->generateI18nText('')); + $language = ''; + $tags = Tags::create(['display']); + $url = StorageUrl::create($externalLink); + $storage = Storage::external($url); + $metadata = Generic::create(''); + $external = External::create($originalName, $description, $language, $tags, false, false, 0, $storage, $metadata); + + $this->documentManager->persist($external); + + return $external; } }