Clean Command Added

master
Muhep Atasoy 2019-12-10 22:23:36 +03:00
parent 5cb8e16191
commit e4aad3329f
3 changed files with 48 additions and 3 deletions

View File

@ -15,7 +15,7 @@ class DataBackupCommand extends Command
*
* @var string
*/
protected $signature = 'backup:data {--dataFolder=} {--backupFolder=}';
protected $signature = 'backup:data {--dataFolder=} {--backupFolder=} {--clean}';
/**
* The description of the command.
@ -34,11 +34,16 @@ class DataBackupCommand extends Command
{
$backupFolder = $this->option('backupFolder');
$dataFolder = $this->option('dataFolder');
$bm = new BackupManager();
$clean = $this->option('clean');
$this->line("<fg=blue>|-> Backing up data folder...</>");
$bm = new BackupManager();
$builder = new DataBuilder();
$builder->setDataFolder($dataFolder)->setBackupFolder($backupFolder);
$builder->setDataFolder($dataFolder)
->setBackupFolder($backupFolder)
->setClean($clean);
$bm->setBuilder($builder)->execute();
if ($bm->getShell()->getReturnValue() == 0) {
$this->line("<fg=green> |-> Data folder successfully backed up.</>");
} else {

View File

@ -0,0 +1,8 @@
<?php
namespace App\Exceptions;
class CleanException extends \Exception
{
}

View File

@ -4,12 +4,36 @@ namespace App\Utils;
use \AdamBrett\ShellWrapper\Command\Builder as CommandBuilder;
use App\Exceptions\BackupFolderNotFoundException;
use App\Exceptions\CleanException;
use Throwable;
abstract class Builder
{
private $backupFolder;
private $containerName;
private $clean;
/**
* Builder constructor.
*/
public function __construct()
{
$this->clean = false;
}
public function __destruct()
{
try {
if ($this->clean) {
$files = glob($this->backupFolder . '/*');
foreach($files as $file){
is_file($file) ? unlink($file) : null;
}
}
} catch (\Exception $exception) {
throw new CleanException($exception->getMessage());
}
}
/**
* @param $backupFolder
@ -49,6 +73,14 @@ abstract class Builder
return $this->containerName;
}
/**
* @param bool $clean
*/
public function setClean(bool $clean): void
{
$this->clean = $clean;
}
/**
* @return CommandBuilder
*/