HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/heifetz/heifetz-app/models/UserLogs.php
<?php

namespace Models;

use Core\DbLib\DbModel;
use Core\Models\CoreHelper;
use Core\Models\OldUser;
use Helpers\Data;
use Traits\ModelGetQuery;

/**
 * @property int $id
 * @property ?int $user_id
 * @property ?string $entity
 * @property ?int $entity_id
 * @property ?string $column
 * @property ?string $value
 * @property string $created_at
 * @property ?string $action
 */
class UserLogs extends DbModel
{

    use ModelGetQuery;

    protected static bool $hasCompanyRelation = true;

    const ACTION_CREATE = 'CREATE';
    const ACTION_UPDATE = 'UPDATE';
    const ACTION_DELETE = 'DELETE';
    const ACTION_SOFT_DELETE = 'SOFT_DELETE';
    const ACTION_REPLACE = 'REPLACE';

    public static array $actions = [
        self::ACTION_CREATE => 'Создание',
        self::ACTION_UPDATE => 'Обновление',
        self::ACTION_DELETE => 'Удаление',
        self::ACTION_SOFT_DELETE => 'Безопасное удаление',
        self::ACTION_REPLACE => 'Замена',
    ];

    static string $tableName = 'user_logs';

    public static function log($entity, $entityId, $column, $value, $action = null)
    {
        return;

        $entityId = is_array($entityId) ? Data::jsonEncode($entityId) : $entityId;
        $value = is_array($value) ? Data::jsonEncode($value) : $value;
        self::create(
            [
                'user_id' => OldUser::getRealId(),
                'entity' => $entity,
                'entity_id' => $entityId,
                'column' => $column,
                'value' => $value,
                'action' => $action,
            ], false
        );
    }

    public static function logCreate($entity, $entityId, $data)
    {
        self::log($entity, $entityId, 'record', $data, self::ACTION_CREATE);
    }

    public static function logUpdate($entity, $entityId, $column, $value)
    {
        self::log($entity, $entityId, $column, $value, self::ACTION_UPDATE);
    }

    public static function logDelete($entity, $entityId)
    {
        self::log($entity, $entityId, 'record', '', self::ACTION_DELETE);
    }

    public static function logSoftDelete($entity, $entityId)
    {
        self::log($entity, $entityId, 'record', '', self::ACTION_SOFT_DELETE);
    }

    /**
     * @param $entity
     * @param $entityId
     * @param array|object $array
     * @param null $action
     *
     * @depricated Use UserLogs::log()
     */
    public static function logRow($entity, $entityId, $array, $action = null)
    {
        self::log($entity, $entityId, 'record', json_encode($array), $action);
    }

}