Closed lcp0578 closed 4 years ago
Could you please elaborate?
Like this.
class BackupCommand extends ContainerAwareCommand
{
protected function configure()
{
$this->setName('system:backup:database')
->setDescription('backup database')
->setHelp('backup database');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln([
'start backup database',
'---------------'
]);
$command = $this->getApplication()->find('backup-manager:backup');
$fileName = 'backup/'.date('YmdHis'). '_'. mt_rand(10, 99) .'.sql';
$args = [
'command' => 'backup-manager:backup',
'database' => 'production',
'destinations' => ['local'], //THIS IS ARRAY!!!, not 'destinations' => 'local',
'-c' => 'gzip',
'--filename' => $fileName
];
$commandInput = new ArrayInput($args);
try {
$returnCode = $command->run($commandInput, $output);
if($returnCode == 0){
$this->flushDb($fileName);
}
$output->writeln([
'backup-manager:',
'code:' . $returnCode
]);
} catch (\Exception $e) {
$output->writeln([
'exception:',
' code' . $e->getCode(),
' msg' . $e->getMessage()
]);
}
$output->writeln([
'end backup database',
'--------------'
]);
}
Im still not sure what you mean. Are you saying that when you write your own command that invokes the backup-manager:backup
, then you are confused by the output? That is why you would like to have:
$output->writeln([
'end backup database',
'--------------'
]);
If so, you should rather update your command to print whatever you want.
Oh,
$args = [
'command' => 'backup-manager:backup',
'database' => 'production',
**'destinations' => ['local'], //THIS IS ARRAY!!!, not 'destinations' => 'local'**,
'-c' => 'gzip',
'--filename' => $fileName
];
Please use words when describing what you want. I don’t want to guess
I'm sorry, when i call the command the args should be 'destinations' => ['local']
, not 'destinations' => 'local'
, it is cost a lot time for me.
Okey, good catch. Can you send a PR to fix this issue?
my PR:
->addArgument('destinations', InputArgument::IS_ARRAY, 'What storages do you want to upload the backup to? Must be array.')
It is defined IS_ARRAY
, so i think should update command --help
info to warning it is must be array for the argument "destinations".
Doesn't InputArgument::IS_ARRAY
already specify that?
Yes, but I want to enrich the command help information
When i call
backup-manager:backup
in another command. destinations arg confuses me.