Compare commits

..

2 Commits

Author SHA1 Message Date
Muhep Atasoy b4e809c61b Create .drone.yml
continuous-integration/drone/push Build is passing Details
2019-12-10 22:23:38 +03:00
Muhep Atasoy e4aad3329f Clean Command Added 2019-12-10 22:23:36 +03:00
4 changed files with 64 additions and 3 deletions

16
.drone.yml Normal file
View File

@ -0,0 +1,16 @@
kind: pipeline
name: default
type: docker
steps:
- name: composer
pull: if-not-exists
image: composer
commands:
- composer install --prefer-dist
- name: test
image: lorisleiva/laravel-docker
commands:
- ./vendor/bin/phpunit

View File

@ -15,7 +15,7 @@ class DataBackupCommand extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'backup:data {--dataFolder=} {--backupFolder=}'; protected $signature = 'backup:data {--dataFolder=} {--backupFolder=} {--clean}';
/** /**
* The description of the command. * The description of the command.
@ -34,11 +34,16 @@ class DataBackupCommand extends Command
{ {
$backupFolder = $this->option('backupFolder'); $backupFolder = $this->option('backupFolder');
$dataFolder = $this->option('dataFolder'); $dataFolder = $this->option('dataFolder');
$bm = new BackupManager(); $clean = $this->option('clean');
$this->line("<fg=blue>|-> Backing up data folder...</>"); $this->line("<fg=blue>|-> Backing up data folder...</>");
$bm = new BackupManager();
$builder = new DataBuilder(); $builder = new DataBuilder();
$builder->setDataFolder($dataFolder)->setBackupFolder($backupFolder); $builder->setDataFolder($dataFolder)
->setBackupFolder($backupFolder)
->setClean($clean);
$bm->setBuilder($builder)->execute(); $bm->setBuilder($builder)->execute();
if ($bm->getShell()->getReturnValue() == 0) { if ($bm->getShell()->getReturnValue() == 0) {
$this->line("<fg=green> |-> Data folder successfully backed up.</>"); $this->line("<fg=green> |-> Data folder successfully backed up.</>");
} else { } 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 \AdamBrett\ShellWrapper\Command\Builder as CommandBuilder;
use App\Exceptions\BackupFolderNotFoundException; use App\Exceptions\BackupFolderNotFoundException;
use App\Exceptions\CleanException;
use Throwable; use Throwable;
abstract class Builder abstract class Builder
{ {
private $backupFolder; private $backupFolder;
private $containerName; 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 * @param $backupFolder
@ -49,6 +73,14 @@ abstract class Builder
return $this->containerName; return $this->containerName;
} }
/**
* @param bool $clean
*/
public function setClean(bool $clean): void
{
$this->clean = $clean;
}
/** /**
* @return CommandBuilder * @return CommandBuilder
*/ */