Skip to content

Commit

Permalink
fix: refactor code to make it compatible with latest pumukit
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurujai committed Oct 31, 2024
1 parent 1681e89 commit 5af122a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Services/APIDeleteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
$this->allowedTagToDelete = $allowedTagToDelete;
}

public function removeTagFromMultimediaObject(string $id, string $tagId = null, string $tagCod = null)
public function removeTagFromMultimediaObject(string $id, string $tagId = null, string $tagCod = null): void
{
$multimediaObject = $this->documentManager->getRepository(MultimediaObject::class)->findOneBy([
'_id' => $id,
Expand All @@ -55,7 +55,7 @@ public function removeTagFromMultimediaObject(string $id, string $tagId = null,

$tag = $this->documentManager->getRepository(Tag::class)->findOneBy($criteria);

if (!$tag || !$tag instanceof Tag) {
if (!$tag instanceof Tag) {
$msg = sprintf('The tag with criteria %s cannot be found on the database', json_encode($criteria, JSON_THROW_ON_ERROR));

throw new \Exception($msg, Response::HTTP_NOT_FOUND);
Expand All @@ -77,7 +77,7 @@ public function removeTagFromMultimediaObject(string $id, string $tagId = null,
$this->documentManager->flush();
}

private function canTagBeRemoved(Tag $tag)
private function canTagBeRemoved(Tag $tag): bool
{
$tags = $this->getTagsAllowedToDelete();

Expand Down
20 changes: 11 additions & 9 deletions Services/APIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

use Doctrine\ODM\MongoDB\DocumentManager;
use Pumukit\CoreBundle\Services\ImportMappingDataService;
use Pumukit\EncoderBundle\Services\JobService;
use Pumukit\EncoderBundle\Services\DTO\JobOptions;
use Pumukit\EncoderBundle\Services\JobCreator;
use Pumukit\SchemaBundle\Document\MultimediaObject;
use Pumukit\SchemaBundle\Document\Person;
use Pumukit\SchemaBundle\Document\Role;
Expand All @@ -24,15 +25,15 @@ class APIService extends APICommonService
public const PUMUKIT_EPISODE = 'pumukit/episode';

private $materialService;
private $jobService;
private $jobCreator;
private $personService;
private $importMappingDataService;

public function __construct(
DocumentManager $documentManager,
FactoryService $factoryService,
MaterialService $materialService,
JobService $jobService,
JobCreator $jobCreator,
PersonService $personService,
ImportMappingDataService $importMappingDataService,
MultimediaObjectEventDispatcherService $multimediaObjectEventDispatcherService,
Expand All @@ -42,7 +43,7 @@ public function __construct(
$this->documentManager = $documentManager;
$this->factoryService = $factoryService;
$this->materialService = $materialService;
$this->jobService = $jobService;
$this->jobCreator = $jobCreator;
$this->personService = $personService;
$this->importMappingDataService = $importMappingDataService;
}
Expand Down Expand Up @@ -92,8 +93,8 @@ public function addTrack(array $requestParameters)

$multimediaObject = $this->getMultimediaObjectFromMediapackageXML($mediaPackage);

// Use master_copy by default, maybe later add an optional parameter to endpoint to add tracks
$multimediaObject = $this->jobService->createTrackFromLocalHardDrive($multimediaObject, $body, $profile, $priority, $language, $description);
$jobOptions = new JobOptions($profile, $priority, $language, $description);
$multimediaObject = $this->jobCreator->fromUploadedFile($multimediaObject, $body, $jobOptions);

$mediaPackage = $this->generateXML($multimediaObject);

Expand Down Expand Up @@ -146,15 +147,15 @@ public function addDCCatalog(array $requestParameters, User $user = null)

$namespacesMetadata = $body->getNamespaces(true);
$bodyDcterms = $body->children($namespacesMetadata['dcterms']);
if (0 === strpos($flavor, 'dublincore/series')) {
if (str_starts_with($flavor, 'dublincore/series')) {
$series = $this->documentManager->getRepository(Series::class)->findOneBy(['_id' => (string) $bodyDcterms->identifier]);
if (!$series) {
$series = $this->createSeriesForMediaPackage($user, $requestParameters);
}
$multimediaObject->setSeries($series);
$this->documentManager->persist($multimediaObject);
$this->documentManager->flush();
} elseif (0 === strpos($flavor, 'dublincore/episode')) {
} elseif (str_starts_with($flavor, 'dublincore/episode')) {
if ($newTitle = (string) $bodyDcterms->title) {
foreach ($multimediaObject->getI18nTitle() as $language => $title) {
$multimediaObject->setTitle($newTitle, $language);
Expand Down Expand Up @@ -254,7 +255,8 @@ public function addMediaPackage(array $requestParameters, User $user = null)
$body = [$body];
}
foreach ($body as $track) {
$multimediaObject = $this->jobService->createTrackFromLocalHardDrive($multimediaObject, $track, $profile, $priority, $language, $description);
$jobOptions = new JobOptions($profile, $priority, $language, $description);
$multimediaObject = $this->jobCreator->fromUploadedFile($multimediaObject, $track, $jobOptions);
}
}

Expand Down

0 comments on commit 5af122a

Please sign in to comment.