Skip to content

Commit

Permalink
refactor(admin/cli): replace EmsCommand.php by AbstractCommand from c…
Browse files Browse the repository at this point in the history
…… …ommon (#1022)
  • Loading branch information
Davidmattei committed Sep 27, 2024
1 parent 373792d commit bf76315
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 47 deletions.
5 changes: 2 additions & 3 deletions EMS/core-bundle/src/Command/CleanAssetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\EntityManager;
use EMS\CommonBundle\Common\Command\AbstractCommand;
use EMS\CoreBundle\Entity\Revision;
use EMS\CoreBundle\Entity\UploadedAsset;
use EMS\CoreBundle\Repository\RevisionRepository;
Expand All @@ -14,7 +15,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CleanAssetCommand extends EmsCommand
class CleanAssetCommand extends AbstractCommand
{
protected static $defaultName = 'ems:asset:clean';

Expand All @@ -37,8 +38,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @var RevisionRepository $revRepo */
$revRepo = $em->getRepository(Revision::class);

$this->formatStyles($output);

$progress = new ProgressBar($output, $repository->countHashes());
$progress->start();

Expand Down
17 changes: 0 additions & 17 deletions EMS/core-bundle/src/Command/EmsCommand.php

This file was deleted.

3 changes: 2 additions & 1 deletion EMS/core-bundle/src/Command/ExtractAssetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EMS\CoreBundle\Command;

use EMS\CommonBundle\Common\Command\AbstractCommand;
use EMS\CommonBundle\Storage\StorageManager;
use EMS\CoreBundle\Service\AssetExtractorService;
use Psr\Log\LoggerInterface;
Expand All @@ -12,7 +13,7 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

class ExtractAssetCommand extends EmsCommand
class ExtractAssetCommand extends AbstractCommand
{
protected static $defaultName = 'ems:asset:extract';

Expand Down
3 changes: 2 additions & 1 deletion EMS/core-bundle/src/Command/IndexFileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManager;
use EMS\CommonBundle\Common\Command\AbstractCommand;
use EMS\CommonBundle\Helper\EmsFields;
use EMS\CoreBundle\Entity\Revision;
use EMS\CoreBundle\Repository\RevisionRepository;
Expand All @@ -21,7 +22,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;

class IndexFileCommand extends EmsCommand
class IndexFileCommand extends AbstractCommand
{
protected static $defaultName = 'ems:revisions:index-file-fields';
/** @var string */
Expand Down
4 changes: 2 additions & 2 deletions EMS/core-bundle/src/Command/RebuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\Persistence\ObjectManager;
use EMS\CommonBundle\Common\Command\AbstractCommand;
use EMS\CommonBundle\Service\ElasticaService;
use EMS\CoreBundle\Entity\ContentType;
use EMS\CoreBundle\Entity\Environment;
Expand All @@ -19,7 +20,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class RebuildCommand extends EmsCommand
class RebuildCommand extends AbstractCommand
{
public const ALL = 'all';
protected static $defaultName = self::COMMAND;
Expand Down Expand Up @@ -82,7 +83,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->aliasService->build();
$this->yellowOk = true === $input->getOption('yellow-ok');
$this->all = true === $input->getOption(self::ALL);
$this->formatStyles($output);
$this->waitFor($this->yellowOk, $output);

$this->bulkSize = \intval($input->getOption('bulk-size'));
Expand Down
21 changes: 2 additions & 19 deletions EMS/core-bundle/src/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\EntityManager;
use EMS\CommonBundle\Common\Command\AbstractCommand;
use EMS\CommonBundle\Helper\EmsFields;
use EMS\CoreBundle\Elasticsearch\Bulker;
use EMS\CoreBundle\Entity\ContentType;
Expand All @@ -22,7 +23,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class ReindexCommand extends EmsCommand
class ReindexCommand extends AbstractCommand
{
protected static $defaultName = 'ems:environment:reindex';
private int $count = 0;
Expand Down Expand Up @@ -76,7 +77,6 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->formatStyles($output);
$name = $input->getArgument('name');
$index = $input->getArgument('index');
$signData = true === $input->getOption('sign-data');
Expand Down Expand Up @@ -209,21 +209,4 @@ public function reindex(string $name, ContentType $contentType, ?string $index,
$output->writeln('WARNING: Environment named '.$name.' not found');
}
}

/**
* @param array<mixed> $response
*/
public function treatBulkResponse(array $response): void
{
foreach ($response['items'] as $item) {
if (isset($item['index']['error'])) {
++$this->error;
$this->logger->warning('log.reindex.revision.error', [
EmsFields::LOG_OUUID_FIELD => $item['index']['_id'],
]);
} else {
++$this->count;
}
}
}
}
5 changes: 2 additions & 3 deletions EMS/core-bundle/src/Command/SynchronizeAssetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\EntityManager;
use EMS\CommonBundle\Common\Command\AbstractCommand;
use EMS\CommonBundle\Storage\NotFoundException;
use EMS\CoreBundle\Entity\UploadedAsset;
use EMS\CoreBundle\Repository\UploadedAssetRepository;
Expand All @@ -15,7 +16,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class SynchronizeAssetCommand extends EmsCommand
class SynchronizeAssetCommand extends AbstractCommand
{
protected static $defaultName = 'ems:asset:synchronize';
/** @var string */
Expand All @@ -40,8 +41,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @var UploadedAssetRepository $repository */
$repository = $em->getRepository(UploadedAsset::class);

$this->formatStyles($output);

$storagesList = [];
foreach ($this->fileService->getHealthStatuses() as $storageName => $health) {
if ($health) {
Expand Down
3 changes: 2 additions & 1 deletion EMS/core-bundle/src/Command/UpdateMetaFieldCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\EntityManager;
use EMS\CommonBundle\Common\Command\AbstractCommand;
use EMS\CoreBundle\Entity\Environment;
use EMS\CoreBundle\Entity\Revision;
use EMS\CoreBundle\Exception\NotLockedException;
Expand All @@ -16,7 +17,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class UpdateMetaFieldCommand extends EmsCommand
class UpdateMetaFieldCommand extends AbstractCommand
{
protected static $defaultName = 'ems:environment:updatemetafield';

Expand Down

0 comments on commit bf76315

Please sign in to comment.