1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Jobs/Ninja/AdjustEmailQuota.php

70 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 05:20:41 +02:00
* @copyright Copyright (c) 2022. 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\Ninja;
use App\Libraries\MultiDB;
use App\Models\Account;
2021-08-07 12:56:42 +02:00
use App\Utils\Ninja;
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;
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()
{
2021-08-07 12:56:42 +02:00
if(!Ninja::isHosted())
return;
//multiDB environment, need to
foreach (MultiDB::$dbs as $db) {
MultiDB::setDB($db);
$this->adjust();
}
2021-08-07 12:56:42 +02:00
}
public function adjust()
{
2021-08-07 12:56:42 +02:00
Account::query()->cursor()->each(function ($account){
2021-08-11 03:12:03 +02:00
nlog("resetting email quota for {$account->key}");
2021-08-07 12:56:42 +02:00
Cache::forget($account->key);
Cache::forget("throttle_notified:{$account->key}");
});
}
}