Skip to content
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ All notable changes to this project will be documented in this file.
* Removed propTypes.
* Upgraded redux-toolkit and how api slices are generated.
* Fixed redux-toolkit cache handling.
* Add Taskfile
* Added Taskfile
* Added update command.

### NB! Prior to 3.x the project was split into separate repositories

Expand Down
36 changes: 30 additions & 6 deletions src/Command/TemplatesListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;

Expand All @@ -24,10 +25,17 @@ public function __construct(
parent::__construct();
}

protected function configure(): void
{
$this->addOption('status', 's', InputOption::VALUE_NONE, 'Get status of installed templates.');
}

final protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$status = $input->getOption('status');

try {
$templates = $this->templateService->getCoreTemplates();

Expand All @@ -39,12 +47,28 @@ final protected function execute(InputInterface $input, OutputInterface $output)

$customTemplates = $this->templateService->getCustomTemplates();

$io->table(['ID', 'Title', 'Status', 'Type'], array_map(fn (TemplateData $templateData) => [
$templateData->id,
$templateData->title,
$templateData->installed ? 'Installed' : 'Not Installed',
$templateData->type,
], array_merge($templates, $customTemplates)));
$allTemplates = array_merge($templates, $customTemplates);

if ($status) {
$numberOfTemplates = count($allTemplates);
$numberOfInstallledTemplates = count(array_filter($allTemplates, fn ($entry): bool => $entry->installed));
$text = $numberOfInstallledTemplates.' / '.$numberOfTemplates.' templates installed.';

if ($numberOfInstallledTemplates === $numberOfTemplates) {
$io->success($text);
} else {
$io->warning($text);

return Command::FAILURE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantics, but not sure I think a status can fail. Even warning might be excessive. I would prefer that we either:

  • Keep the --status option but change to info / success
  • Change to --validate-install and use warning / error

}
} else {
$io->table(['ID', 'Title', 'Status', 'Type'], array_map(fn (TemplateData $templateData) => [
$templateData->id,
$templateData->title,
$templateData->installed ? 'Installed' : 'Not Installed',
$templateData->type,
], $allTemplates));
}

return Command::SUCCESS;
} catch (\Exception $e) {
Expand Down
88 changes: 84 additions & 4 deletions src/Command/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,89 @@

namespace App\Command;

class UpdateCommand
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
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: 'app:update',
description: 'Check if important commands have been run. Use --force to run the commands.',
)]
class UpdateCommand extends Command
{
// TODO: Test that migrations have been run.
// TODO: Run test of status for templates. No templates = clean install. Install all?
// TODO: Update existing templates.
protected function configure(): void
{
$this->addOption('force', 'f', InputOption::VALUE_NONE, 'Update all requirements. Otherwise, update command only checks requirements.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the naming combination here. --force means something else for me. If we need a status command I would make a dedicated app:status.

For aap:update we could follow doctrine migrations:

  • no option: Prompt for "are yoy sure?"
  • --no-interaction: just run

}

final protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$force = $input->getOption('force');

$application = $this->getApplication();

if (null === $application) {
$io->error('Application not initialized.');

return Command::FAILURE;
}

if ($force) {
// Run migrations.
$migrationsCommand = new ArrayInput([
'command' => 'doctrine:migrations:migrate',
]);
$migrationsCommand->setInteractive(false);
$application->doRun($migrationsCommand, $output);

// Install all templates.
$migrationsCommand = new ArrayInput([
'command' => 'app:templates:install',
'--all' => true,
'--update' => true,
]);
$migrationsCommand->setInteractive(false);
$application->doRun($migrationsCommand, $output);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the called command fail we should also fail.

} else {
$io->title('Migrations status');

// Check status for migrations.
$command = new ArrayInput([
'command' => 'doctrine:migrations:up-to-date',
]);
$result = $application->doRun($command, $output);

if (0 !== $result) {
$io->info('Run doctrine:migrations:migrate to migrate to latest migration.');

return Command::FAILURE;
}

$io->writeln('');
$io->writeln('');
$io->writeln('');
$io->title('Templates status');

// List status for templates.
$command = new ArrayInput([
'command' => 'app:templates:list',
'--status' => true,
]);
$result = $application->doRun($command, $output);

if (0 !== $result) {
$io->info('Run app:templates:install to install missing templates.');

return Command::FAILURE;
}
}

return Command::SUCCESS;
}
}