diff --git a/Command/AccountConnectionCommand.php b/Command/AccountConnectionCommand.php index c6f21d5..196096b 100644 --- a/Command/AccountConnectionCommand.php +++ b/Command/AccountConnectionCommand.php @@ -30,11 +30,12 @@ protected function configure() ->setName('pumukit:youtube:account:test') ->setDescription('Test connection accounts') ->addOption('account', null, InputOption::VALUE_REQUIRED, 'Name of account') + ->addOption('channel', null, InputOption::VALUE_REQUIRED, 'UID of channel') ->setHelp( <<<'EOT' Check: - php bin/console pumukit:youtube:account:test --account={login} + php bin/console pumukit:youtube:account:test --account={login} --channel={channelId} EOT ) @@ -45,33 +46,31 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $output->writeln('----- Testing connection with YouTube -----'); - $account = $this->accountExists($input->getOption('account')); - if (!$account) { - $output->writeln('Account not in DB'); + $youtubeAccount = $this->ensureYouTubeAccountExists($input); - return 0; - } - - $service = $this->googleAccountService->googleServiceFromAccount($account); + $service = $this->googleAccountService->googleServiceFromAccount($youtubeAccount); - $response = $service->playlists->listPlaylists('snippet,contentDetails', [ + $queryParams = [ + 'channelId' => $input->getOption('channel'), 'maxResults' => 5, - 'mine' => true, - ]); + ]; - print_r($response); + $response = $service->playlists->listPlaylists('snippet', $queryParams); + $output->writeln('Number of playlist of account: '.$response->pageInfo->getTotalResults()); return 0; } - private function accountExists(string $login): ?Tag + private function ensureYouTubeAccountExists(InputInterface $input): Tag { - $account = $this->documentManager->getRepository(Tag::class)->findOneBy(['properties.login' => $login]); + $youtubeAccount = $this->documentManager->getRepository(Tag::class)->findOneBy([ + 'properties.login' => $input->getOption('account'), + ]); - if ($account->getProperty('access_token') || $account->getProperty('refresh_token')) { - return $account; + if (!$youtubeAccount) { + throw new \Exception('Account not found'); } - return null; + return $youtubeAccount; } }