PSR12 code standard.
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@ -1,52 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
|
||||
use Twig\Environment;
|
||||
use Twig\Loader\ArrayLoader;
|
||||
|
||||
use DateTime;
|
||||
|
||||
use Ntfy\Server;
|
||||
use Ntfy\Message;
|
||||
use Ntfy\Client;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'backup',
|
||||
description: 'Start backup to assigned buckets.',
|
||||
hidden: false,
|
||||
)]
|
||||
class CommandBackup extends Command
|
||||
{
|
||||
static $defaultName = "backup";
|
||||
static $defaultDescription = "Start backup to assigned buckets";
|
||||
public static $defaultName = "backup";
|
||||
public static $defaultDescription = "Start backup to assigned buckets";
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->addArgument('config', InputArgument::OPTIONAL, 'Configuration file', "config.yml");
|
||||
$this->addArgument(
|
||||
'config',
|
||||
InputArgument::OPTIONAL,
|
||||
'Configuration file',
|
||||
"config.yml"
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->title('Start backup process');
|
||||
|
||||
$sio = new SymfonyStyle($input, $output);
|
||||
$sio->title('Start backup process');
|
||||
|
||||
try {
|
||||
$app = new App($input->getArgument('config'));
|
||||
}
|
||||
catch (\Throwable $e) {
|
||||
$io->error('Unable to parse the YAML string: '. $e->getMessage());
|
||||
} catch (\Throwable $e) {
|
||||
$sio->error('Configuration error:' . $e->getMessage());
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$rclone = new Rclone\Rclone();
|
||||
$rclone->setLogger($app->getLogger()->withName('rclone'));
|
||||
|
||||
@ -57,7 +51,7 @@ class CommandBackup extends Command
|
||||
$twig = new Environment($loader);
|
||||
$twig->addExtension(new Twig\AppExtension());
|
||||
|
||||
foreach ($io->progressIterate($app->getConfig()['backup']) as $conf) {
|
||||
foreach ($sio->progressIterate($app->getConfig()['backup']) as $conf) {
|
||||
$message = new Message();
|
||||
$message->topic($app->getConfig()['notification']['topic']);
|
||||
$message->title($conf['title']);
|
||||
@ -73,7 +67,7 @@ class CommandBackup extends Command
|
||||
$template['destination_size_after'] = $rclone->getSize($conf['destination']);
|
||||
$template['end'] = new DateTime();
|
||||
|
||||
$message->body($twig->render('notify', $template));
|
||||
$message->body($twig->render('notify', $template));
|
||||
} catch (\Throwable $e) {
|
||||
$message->body($e->getMessage());
|
||||
$message->tags(["warning"]);
|
||||
@ -82,7 +76,7 @@ class CommandBackup extends Command
|
||||
$client->send($message);
|
||||
}
|
||||
|
||||
$io->success("Complete");
|
||||
$sio->success("Complete");
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user