mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-05-29 14:44:55 +00:00
Merge pull request #508 from alexdev01012020/email-backup
Overrite the email notification for backup
This commit is contained in:
@@ -76,7 +76,10 @@ class BackupsController extends ApiController
|
||||
{
|
||||
$this->authorize('manage backups');
|
||||
|
||||
dispatch(new CreateBackupJob($request->all()))->onQueue(config('backup.queue.name'));
|
||||
$data = $request->all();
|
||||
$data['company'] = $request->header('company');
|
||||
|
||||
dispatch(new CreateBackupJob($data))->onQueue(config('backup.queue.name'));
|
||||
|
||||
return $this->respondSuccess();
|
||||
}
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\FileDisk;
|
||||
use App\Space\BackupConfigurationFactory;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Spatie\Backup\Config\Config;
|
||||
use Spatie\Backup\Tasks\Backup\BackupJobFactory;
|
||||
|
||||
class CreateBackupJob implements ShouldQueue
|
||||
@@ -25,7 +24,7 @@ class CreateBackupJob implements ShouldQueue
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($data = '')
|
||||
public function __construct($data = [])
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
@@ -35,14 +34,7 @@ class CreateBackupJob implements ShouldQueue
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$fileDisk = FileDisk::find($this->data['file_disk_id']);
|
||||
$fileDisk->setConfig();
|
||||
|
||||
$prefix = env('DYNAMIC_DISK_PREFIX', 'temp_');
|
||||
|
||||
config(['backup.backup.destination.disks' => [$prefix.$fileDisk->driver]]);
|
||||
|
||||
$config = Config::fromArray(config('backup'));
|
||||
$config = BackupConfigurationFactory::make($this->data);
|
||||
$backupJob = BackupJobFactory::createFromConfig($config);
|
||||
if (! defined('SIGINT')) {
|
||||
$backupJob->disableSignals();
|
||||
|
||||
40
app/Space/BackupConfigurationFactory.php
Normal file
40
app/Space/BackupConfigurationFactory.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Space;
|
||||
|
||||
use App\Models\CompanySetting;
|
||||
use App\Models\FileDisk;
|
||||
use Exception;
|
||||
use Spatie\Backup\Config\Config;
|
||||
|
||||
class BackupConfigurationFactory
|
||||
{
|
||||
public static function make($data = []): Config
|
||||
{
|
||||
if (blank($data['company'] ?? null)) {
|
||||
throw new Exception('The Company ID is missig');
|
||||
}
|
||||
|
||||
if (blank($data['file_disk_id'] ?? null)) {
|
||||
throw new Exception('No file disk selected');
|
||||
}
|
||||
|
||||
$fileDisk = FileDisk::find($data['file_disk_id']);
|
||||
|
||||
$fileDisk->setConfig();
|
||||
|
||||
$prefix = env('DYNAMIC_DISK_PREFIX', 'temp_');
|
||||
|
||||
config(['backup.backup.destination.disks' => [$prefix.$fileDisk->driver]]);
|
||||
|
||||
$companyNotificationEmail = CompanySetting::getSetting('notification_email', $data['company']);
|
||||
|
||||
if ($companyNotificationEmail) {
|
||||
config(['backup.notifications.mail.to' => $companyNotificationEmail]);
|
||||
}
|
||||
|
||||
$config = Config::fromArray(config('backup'));
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user