1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Jobs/Util/SystemLogger.php

108 lines
2.6 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Jobs\Util;
use App\Libraries\MultiDB;
use App\Models\Client;
use App\Models\Company;
use App\Models\SystemLog;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class SystemLogger implements ShouldQueue
{
2024-01-14 05:05:00 +01:00
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
protected $log;
protected $category_id;
protected $event_id;
protected $type_id;
protected $client;
protected $company;
public function __construct($log, $category_id, $event_id, $type_id, ?Client $client, Company $company)
{
$this->log = $log;
$this->category_id = $category_id;
$this->event_id = $event_id;
$this->type_id = $type_id;
$this->client = $client;
2021-05-19 04:47:24 +02:00
$this->company = $company;
}
2024-01-14 05:05:00 +01:00
public function handle(): void
{
if (! $this->company) {
nlog('SystemLogger:: No company');
2021-05-19 04:47:24 +02:00
return;
2021-11-10 19:54:59 +01:00
}
MultiDB::setDb($this->company->db);
$client_id = $this->client ? $this->client->id : null;
2021-08-27 13:27:13 +02:00
if (! $this->client && ! $this->company->owner()) {
nlog('SystemLogger:: could not find client and/or company owner');
2021-08-27 13:27:13 +02:00
return;
2021-11-10 19:54:59 +01:00
}
$user_id = $this->client ? $this->client->user_id : $this->company->owner()->id;
2021-05-19 04:47:24 +02:00
$sl = [
'client_id' => $client_id,
'company_id' => $this->company->id,
'user_id' => $user_id,
'log' => $this->log,
'category_id' => $this->category_id,
'event_id' => $this->event_id,
'type_id' => $this->type_id,
];
if (! $this->log) {
nlog('SystemLogger:: no log to store');
2022-11-01 07:10:05 +01:00
$this->category_id = null;
$this->event_id = null;
$this->type_id = null;
$this->client = null;
$this->company = null;
2021-05-03 12:50:08 +02:00
return;
2021-11-10 19:54:59 +01:00
}
2021-05-03 12:50:08 +02:00
SystemLog::create($sl);
2022-11-01 07:10:05 +01:00
$this->log = null;
$this->category_id = null;
$this->event_id = null;
$this->type_id = null;
$this->client = null;
$this->company = null;
}
2021-11-10 19:54:59 +01:00
public function failed($e)
{
2023-02-02 02:14:42 +01:00
config(['queue.failed.driver' => null]);
2021-11-10 19:54:59 +01:00
}
}