40 lines
1.0 KiB
PHP
40 lines
1.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Lucent\Command;
|
||
|
|
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
use Lucent\Command\Data\CommandLogItem;
|
||
|
|
|
||
|
|
class CommandRepo
|
||
|
|
{
|
||
|
|
public function findBySignature($signature): ?CommandLogItem
|
||
|
|
{
|
||
|
|
|
||
|
|
$row = DB::table("command_logs")->where("signature", $signature)->first();
|
||
|
|
if (empty($row)) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
return CommandLogItem::fromDB($row);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public function upsertCommand(CommandLogItem $commandLogItem): void
|
||
|
|
{
|
||
|
|
$foundCommandLogItem = $this->findBySignature($commandLogItem->signature);
|
||
|
|
if (empty($foundCommandLogItem)) {
|
||
|
|
DB::table("command_logs")->insert(toArray($commandLogItem));
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
DB::table("command_logs")->where("signature", $commandLogItem->signature)->update(toArray($commandLogItem));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function appendToLogs(string $signature, string $line): void
|
||
|
|
{
|
||
|
|
$res = DB::update(
|
||
|
|
'update command_logs set logs = logs || ? where signature = ?',
|
||
|
|
[$line, $signature]
|
||
|
|
);
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|