backup-manager / symfony

Driver to seamlessly integrate the Backup Manager into Symfony applications.
119 stars 40 forks source link

update backup command help info. #57

Closed lcp0578 closed 4 years ago

lcp0578 commented 5 years ago

When i call backup-manager:backup in another command. destinations arg confuses me.

Nyholm commented 5 years ago

Could you please elaborate?

lcp0578 commented 5 years ago

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',
            '--------------'
        ]);
    }
Nyholm commented 5 years ago

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.

lcp0578 commented 5 years ago

Oh,

$args = [
            'command' => 'backup-manager:backup',
            'database' => 'production',
            **'destinations' => ['local'], //THIS IS ARRAY!!!, not 'destinations' => 'local'**,
            '-c' => 'gzip',
            '--filename' => $fileName
        ];
Nyholm commented 5 years ago

Please use words when describing what you want. I don’t want to guess

lcp0578 commented 5 years ago

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.

Nyholm commented 5 years ago

Okey, good catch. Can you send a PR to fix this issue?

lcp0578 commented 5 years ago

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".

Nyholm commented 5 years ago

Doesn't InputArgument::IS_ARRAY already specify that?

lcp0578 commented 5 years ago

Yes, but I want to enrich the command help information