commands and logs to the database

This commit is contained in:
2024-08-27 17:42:06 +03:00
parent 74d2fcc4fa
commit ae65ca47f6
16 changed files with 210 additions and 72 deletions
+40
View File
@@ -0,0 +1,40 @@
<?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]
);
}
}