-
Notifications
You must be signed in to change notification settings - Fork 7
Update command #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update command #272
Changes from 3 commits
becb8b4
d51484c
674bb1e
c80f097
81743ec
4291977
d30349d
1b611ed
4b8d66c
6d68690
a48f88e
f225a7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like the naming combination here. For
|
||
} | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
There was a problem hiding this comment.
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:--status
option but change toinfo
/success
--validate-install
and usewarning
/error