mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 23:42:34 +00:00
Merge (#127)
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
@ -15,7 +16,6 @@
|
||||
* @property string $disk
|
||||
* @property Server $server
|
||||
* @property ?Site $site
|
||||
* @property string $content
|
||||
*/
|
||||
class ServerLog extends AbstractModel
|
||||
{
|
||||
@ -39,8 +39,12 @@ public static function boot(): void
|
||||
parent::boot();
|
||||
|
||||
static::deleting(function (ServerLog $log) {
|
||||
if (Storage::disk($log->disk)->exists($log->name)) {
|
||||
Storage::disk($log->disk)->delete($log->name);
|
||||
try {
|
||||
if (Storage::disk($log->disk)->exists($log->name)) {
|
||||
Storage::disk($log->disk)->delete($log->name);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e->getMessage(), ['exception' => $e]);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -72,7 +76,7 @@ public function write($buf): void
|
||||
}
|
||||
}
|
||||
|
||||
public function getContentAttribute(): ?string
|
||||
public function getContent(): ?string
|
||||
{
|
||||
if (Storage::disk($this->disk)->exists($this->name)) {
|
||||
return Storage::disk($this->disk)->get($this->name);
|
||||
@ -80,4 +84,17 @@ public function getContentAttribute(): ?string
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function log(Server $server, string $type, string $content, ?Site $site = null): void
|
||||
{
|
||||
$log = new static([
|
||||
'server_id' => $server->id,
|
||||
'site_id' => $site?->id,
|
||||
'name' => $server->id.'-'.strtotime('now').'-'.$type.'.log',
|
||||
'type' => $type,
|
||||
'disk' => config('core.logs_disk'),
|
||||
]);
|
||||
$log->save();
|
||||
$log->write($content);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user