1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Models/Backup.php
2022-02-19 16:11:30 +11:00

51 lines
1.2 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Models;
use App\Models\Client;
use Illuminate\Support\Facades\Storage;
class Backup extends BaseModel
{
public function getEntityType()
{
return self::class;
}
public function activity()
{
return $this->belongsTo(Activity::class);
}
public function storeRemotely(?string $html, Client $client)
{
if(!$html || strlen($html) == 0)
return;
$path = $client->backup_path() . "/";
$filename = now()->format('Y_m_d'). "_" . md5(time()) . ".html";
$file_path = $path . $filename;
Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
Storage::disk(config('filesystems.default'))->put($file_path, $html);
if(Storage::disk(config('filesystems.default'))->exists($file_path)){
$this->html_backup = '';
$this->filename = $file_path;
$this->save();
}
}
}