46 lines
1.7 KiB
PHP
46 lines
1.7 KiB
PHP
<?php
|
||
/**
|
||
* @package Bicycle
|
||
* @author Egor Isaev
|
||
* @description TransactionHistoryRepository.php
|
||
* @copyright (c) 15/08/2026
|
||
*/
|
||
|
||
namespace App\Repositories;
|
||
|
||
use System\Classes\Repository;
|
||
|
||
/**
|
||
* Репозиторий таблицы transaction_history — лог правок/удалений операций (см.
|
||
* бюджет_текущий_план.md → Transactions → «Лог правок/удалений»). Только запись — само чтение
|
||
* лога/механизм отката не спроектированы, здесь только то, что нужно, чтобы лог начал
|
||
* наполняться вместе с CRUD транзакций (App\Controller\TransactionsController).
|
||
*/
|
||
class TransactionHistoryRepository extends Repository
|
||
{
|
||
/**
|
||
* @param string|null $connection Имя подключения (Database::instance($connection)); null — по умолчанию
|
||
*/
|
||
public function __construct(?string $connection = null)
|
||
{
|
||
parent::__construct('transaction_history', connection: $connection);
|
||
}
|
||
|
||
/**
|
||
* @param int $transaction_id
|
||
* @param int $user_id
|
||
* @param string $action create|edit|delete
|
||
* @param array|null $snapshot Полный слепок строки transactions после действия; null для delete
|
||
* @return void
|
||
*/
|
||
public function log(int $transaction_id, int $user_id, string $action, ?array $snapshot): void
|
||
{
|
||
$this->create([
|
||
'transaction_id' => $transaction_id,
|
||
'user_id' => $user_id,
|
||
'action' => $action,
|
||
'snapshot' => $snapshot,
|
||
]);
|
||
}
|
||
}
|