2020-04-30 13:45:47 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-04-30 13:45:47 +02:00
|
|
|
*
|
|
|
|
* @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)
|
2020-04-30 13:45:47 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-04-30 13:45:47 +02:00
|
|
|
*/
|
|
|
|
|
2020-05-02 02:04:25 +02:00
|
|
|
namespace App\Jobs\Ninja;
|
2020-04-30 13:45:47 +02:00
|
|
|
|
2022-09-08 10:57:32 +02:00
|
|
|
use App\DataMapper\Analytics\EmailCount;
|
2020-04-30 13:45:47 +02:00
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use App\Models\Account;
|
2021-08-07 12:56:42 +02:00
|
|
|
use App\Utils\Ninja;
|
2020-04-30 13:45:47 +02:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2021-08-07 12:56:42 +02:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2022-09-08 10:57:32 +02:00
|
|
|
use Turbo124\Beacon\Facades\LightLogs;
|
2020-04-30 13:45:47 +02:00
|
|
|
|
|
|
|
class AdjustEmailQuota implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! Ninja::isHosted()) {
|
2021-08-07 12:56:42 +02:00
|
|
|
return;
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-08-07 12:56:42 +02:00
|
|
|
|
|
|
|
//multiDB environment, need to
|
|
|
|
foreach (MultiDB::$dbs as $db) {
|
|
|
|
MultiDB::setDB($db);
|
|
|
|
|
2020-04-30 13:45:47 +02:00
|
|
|
$this->adjust();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function adjust()
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
Account::query()->cursor()->each(function ($account) {
|
2021-08-11 03:12:03 +02:00
|
|
|
nlog("resetting email quota for {$account->key}");
|
2022-09-08 10:57:32 +02:00
|
|
|
|
|
|
|
$email_count = Cache::get($account->key);
|
|
|
|
|
2022-10-28 05:37:01 +02:00
|
|
|
if($email_count > 0){
|
|
|
|
|
|
|
|
try{
|
|
|
|
LightLogs::create(new EmailCount($email_count, $account->key))->send();
|
|
|
|
}
|
|
|
|
catch(\Exception $e){
|
|
|
|
nlog($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
2022-09-08 10:57:32 +02:00
|
|
|
|
2021-08-07 12:56:42 +02:00
|
|
|
Cache::forget($account->key);
|
|
|
|
Cache::forget("throttle_notified:{$account->key}");
|
2022-09-08 10:57:32 +02:00
|
|
|
|
2021-08-07 12:56:42 +02:00
|
|
|
});
|
2020-04-30 13:45:47 +02:00
|
|
|
}
|
|
|
|
}
|