-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Copy image jobs. * Remove cache dir validation * Create keyword checks if same keword with reqested name exists
- Loading branch information
1 parent
674bb8d
commit ba3f982
Showing
21 changed files
with
730 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AnzuSystems\CoreDamBundle\Command; | ||
|
||
use AnzuSystems\Contracts\AnzuApp; | ||
use AnzuSystems\CoreDamBundle\Command\Traits\OutputUtilTrait; | ||
use AnzuSystems\CoreDamBundle\Domain\Job\JobImageCopyFactory; | ||
use AnzuSystems\CoreDamBundle\Entity\Asset; | ||
use AnzuSystems\CoreDamBundle\Entity\AssetFile; | ||
use AnzuSystems\CoreDamBundle\Entity\AssetLicence; | ||
use AnzuSystems\CoreDamBundle\Repository\AssetFileRepository; | ||
use AnzuSystems\CoreDamBundle\Repository\AssetLicenceRepository; | ||
use AnzuSystems\CoreDamBundle\Repository\AssetRepository; | ||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Exception; | ||
use League\Flysystem\FilesystemException; | ||
use SplFileObject; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Helper\ProgressBar; | ||
use Symfony\Component\Console\Helper\QuestionHelper; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
|
||
#[AsCommand( | ||
name: 'anzu:job:copy-asset-files', | ||
description: 'Create JobImageCopy based on licenceId and assetLicenceIds from file' | ||
)] | ||
final class GenerateCopyJobCommand extends Command | ||
{ | ||
use OutputUtilTrait; | ||
private const string USERS_FILE_PATH_OPT = 'file'; | ||
private const string LICENCE_ID_ARG = 'licence'; | ||
private const string USERS_FILE_PATH_DEFAULT = 'image_split.csv'; | ||
|
||
private const int MAX_ASSETS_PER_JOB = 20; | ||
|
||
public function __construct( | ||
private readonly Connection $damMediaApiMigConnection, | ||
private readonly Connection $defaultConnection, | ||
private readonly JobImageCopyFactory $imageCopyFactory, | ||
private readonly AssetRepository $assetRepository, | ||
private readonly AssetLicenceRepository $assetLicenceRepository, | ||
private readonly AssetFileRepository $assetFileRepository, | ||
private readonly EntityManagerInterface $entityManager, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function configure(): void | ||
{ | ||
$this | ||
->addArgument( | ||
name: self::LICENCE_ID_ARG, | ||
mode: InputArgument::REQUIRED, | ||
) | ||
->addOption( | ||
name: self::USERS_FILE_PATH_OPT, | ||
mode: InputOption::VALUE_REQUIRED, | ||
default: AnzuApp::getDataDir() . '/' . self::USERS_FILE_PATH_DEFAULT | ||
); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
* @throws FilesystemException | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$licenceId = $input->getArgument(self::LICENCE_ID_ARG); | ||
$licence = $this->assetLicenceRepository->find($licenceId); | ||
|
||
if (null === $licence) { | ||
$output->writeln("<error>Licence not found: ({$licenceId})</error>"); | ||
|
||
return Command::FAILURE; | ||
} | ||
$filePath = $input->getOption(self::USERS_FILE_PATH_OPT); | ||
if (false === file_exists($filePath)) { | ||
$output->writeln("<error>File not found at path: ({$filePath})</error>"); | ||
|
||
return Command::FAILURE; | ||
} | ||
|
||
/** @var QuestionHelper $helper */ | ||
$helper = $this->getHelper('question'); | ||
$question = new ConfirmationQuestion(sprintf('Copy to licence (%s)? [y/n] ', $licence->getName()), false); | ||
|
||
if (false === $helper->ask($input, $output, $question)) { | ||
return Command::SUCCESS; | ||
} | ||
|
||
$csv = new SplFileObject($filePath); | ||
$csv->setFlags(SplFileObject::SKIP_EMPTY); | ||
$progress = new ProgressBar($output); | ||
$progress->start(); | ||
|
||
/** @var array<int|string, Asset> $assets */ | ||
$assets = []; | ||
while (false === $csv->eof()) { | ||
$row = $csv->fgetcsv(); | ||
|
||
if (false === is_array($row) || false === isset($row[0])) { | ||
continue; | ||
} | ||
|
||
$assetFile = $this->assetFileRepository->find($row[0]); | ||
if (false === ($assetFile instanceof AssetFile)) { | ||
continue; | ||
} | ||
|
||
$assets[(string) $assetFile->getAsset()->getId()] = $assetFile->getAsset(); | ||
if (count($assets) >= self::MAX_ASSETS_PER_JOB) { | ||
$this->imageCopyFactory->createPodcastSynchronizerJob($licence, new ArrayCollection($assets)); | ||
$assets = []; | ||
$this->entityManager->clear(); | ||
/** @var AssetLicence $licence */ | ||
$licence = $this->assetLicenceRepository->find($licenceId); | ||
} | ||
|
||
$progress->advance(); | ||
} | ||
|
||
if (false === empty($assets)) { | ||
$this->imageCopyFactory->createPodcastSynchronizerJob($licence, new ArrayCollection($assets)); | ||
} | ||
|
||
$progress->finish(); | ||
$output->writeln(''); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AnzuSystems\CoreDamBundle\Domain\Job; | ||
|
||
use AnzuSystems\CommonBundle\Entity\Interfaces\JobInterface; | ||
use AnzuSystems\CommonBundle\Validator\Validator; | ||
use AnzuSystems\CoreDamBundle\Entity\JobImageCopy; | ||
|
||
final readonly class JobImageCopyFacade | ||
{ | ||
public function __construct( | ||
private JobImageCopyManager $manager, | ||
private Validator $validator, | ||
) { | ||
} | ||
|
||
public function create(JobImageCopy $job): JobInterface | ||
{ | ||
$this->validator->validate($job); | ||
$this->manager->create($job); | ||
|
||
return $job; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AnzuSystems\CoreDamBundle\Domain\Job; | ||
|
||
use AnzuSystems\CoreDamBundle\Entity\Asset; | ||
use AnzuSystems\CoreDamBundle\Entity\AssetLicence; | ||
use AnzuSystems\CoreDamBundle\Entity\JobImageCopy; | ||
use AnzuSystems\CoreDamBundle\Entity\JobImageCopyItem; | ||
use Doctrine\Common\Collections\Collection; | ||
|
||
final readonly class JobImageCopyFactory | ||
{ | ||
public function __construct( | ||
private JobImageCopyFacade $imageCopyFacade, | ||
) { | ||
} | ||
|
||
/** | ||
* @param Collection<int|string, Asset> $assets | ||
*/ | ||
public function createPodcastSynchronizerJob(AssetLicence $licence, Collection $assets): JobImageCopy | ||
{ | ||
$job = (new JobImageCopy()) | ||
->setLicence($licence) | ||
->setItems( | ||
$assets->map( | ||
fn (Asset $asset): JobImageCopyItem => (new JobImageCopyItem())->setSourceAsset($asset) | ||
) | ||
) | ||
; | ||
|
||
$this->imageCopyFacade->create($job); | ||
|
||
return $job; | ||
} | ||
} |
Oops, something went wrong.