Skip to content

Commit

Permalink
Merge branch '6.x' into chore/composer.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidmattei authored Dec 28, 2023
2 parents 5beb3bd + 0e8cabc commit 6727783
Show file tree
Hide file tree
Showing 68 changed files with 523 additions and 212 deletions.
11 changes: 8 additions & 3 deletions EMS/client-helper-bundle/src/Command/HealthCheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@

namespace EMS\ClientHelperBundle\Command;

use EMS\ClientHelperBundle\Commands;
use EMS\ClientHelperBundle\Exception\ClusterHealthNotGreenException;
use EMS\ClientHelperBundle\Exception\ClusterHealthRedException;
use EMS\ClientHelperBundle\Exception\IndexNotFoundException;
use EMS\ClientHelperBundle\Helper\Environment\EnvironmentHelper;
use EMS\CommonBundle\Common\Command\AbstractCommand;
use EMS\CommonBundle\Service\ElasticaService;
use EMS\CommonBundle\Storage\StorageManager;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: Commands::HEALTH_CHECK,
description: 'Performs system health check.',
hidden: false
)]
final class HealthCheckCommand extends AbstractCommand
{
protected static $defaultName = 'emsch:health-check';

public function __construct(
private readonly EnvironmentHelper $environmentHelper,
private readonly ElasticaService $elasticaService,
Expand All @@ -29,7 +34,7 @@ public function __construct(

protected function configure(): void
{
$this->setDescription('Performs system health check.')
$this
->setHelp('Verify that the assets folder exists and is not empty. Verify that the Elasticsearch cluster is at least yellow and that the configured indexes exist.')
->addOption('green', 'g', InputOption::VALUE_NONE, 'Require a green Elasticsearch cluster health.', null)
->addOption('skip-storage', 's', InputOption::VALUE_NONE, 'Skip the storage health check.', null);
Expand Down
10 changes: 10 additions & 0 deletions EMS/client-helper-bundle/src/Commands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace EMS\ClientHelperBundle;

final class Commands
{
public const HEALTH_CHECK = 'emsch:health-check';
}
6 changes: 5 additions & 1 deletion EMS/common-bundle/src/Command/Admin/CommandCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
use EMS\CommonBundle\Commands;
use EMS\CommonBundle\Common\Admin\AdminHelper;
use EMS\CommonBundle\Common\Command\AbstractCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: Commands::ADMIN_COMMAND,
hidden: false
)]
class CommandCommand extends AbstractCommand
{
final public const COMMAND = 'remote-command';
protected static $defaultName = Commands::ADMIN_COMMAND;
private string $command;

public function __construct(private readonly AdminHelper $adminHelper)
Expand Down
8 changes: 6 additions & 2 deletions EMS/common-bundle/src/Command/Admin/NextJobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@
use EMS\CommonBundle\Common\Admin\AdminHelper;
use EMS\CommonBundle\Common\Command\AbstractCommand;
use EMS\CommonBundle\Common\Job\JobManager;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: Commands::ADMIN_NEXT_JOB,
description: 'Contact the admin to check if a job is planned for the given tag and run it locally.',
hidden: false
)]
class NextJobCommand extends AbstractCommand
{
final public const TAG_ARGUMENT = 'tag';
final public const SILENT_OPTION = 'silent';
protected static $defaultName = Commands::ADMIN_NEXT_JOB;
private string $tag;
private bool $silent;

Expand All @@ -30,7 +35,6 @@ public function __construct(private readonly AdminHelper $adminHelper, private r
protected function configure(): void
{
parent::configure();
$this->setDescription('Contact the admin to check if a job is planned for the given tag and run it locally');
$this->addArgument(self::TAG_ARGUMENT, InputArgument::REQUIRED, 'Tag that identifies the scheduled jobs');
$this->addOption(self::SILENT_OPTION, null, InputOption::VALUE_NONE, 'Dont echo outputs in the console (only in the admin job logs)');
}
Expand Down
8 changes: 6 additions & 2 deletions EMS/common-bundle/src/Command/ClearLogsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
use EMS\CommonBundle\Commands;
use EMS\CommonBundle\Common\Command\AbstractCommand;
use EMS\CommonBundle\Repository\LogRepository;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: Commands::CLEAR_LOGS,
description: 'Clear doctrine logs.',
hidden: false
)]
class ClearLogsCommand extends AbstractCommand
{
protected static $defaultName = Commands::CLEAR_LOGS;
private \DateTime $before;
/** @var string[] */
private array $channels = [];
Expand All @@ -28,7 +33,6 @@ public function __construct(private readonly LogRepository $logRepository)

protected function configure(): void
{
$this->setDescription('Clear doctrine logs');
$this
->addOption(self::OPTION_BEFORE, null, InputOption::VALUE_OPTIONAL, 'CLear logs older than the strtotime (-1day, -5min, now)', '-1week')
->addOption(self::OPTION_CHANNEL, null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Define channels default [app]', ['app'])
Expand Down
8 changes: 6 additions & 2 deletions EMS/common-bundle/src/Command/CurlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use EMS\CommonBundle\Storage\Service\StorageInterface;
use EMS\CommonBundle\Storage\StorageManager;
use EMS\CommonBundle\Twig\AssetRuntime;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -24,14 +25,18 @@
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

#[AsCommand(
name: Commands::CURL,
description: 'Curl an internal resource.',
hidden: false
)]
class CurlCommand extends AbstractCommand
{
final public const ARGUMENT_URL = 'url';
final public const ARGUMENT_FILENAME = 'filename';
final public const OPTION_METHOD = 'method';
final public const OPTION_BASE_URL = 'base-url';
final public const OPTION_SAVE = 'save';
protected static $defaultName = Commands::CURL;
private ?SessionInterface $session = null;

private string $url;
Expand All @@ -47,7 +52,6 @@ public function __construct(private readonly EventDispatcherInterface $eventDisp

protected function configure(): void
{
$this->setDescription('Curl an internal resource');
$this->addArgument(self::ARGUMENT_URL, InputArgument::REQUIRED, 'Absolute url to the resource');
$this->addArgument(self::ARGUMENT_FILENAME, InputArgument::REQUIRED, 'Filename where to save the ouput');
$this->addOption(self::OPTION_METHOD, null, InputOption::VALUE_OPTIONAL, 'HTTP method (GET, POST)', 'GET');
Expand Down
9 changes: 7 additions & 2 deletions EMS/common-bundle/src/Command/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
use EMS\CommonBundle\Common\Command\AbstractCommand;
use EMS\CommonBundle\Service\ElasticaService;
use EMS\CommonBundle\Storage\StorageManager;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: Commands::STATUS,
description: 'Returns the health status of the elasticsearch cluster and of the different storage services.',
hidden: false
)]
class StatusCommand extends AbstractCommand
{
protected static $defaultName = Commands::STATUS;
private const OPTION_TIMEOUT = 'timeout';
private const OPTION_SILENT = 'silent';
private const OPTION_WAIT_FOR_STATUS = 'wait-for-status';
Expand All @@ -26,7 +31,7 @@ public function __construct(private readonly ElasticaService $elasticaService, p

protected function configure(): void
{
$this->setDescription('Returns the health status of the elasticsearch cluster and of the different storage services.')
$this
->addOption(
self::OPTION_SILENT,
null,
Expand Down
9 changes: 8 additions & 1 deletion EMS/core-bundle/src/Command/ActivateContentTypeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace EMS\CoreBundle\Command;

use EMS\CommonBundle\Helper\EmsFields;
use EMS\CoreBundle\Commands;
use EMS\CoreBundle\Service\ContentTypeService;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -16,9 +18,14 @@
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(
name: Commands::CONTENT_TYPE_ACTIVATE,
description: 'Activate a content type.',
hidden: false,
aliases: ['ems:contenttype:activate']
)]
class ActivateContentTypeCommand extends Command
{
protected static $defaultName = 'ems:contenttype:activate';
private ?SymfonyStyle $io = null;
private ?bool $deactivate = null;

Expand Down
12 changes: 9 additions & 3 deletions EMS/core-bundle/src/Command/AlignManagedAliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@

namespace EMS\CoreBundle\Command;

use EMS\CoreBundle\Commands;
use EMS\CoreBundle\Service\AliasService;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: Commands::MANAGED_ALIAS_ALIGN,
description: 'Align a managed alias to another.',
hidden: false,
aliases: ['ems:managedalias:align']
)]
class AlignManagedAliases extends Command
{
protected static $defaultName = 'ems:managedalias:align';

public function __construct(protected LoggerInterface $logger, protected AliasService $aliasService)
{
parent::__construct();
}

protected function configure(): void
{
$this->setDescription('Align a managed alias to another')
$this
->addArgument(
'source',
InputArgument::REQUIRED,
Expand Down
14 changes: 8 additions & 6 deletions EMS/core-bundle/src/Command/Asset/HeadAssetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@

namespace EMS\CoreBundle\Command\Asset;

use EMS\CoreBundle\Commands;
use EMS\CoreBundle\Entity\UploadedAsset;
use EMS\CoreBundle\Service\FileService;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(
name: Commands::ASSET_HEAD,
description: 'Loop over all known uploaded assets and update the seen information if the file is connected.',
hidden: false,
aliases: ['ems:asset:head']
)]
final class HeadAssetCommand extends Command
{
protected static $defaultName = 'ems:asset:head';
private SymfonyStyle $io;

public function __construct(protected LoggerInterface $logger, protected FileService $fileService)
{
parent::__construct();
}

protected function configure(): void
{
$this->setDescription('Loop over all known uploaded assets and update the seen information if the file is connected');
}

protected function initialize(InputInterface $input, OutputInterface $output): void
{
$this->io = new SymfonyStyle($input, $output);
Expand Down
17 changes: 11 additions & 6 deletions EMS/core-bundle/src/Command/Check/AliasesCheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@

namespace EMS\CoreBundle\Command\Check;

use EMS\CoreBundle\Command\RebuildCommand;
use EMS\CoreBundle\Commands;
use EMS\CoreBundle\Entity\User;
use EMS\CoreBundle\Service\AliasService;
use EMS\CoreBundle\Service\EnvironmentService;
use EMS\CoreBundle\Service\JobService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(
name: Commands::MANAGED_ALIAS_CHECK,
description: 'Checks that all managed environments have their corresponding alias and index present in the cluster.',
hidden: false,
aliases: ['ems:check:aliases']
)]
final class AliasesCheckCommand extends Command
{
protected static $defaultName = self::COMMAND;
public const COMMAND = 'ems:check:aliases';
private const OPTION_REPAIR = 'repair';
private SymfonyStyle $io;
private bool $repair = false;
Expand All @@ -30,7 +35,7 @@ public function __construct(private readonly EnvironmentService $environmentServ

protected function configure(): void
{
$this->setDescription('Checks that all managed environments have their corresponding alias and index present in the cluster.')
$this
->addOption(self::OPTION_REPAIR, null, InputOption::VALUE_NONE, 'If an environment does not have its alias present and if they are no pending job a rebuild job is queued.');
}

Expand Down Expand Up @@ -63,9 +68,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$fakeUser = new User();
$fakeUser->setUsername(self::COMMAND);
$fakeUser->setUsername(Commands::MANAGED_ALIAS_CHECK);
$command = \join(' ', [
RebuildCommand::COMMAND,
Commands::ENVIRONMENT_REBUILD,
$environment->getName(),
]);
$this->jobService->createCommand($fakeUser, $command);
Expand Down
15 changes: 8 additions & 7 deletions EMS/core-bundle/src/Command/CleanAssetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@

use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\EntityManager;
use EMS\CoreBundle\Commands;
use EMS\CoreBundle\Entity\Revision;
use EMS\CoreBundle\Entity\UploadedAsset;
use EMS\CoreBundle\Repository\RevisionRepository;
use EMS\CoreBundle\Repository\UploadedAssetRepository;
use EMS\CoreBundle\Service\FileService;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: Commands::ASSET_CLEAN,
description: 'Unreference useless assets (no files are deleted from storages).',
hidden: false,
aliases: ['ems:asset:clean']
)]
class CleanAssetCommand extends EmsCommand
{
protected static $defaultName = 'ems:asset:clean';

public function __construct(protected LoggerInterface $logger, protected Registry $doctrine, protected FileService $fileService)
{
parent::__construct();
}

protected function configure(): void
{
$this->setDescription('Unreference useless assets (no files are deleted from storages)');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var EntityManager $em */
Expand Down
Loading

0 comments on commit 6727783

Please sign in to comment.