78 lines
2.0 KiB
PHP
78 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use App\Utils\BackupManager;
|
|
use App\Utils\Builders\PackageBuilder;
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use LaravelZero\Framework\Commands\Command;
|
|
|
|
class PackCommand extends Command
|
|
{
|
|
/**
|
|
* The signature of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'backup:pack
|
|
{name : Package name.}
|
|
{--folder= : Backup folder.}
|
|
{--export= : Export folder for created package.}';
|
|
|
|
/**
|
|
* The description of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Create backup package';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
* @throws \Throwable
|
|
*/
|
|
public function handle()
|
|
{
|
|
$backupFolder = $this->option('folder');
|
|
$exportFolder = $this->option('export');
|
|
$packageName = $this->argument('name');
|
|
|
|
if (!$backupFolder) {
|
|
$backupFolder = env('BACKUP_FOLDER');
|
|
}
|
|
|
|
if (!$exportFolder) {
|
|
$exportFolder = env('EXPORT_FOLDER');
|
|
}
|
|
|
|
$this->line("<fg=blue>|-> {$packageName} is packing...</>");
|
|
|
|
$packageBuilder = new PackageBuilder();
|
|
$packageBuilder->setBackupFolder($backupFolder)
|
|
->setExportFolder($exportFolder)
|
|
->setPackageName($packageName);
|
|
|
|
$backupManager = new BackupManager();
|
|
$backupManager->setBuilder($packageBuilder)->execute();
|
|
|
|
if ($backupManager->getShell()->getReturnValue() == 0) {
|
|
$this->line("<fg=green> |-> Package created.</>");
|
|
} else {
|
|
$this->line("<fg=red> |-> Failed to create package.</>");
|
|
}
|
|
return;
|
|
}
|
|
|
|
/**
|
|
* Define the command's schedule.
|
|
*
|
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
|
* @return void
|
|
*/
|
|
public function schedule(Schedule $schedule): void
|
|
{
|
|
// $schedule->command(static::class)->everyMinute();
|
|
}
|
|
}
|