Skip to content

Commit b6e738d

Browse files
authored
Merge pull request #51 from mxgross/BackupCommand
Backup command
2 parents b29f8d7 + f41e1cf commit b6e738d

File tree

7 files changed

+541
-287
lines changed

7 files changed

+541
-287
lines changed

Command/EasyBackupBackupCommand.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the EasyBackupBundle.
5+
* All rights reserved by Maximilian Groß (www.maximiliangross.de).
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace KimaiPlugin\EasyBackupBundle\Command;
11+
12+
use Symfony\Component\Console\Command\Command;
13+
use Symfony\Component\Console\Attribute\AsCommand;
14+
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
15+
use Symfony\Component\Console\Input\InputInterface;
16+
use Symfony\Component\Console\Output\OutputInterface;
17+
18+
use KimaiPlugin\EasyBackupBundle\Service\EasyBackupService;
19+
20+
// the name of the command is what users type after "php bin/console"
21+
22+
class EasyBackupBackupCommand extends ContainerAwareCommand
23+
{
24+
protected static $defaultName = 'EasyBackup:backup';
25+
// the command description shown when running "php bin/console list"
26+
protected static $defaultDescription = 'Creates a new backup.';
27+
28+
private $router;
29+
private $easyBackupService;
30+
31+
public function __construct(EasyBackupService $easyBackupService)
32+
{
33+
$this->easyBackupService = $easyBackupService;
34+
35+
parent::__construct();
36+
}
37+
38+
protected function configure(): void
39+
{
40+
$this
41+
->setName('EasyBackup:backup')
42+
->setDescription('Creates a new backup.')
43+
->setHelp('This command allows you to create a new backup e.g. via cronjob.');
44+
}
45+
46+
protected function execute(InputInterface $input, OutputInterface $output): int
47+
{
48+
$log = $this->easyBackupService->createBackup();
49+
50+
//$output->writeln($result);
51+
$output->writeln($log);
52+
53+
return 0;
54+
55+
// or return this if some error happened during the execution
56+
// (it's equivalent to returning int(1))
57+
// return Command::FAILURE;
58+
59+
// or return this to indicate incorrect command usage; e.g. invalid options
60+
// or missing arguments (it's equivalent to returning int(2))
61+
// return Command::INVALID
62+
}
63+
}

0 commit comments

Comments
 (0)