Skip to content

Commit

Permalink
TTK-27357: Migrate command to pmk5 (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
albacodina authored Dec 9, 2024
1 parent a754b4a commit da7719d
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions Command/ImportYouTubeExternalPlayerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down Expand Up @@ -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;
}
}

0 comments on commit da7719d

Please sign in to comment.