setName('photos:albums:add')
->setDescription('Add specified photo to album')
->addArgument('user', InputArgument::REQUIRED, 'User owning the album')
->addArgument('album', InputArgument::REQUIRED, 'Album name')
->addArgument('file', InputArgument::REQUIRED,
'Path of file to add to the album. It must already be scanned and available in NextCloud. Example: Photos/picture1.jpg');
}
/**
* Execute the command
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$userString = $input->getArgument('user');
$albumString = $input->getArgument('album');
$filePath = $input->getArgument('file');
$user = $this->userManager->get($userString);
if ($user === null) {
throw new \Exception("User $userString was not found");
}
$userID = $user->getUID();
try {
$pictureFileID = $this->rootFolder->getUserFolder($userID)->get($filePath)->getId();
} catch (\Exception $ex) {
$output->writeln('Invalid file path');
$output->writeln($ex->getMessage());
return 1;
}
$album = $this->albumMapper->getByName($albumString, $userString);
if (!$album) {
throw new \Exception("Album $albumString was not found");
}
try {
$this->albumMapper->addFile($album->getId(), $pictureFileID, $userID);
} catch (\Exception $ex) {
$output->writeln("Problem adding $filePath to $albumString");
$output->writeln($ex->getMessage());
return 1;
}
return 0;
}
}