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/jobs/AbstractJob.php
<?php

declare(strict_types=1);

namespace Jobs;

use Core\Models\CoreHelper;
use Helpers\Data;
use Helpers\Validator;
use Models\Job;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

abstract class AbstractJob
{

    protected Logger $logger;

    protected array $data = [];
    private array $errors = [];

    /** Возвращает правила валидации */
    protected static function getRules(): array
    {
        return [];
    }

    /** Возвращает стандартные переводы для полей */
    protected static function getTranslations(): array
    {
        return [];
    }

    public function validate(string $type = Validator::TYPE_UPDATE): array
    {
        if (empty(static::getRules())) {
            return [];
        }

        $translations = empty($translations) ? static::getTranslations() : $translations;

        return (new Validator(static::getRules()))->validate($this->data, $translations, $type);
    }

    public static function make(array $data = []): static
    {
        $job = new static();
        if (!empty($data)) {
            $job->setData($data);
        }

        $errors = $job->validate(Validator::TYPE_CREATE);

        if (!empty($errors)) {
            $job->errors = $errors;
        }

        return $job;
    }

    public function __construct()
    {
        $class = explode("\\", static::class);
        $class = array_pop($class);

        $this->logger = new Logger('jobs');
        $fileName = ROOT . '/logs/' . date('Y-m-d_') . $class;
        $this->logger->pushHandler(new StreamHandler($fileName . '.log'));
        $this->logger->pushHandler(new StreamHandler($fileName . '.err.log', Logger::ERROR));
    }

    public function setData(array $data): static
    {
        $this->data = $data;

        return $this;
    }

    public function create(): void
    {
        $job = new Job();
        $job->name = static::class;
        $job->data = Data::jsonEncode($this->data);
        $job->company_id = CoreHelper::$companyId;
        $job->created_at = date('Y-m-d H:i:s');
        $job->updated_at = date('Y-m-d H:i:s');
        $job->save();
    }

    abstract public function execute(): bool;

    public function getErrors(): array
    {
        return $this->errors;
    }

}