1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Models/SystemLog.php

311 lines
9.1 KiB
PHP
Raw Normal View History

2019-10-01 03:56:48 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2019-10-01 03:56:48 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2019-10-01 03:56:48 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-10-01 03:56:48 +02:00
*/
namespace App\Models;
2020-08-24 12:28:47 +02:00
use App\Utils\Traits\MakesHash;
2019-10-01 03:56:48 +02:00
use Illuminate\Database\Eloquent\Model;
2020-08-24 12:28:47 +02:00
use Illuminate\Database\Eloquent\SoftDeletes;
2019-10-01 03:56:48 +02:00
2023-03-08 08:33:42 +01:00
/**
* App\Models\SystemLog
*
* @property int $id
* @property int $company_id
* @property int|null $user_id
* @property int|null $client_id
* @property int|null $category_id
* @property int|null $event_id
* @property int|null $type_id
* @property array $log
* @property int|null $created_at
* @property int|null $updated_at
* @property int|null $deleted_at
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog company()
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog filter(\App\Filters\QueryFilters $filters)
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog query()
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog whereCategoryId($value)
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog whereClientId($value)
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog whereCompanyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog whereEventId($value)
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog whereLog($value)
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog whereTypeId($value)
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog whereUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog withTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|SystemLog withoutTrashed()
* @mixin \Eloquent
*/
2019-10-01 03:56:48 +02:00
class SystemLog extends Model
{
2020-08-24 12:28:47 +02:00
use Filterable;
use SoftDeletes;
use MakesHash;
2020-08-24 12:28:47 +02:00
protected $casts = [
'updated_at' => 'timestamp',
'created_at' => 'timestamp',
'deleted_at' => 'timestamp',
'log' => 'array',
2020-08-24 12:28:47 +02:00
];
protected $dateFormat = 'Y-m-d H:i:s.u';
2019-10-01 03:56:48 +02:00
/* Category IDs */
2024-01-14 05:05:00 +01:00
public const CATEGORY_GATEWAY_RESPONSE = 1;
2024-01-14 05:05:00 +01:00
public const CATEGORY_MAIL = 2;
2024-01-14 05:05:00 +01:00
public const CATEGORY_WEBHOOK = 3;
2024-01-14 05:05:00 +01:00
public const CATEGORY_PDF = 4;
2024-01-14 05:05:00 +01:00
public const CATEGORY_SECURITY = 5;
2019-10-01 03:56:48 +02:00
2024-01-14 05:05:00 +01:00
public const CATEGORY_LOG = 6;
2022-10-12 02:27:14 +02:00
2019-10-01 03:56:48 +02:00
/* Event IDs*/
2024-01-14 05:05:00 +01:00
public const EVENT_PAYMENT_RECONCILIATION_FAILURE = 10;
2024-01-14 05:05:00 +01:00
public const EVENT_PAYMENT_RECONCILIATION_SUCCESS = 11;
2024-01-14 05:05:00 +01:00
public const EVENT_GATEWAY_SUCCESS = 21;
2024-01-14 05:05:00 +01:00
public const EVENT_GATEWAY_FAILURE = 22;
2024-01-14 05:05:00 +01:00
public const EVENT_GATEWAY_ERROR = 23;
2024-01-14 05:05:00 +01:00
public const EVENT_MAIL_SEND = 30;
2024-01-14 05:05:00 +01:00
public const EVENT_MAIL_RETRY_QUEUE = 31; //we use this to queue emails that are spooled and not sent due to the email queue quota being exceeded.
2024-01-14 05:05:00 +01:00
public const EVENT_MAIL_BOUNCED = 32;
2024-01-14 05:05:00 +01:00
public const EVENT_MAIL_SPAM_COMPLAINT = 33;
2024-01-14 05:05:00 +01:00
public const EVENT_MAIL_DELIVERY = 34;
2024-01-14 05:05:00 +01:00
public const EVENT_MAIL_OPENED = 35;
2024-01-14 05:05:00 +01:00
public const EVENT_WEBHOOK_RESPONSE = 40;
2024-01-14 05:05:00 +01:00
public const EVENT_WEBHOOK_SUCCESS = 41;
2024-01-14 05:05:00 +01:00
public const EVENT_WEBHOOK_FAILURE = 42;
2021-01-13 00:25:33 +01:00
2024-01-14 05:05:00 +01:00
public const EVENT_PDF_RESPONSE = 50;
2024-01-14 05:05:00 +01:00
public const EVENT_AUTHENTICATION_FAILURE = 60;
public const EVENT_USER = 61;
2021-01-14 04:44:52 +01:00
/*Type IDs*/
2024-01-14 05:05:00 +01:00
public const TYPE_PAYPAL = 300;
public const TYPE_STRIPE = 301;
2024-01-14 05:05:00 +01:00
public const TYPE_LEDGER = 302;
2024-01-14 05:05:00 +01:00
public const TYPE_FAILURE = 303;
2024-01-14 05:05:00 +01:00
public const TYPE_CHECKOUT = 304;
2024-01-14 05:05:00 +01:00
public const TYPE_AUTHORIZE = 305;
2024-01-14 05:05:00 +01:00
public const TYPE_CUSTOM = 306;
2024-01-14 05:05:00 +01:00
public const TYPE_BRAINTREE = 307;
2024-01-14 05:05:00 +01:00
public const TYPE_WEPAY = 309;
2024-01-14 05:05:00 +01:00
public const TYPE_PAYFAST = 310;
2024-01-14 05:05:00 +01:00
public const TYPE_PAYTRACE = 311;
2024-01-14 05:05:00 +01:00
public const TYPE_MOLLIE = 312;
2024-01-14 05:05:00 +01:00
public const TYPE_EWAY = 313;
2024-01-14 05:05:00 +01:00
public const TYPE_FORTE = 314;
2024-01-14 05:05:00 +01:00
public const TYPE_SQUARE = 320;
2024-01-14 05:05:00 +01:00
public const TYPE_GOCARDLESS = 321;
2024-01-14 05:05:00 +01:00
public const TYPE_RAZORPAY = 322;
2021-04-28 12:54:27 +02:00
2024-01-14 05:05:00 +01:00
public const TYPE_PAYPAL_PPCP = 323;
2023-10-16 03:05:19 +02:00
2024-01-14 05:05:00 +01:00
public const TYPE_QUOTA_EXCEEDED = 400;
2024-01-14 05:05:00 +01:00
public const TYPE_UPSTREAM_FAILURE = 401;
2024-01-14 05:05:00 +01:00
public const TYPE_WEBHOOK_RESPONSE = 500;
2021-01-14 04:44:52 +01:00
2024-01-14 05:05:00 +01:00
public const TYPE_PDF_FAILURE = 600;
2024-01-14 05:05:00 +01:00
public const TYPE_PDF_SUCCESS = 601;
2021-01-13 00:12:01 +01:00
2024-01-14 05:05:00 +01:00
public const TYPE_MODIFIED = 701;
2024-01-14 05:05:00 +01:00
public const TYPE_DELETED = 702;
2021-01-14 04:44:52 +01:00
2024-01-14 05:05:00 +01:00
public const TYPE_LOGIN_SUCCESS = 800;
2024-01-14 05:05:00 +01:00
public const TYPE_LOGIN_FAILURE = 801;
2024-01-14 05:05:00 +01:00
public const TYPE_GENERIC = 900;
2022-10-12 02:27:14 +02:00
protected $fillable = [
'client_id',
'company_id',
'user_id',
'log',
'category_id',
'event_id',
'type_id',
];
2020-11-25 15:19:52 +01:00
public function resolveRouteBinding($value, $field = null)
2020-08-24 11:51:19 +02:00
{
if (is_numeric($value)) {
throw new \Illuminate\Database\Eloquent\ModelNotFoundException("Record with value {$value} not found");
2020-08-24 11:51:19 +02:00
}
return $this
->where('id', $this->decodePrimaryKey($value))
->company()
->firstOrFail();
2020-08-24 11:51:19 +02:00
}
2020-08-24 12:28:47 +02:00
/*
2020-08-24 12:28:47 +02:00
V2 type of scope
*/
public function scopeCompany($query)
{
/** @var \App\Models\User $user */
$user = auth()->user();
$query->where('company_id', $user->companyId());
2020-08-24 12:28:47 +02:00
return $query;
}
2021-08-08 14:20:32 +02:00
public function getCategoryName()
{
switch ($this->category_id) {
case self::CATEGORY_GATEWAY_RESPONSE:
return 'Gateway';
2021-08-08 14:20:32 +02:00
case self::CATEGORY_MAIL:
return 'Mail';
2021-08-08 14:20:32 +02:00
case self::CATEGORY_WEBHOOK:
return 'Webhook';
2021-08-08 14:20:32 +02:00
case self::CATEGORY_PDF:
return 'PDF';
2021-08-08 14:20:32 +02:00
case self::CATEGORY_SECURITY:
return 'Security';
2021-08-08 14:20:32 +02:00
default:
return 'undefined';
}
}
public function getEventName()
{
switch ($this->event_id) {
case self::EVENT_PAYMENT_RECONCILIATION_FAILURE:
return 'Payment reco failure';
2021-08-08 14:20:32 +02:00
case self::EVENT_PAYMENT_RECONCILIATION_SUCCESS:
return 'Payment reco success';
2021-08-08 14:20:32 +02:00
case self::EVENT_GATEWAY_SUCCESS:
return 'Success';
2021-08-08 14:20:32 +02:00
case self::EVENT_GATEWAY_FAILURE:
return 'Failure';
2021-08-08 14:20:32 +02:00
case self::EVENT_GATEWAY_ERROR:
return 'Error';
2021-08-08 14:20:32 +02:00
case self::EVENT_MAIL_SEND:
return 'Send';
2021-08-08 14:20:32 +02:00
case self::EVENT_MAIL_RETRY_QUEUE:
return 'Retry';
2021-08-08 14:20:32 +02:00
case self::EVENT_MAIL_BOUNCED:
return 'Bounced';
2021-08-08 14:20:32 +02:00
case self::EVENT_MAIL_SPAM_COMPLAINT:
return 'Spam';
2021-08-08 14:20:32 +02:00
case self::EVENT_MAIL_DELIVERY:
return 'Delivery';
2021-08-08 14:20:32 +02:00
case self::EVENT_WEBHOOK_RESPONSE:
return 'Webhook Response';
2021-08-08 14:20:32 +02:00
case self::EVENT_PDF_RESPONSE:
return 'Pdf Response';
2021-08-08 14:20:32 +02:00
case self::EVENT_AUTHENTICATION_FAILURE:
return 'Auth Failure';
2021-08-08 14:20:32 +02:00
case self::EVENT_USER:
return 'User';
2021-08-08 14:20:32 +02:00
default:
return 'undefined';
}
}
public function getTypeName()
{
switch ($this->type_id) {
case self::TYPE_QUOTA_EXCEEDED:
return 'Quota Exceeded';
2021-08-08 14:20:32 +02:00
case self::TYPE_UPSTREAM_FAILURE:
return 'Upstream Failure';
2021-08-08 14:20:32 +02:00
case self::TYPE_WEBHOOK_RESPONSE:
return 'Webhook';
2021-08-08 14:20:32 +02:00
case self::TYPE_PDF_FAILURE:
return 'Failure';
2021-08-08 14:20:32 +02:00
case self::TYPE_PDF_SUCCESS:
return 'Success';
2021-08-08 14:20:32 +02:00
case self::TYPE_MODIFIED:
return 'Modified';
2021-08-08 14:20:32 +02:00
case self::TYPE_DELETED:
return 'Deleted';
2021-08-08 14:20:32 +02:00
case self::TYPE_LOGIN_SUCCESS:
return 'Login Success';
2021-08-08 14:20:32 +02:00
case self::TYPE_LOGIN_FAILURE:
return 'Login Failure';
2021-08-08 14:20:32 +02:00
case self::TYPE_PAYPAL:
return 'PayPal';
2021-08-08 14:20:32 +02:00
case self::TYPE_STRIPE:
return 'Stripe';
2021-08-08 14:20:32 +02:00
case self::TYPE_LEDGER:
return 'Ledger';
2021-08-08 14:20:32 +02:00
case self::TYPE_FAILURE:
return 'Failure';
2021-08-08 14:20:32 +02:00
case self::TYPE_CHECKOUT:
return 'Checkout';
2021-08-08 14:20:32 +02:00
case self::TYPE_AUTHORIZE:
return 'Auth.net';
2021-08-08 14:20:32 +02:00
case self::TYPE_CUSTOM:
return 'Custom';
2021-08-08 14:20:32 +02:00
case self::TYPE_BRAINTREE:
return 'Braintree';
2021-08-08 14:20:32 +02:00
case self::TYPE_WEPAY:
return 'WePay';
2021-08-08 14:20:32 +02:00
case self::TYPE_PAYFAST:
return "Payfast";
2022-08-04 16:02:15 +02:00
case self::TYPE_FORTE:
return "Forte";
2021-08-08 14:20:32 +02:00
default:
return 'undefined';
}
}
2020-11-25 15:19:52 +01:00
}