1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/app/Models/Backup.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2019-04-21 14:24:26 +02:00
<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-05-11 05:32:07 +02:00
*/
2019-04-21 14:24:26 +02:00
namespace App\Models;
2021-10-20 05:05:46 +02:00
use App\Models\Client;
use Illuminate\Support\Facades\Storage;
2019-04-21 14:24:26 +02:00
class Backup extends BaseModel
{
public function getEntityType()
{
return self::class;
}
public function activity()
{
return $this->belongsTo(Activity::class);
}
2021-10-20 05:05:46 +02:00
public function storeRemotely(string $html, Client $client)
{
if(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();
}
}
}