Files
lucent-laravel/src/Command/CommandRepo.php
T

40 lines
1.1 KiB
PHP
Raw Normal View History

2024-08-27 17:42:06 +03:00
<?php
namespace Lucent\Command;
use Lucent\Command\Data\CommandLogItem;
2024-09-07 13:22:58 +03:00
use Lucent\Database\Database;
2024-08-27 17:42:06 +03:00
class CommandRepo
{
public function findBySignature($signature): ?CommandLogItem
{
2024-09-07 13:22:58 +03:00
$row = Database::make()->table("command_logs")->where("signature", $signature)->first();
2024-08-27 17:42:06 +03:00
if (empty($row)) {
return null;
}
return CommandLogItem::fromDB($row);
}
public function upsertCommand(CommandLogItem $commandLogItem): void
{
$foundCommandLogItem = $this->findBySignature($commandLogItem->signature);
if (empty($foundCommandLogItem)) {
2024-09-07 13:22:58 +03:00
Database::make()->table("command_logs")->insert(toArray($commandLogItem));
2024-08-27 17:42:06 +03:00
return;
}
2024-09-07 13:22:58 +03:00
Database::make()->table("command_logs")->where("signature", $commandLogItem->signature)->update(toArray($commandLogItem));
2024-08-27 17:42:06 +03:00
}
public function appendToLogs(string $signature, string $line): void
{
2024-09-07 13:22:58 +03:00
Database::make()->update(
2024-08-27 17:42:06 +03:00
'update command_logs set logs = logs || ? where signature = ?',
[$line, $signature]
);
}
}