2023-05-24 12:26:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-11-23 20:02:30 +00:00
|
|
|
use Illuminate\Support\Carbon;
|
2023-05-24 12:26:50 +00:00
|
|
|
|
|
|
|
class ApplicationDeploymentQueue extends Model
|
|
|
|
{
|
2023-06-30 13:57:40 +00:00
|
|
|
protected $guarded = [];
|
2023-11-23 20:02:30 +00:00
|
|
|
|
2023-11-27 10:54:55 +00:00
|
|
|
public function getOutput($name)
|
|
|
|
{
|
2023-11-23 20:02:30 +00:00
|
|
|
if (!$this->logs) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return collect(json_decode($this->logs))->where('name', $name)->first()?->output ?? null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addLogEntry(string $message, string $type = 'stdout', bool $hidden = false)
|
|
|
|
{
|
|
|
|
if ($type === 'error') {
|
|
|
|
$type = 'stderr';
|
|
|
|
}
|
2023-11-27 10:54:55 +00:00
|
|
|
$message = str($message)->trim();
|
|
|
|
if ($message->startsWith('╔')) {
|
|
|
|
$message = "\n" . $message;
|
|
|
|
}
|
2023-11-23 20:02:30 +00:00
|
|
|
$newLogEntry = [
|
|
|
|
'command' => null,
|
2023-11-27 10:54:55 +00:00
|
|
|
'output' => remove_iip($message),
|
2023-11-23 20:02:30 +00:00
|
|
|
'type' => $type,
|
|
|
|
'timestamp' => Carbon::now('UTC'),
|
|
|
|
'hidden' => $hidden,
|
|
|
|
'batch' => 1,
|
|
|
|
];
|
|
|
|
if ($this->logs) {
|
|
|
|
$previousLogs = json_decode($this->logs, associative: true, flags: JSON_THROW_ON_ERROR);
|
|
|
|
$newLogEntry['order'] = count($previousLogs) + 1;
|
|
|
|
$previousLogs[] = $newLogEntry;
|
|
|
|
$this->update([
|
|
|
|
'logs' => json_encode($previousLogs, flags: JSON_THROW_ON_ERROR),
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$this->update([
|
|
|
|
'logs' => json_encode([$newLogEntry], flags: JSON_THROW_ON_ERROR),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
2023-05-24 12:26:50 +00:00
|
|
|
}
|