2019-04-21 22:24:26 +10:00
|
|
|
<?php
|
2019-05-11 13:32:07 +10:00
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2022-04-27 13:20:41 +10:00
|
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
2021-06-16 16:58:16 +10:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 13:32:07 +10:00
|
|
|
*/
|
2019-04-21 22:24:26 +10:00
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2021-10-20 14:05:46 +11:00
|
|
|
use App\Models\Client;
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
2019-04-21 22:24:26 +10:00
|
|
|
class Backup extends BaseModel
|
|
|
|
|
{
|
2020-05-06 21:49:42 +10:00
|
|
|
public function getEntityType()
|
|
|
|
|
{
|
2020-09-06 19:38:10 +10:00
|
|
|
return self::class;
|
2020-05-06 21:49:42 +10:00
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:59:12 +11:00
|
|
|
public function activity()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Activity::class);
|
|
|
|
|
}
|
2021-10-20 14:05:46 +11:00
|
|
|
|
2022-02-19 16:11:30 +11:00
|
|
|
public function storeRemotely(?string $html, Client $client)
|
2021-10-20 14:05:46 +11:00
|
|
|
{
|
2022-06-21 09:57:17 +00:00
|
|
|
if (! $html || strlen($html) == 0) {
|
2021-10-20 14:05:46 +11:00
|
|
|
return;
|
2022-06-21 09:57:17 +00:00
|
|
|
}
|
2021-10-20 14:05:46 +11:00
|
|
|
|
2022-06-21 09:57:17 +00:00
|
|
|
$path = $client->backup_path().'/';
|
|
|
|
|
$filename = now()->format('Y_m_d').'_'.md5(time()).'.html';
|
|
|
|
|
$file_path = $path.$filename;
|
2021-10-20 14:05:46 +11:00
|
|
|
|
|
|
|
|
Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
|
2022-06-21 09:57:17 +00:00
|
|
|
|
2021-10-20 14:05:46 +11:00
|
|
|
Storage::disk(config('filesystems.default'))->put($file_path, $html);
|
|
|
|
|
|
2022-06-21 09:57:17 +00:00
|
|
|
if (Storage::disk(config('filesystems.default'))->exists($file_path)) {
|
2021-10-20 14:05:46 +11:00
|
|
|
$this->html_backup = '';
|
|
|
|
|
$this->filename = $file_path;
|
|
|
|
|
$this->save();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-20 09:46:21 +10:00
|
|
|
|
|
|
|
|
public function deleteFile()
|
|
|
|
|
{
|
2022-06-21 09:57:17 +00:00
|
|
|
nlog('deleting => '.$this->filename);
|
2022-05-20 09:46:21 +10:00
|
|
|
|
2022-08-04 09:29:30 +10:00
|
|
|
if(!$this->filename)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-06-21 09:57:17 +00:00
|
|
|
try {
|
2022-05-20 09:46:21 +10:00
|
|
|
Storage::disk(config('filesystems.default'))->delete($this->filename);
|
2022-06-21 09:57:17 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
nlog('BACKUPEXCEPTION deleting backup file with error '.$e->getMessage());
|
2022-05-20 09:46:21 +10:00
|
|
|
}
|
|
|
|
|
}
|
2019-12-31 08:59:12 +11:00
|
|
|
}
|