Skip to content

Commit

Permalink
feat: add control to block updateStatus command if there arent quota …
Browse files Browse the repository at this point in the history
…for YouTube
  • Loading branch information
Yurujai committed Aug 21, 2024
1 parent df99b82 commit 583a7d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Command/VideoUpdateStatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ protected function updateVideoStatusInYoutube($youtubeDocuments, OutputInterface

try {
$result = $this->videoListService->updateVideoStatus($youtube, $multimediaObject);
if (false === $result['status'] && 'quotaExceeded' === $result['message']) {
break;
}
} catch (\Exception $e) {
$errorLog = sprintf('[YouTube] Update status of the video %s failed: %s', $multimediaObject->getId(), $e->getMessage());
$output->writeln($errorLog);
Expand Down
10 changes: 5 additions & 5 deletions Services/VideoListService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
$this->logger = $logger;
}

public function updateVideoStatus(Youtube $youtube, MultimediaObject $multimediaObject): bool
public function updateVideoStatus(Youtube $youtube, MultimediaObject $multimediaObject): array
{
$infoLog = sprintf(
'%s [%s] Started update video status on MultimediaObject with id %s',
Expand All @@ -56,7 +56,7 @@ public function updateVideoStatus(Youtube $youtube, MultimediaObject $multimedia
if (!$account) {
$this->logger->error('Multimedia object with ID '.$multimediaObject->getId().' doesnt have Youtube account set.');

return false;
return ['status' => false, 'message' => 'Multimedia object doesnt have Youtube account set'];
}

$video = $this->createVideo($youtube->getYoutubeId());
Expand All @@ -76,7 +76,7 @@ public function updateVideoStatus(Youtube $youtube, MultimediaObject $multimedia
$youtube->setError($error);
$this->documentManager->flush();

return false;
return ['status' => false, 'message' => $error['error']['errors'][0]['reason']];
}

$youtube->setStatus($status);
Expand All @@ -92,15 +92,15 @@ public function updateVideoStatus(Youtube $youtube, MultimediaObject $multimedia

$this->documentManager->flush();

return false;
return ['status' => false, 'message' => 'pumukit.statusError'];
}

$youtube->setSyncMetadataDate(new \DateTime('now'));
$youtube->removeError();

$this->documentManager->flush();

return true;
return ['status' => true];
}

private function list(Tag $youtubeAccount, \Google_Service_YouTube_Video $video): VideoListResponse
Expand Down

0 comments on commit 583a7d5

Please sign in to comment.