80 lines
2.0 KiB
PHP
80 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use App\Utils\BackupManager;
|
|
use App\Utils\Builders\DataBuilder;
|
|
use App\Utils\Builders\UploadBuilder;
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use LaravelZero\Framework\Commands\Command;
|
|
|
|
class UploadCommand extends Command
|
|
{
|
|
/**
|
|
* The signature of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'backup:upload
|
|
{name : Package name.}
|
|
{--export : Folder for created packages.}
|
|
{--target= : Target folder for Mega.nz}';
|
|
|
|
/**
|
|
* The description of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Upload backup file to Mega.nz';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
* @throws \Throwable
|
|
*/
|
|
public function handle()
|
|
{
|
|
$exportFolder = $this->option('export');
|
|
$targetFolder = $this->option('target');
|
|
$name = $this->argument('name');
|
|
|
|
if (!$targetFolder) {
|
|
$targetFolder = env('TARGET_FOLDER');
|
|
}
|
|
|
|
if (!$exportFolder) {
|
|
$exportFolder = env('EXPORT_FOLDER');
|
|
}
|
|
|
|
$this->line("<fg=blue>|-> {$name} is uploading...</>");
|
|
|
|
$uploadBuilder = new UploadBuilder();
|
|
$uploadBuilder->setExportFolder($exportFolder)
|
|
->setTargetFolder($targetFolder)
|
|
->setPackageName($name);
|
|
|
|
$backupManager = new BackupManager();
|
|
$backupManager->setBuilder($uploadBuilder)
|
|
->execute();
|
|
|
|
if ($backupManager->getShell()->getReturnValue() == 0) {
|
|
$this->line("<fg=green> |-> Upload successful.</>");
|
|
} else {
|
|
$this->line("<fg=red> |-> Upload failed.</>");
|
|
}
|
|
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();
|
|
}
|
|
}
|