mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Move stale invoice cleanup to scheduler
This commit is contained in:
parent
c3945a1bac
commit
3bb04b4edf
@ -23,6 +23,7 @@ use App\Jobs\Ninja\QueueSize;
|
||||
use App\Jobs\Ninja\SystemMaintenance;
|
||||
use App\Jobs\Ninja\TaskScheduler;
|
||||
use App\Jobs\Quote\QuoteCheckExpired;
|
||||
use App\Jobs\Subscription\CleanStaleInvoiceOrder;
|
||||
use App\Jobs\Util\DiskCleanup;
|
||||
use App\Jobs\Util\ReminderJob;
|
||||
use App\Jobs\Util\SchedulerCheck;
|
||||
@ -68,6 +69,9 @@ class Kernel extends ConsoleKernel
|
||||
/* Sends recurring invoices*/
|
||||
$schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping()->name('recurring-invoice-job')->onOneServer();
|
||||
|
||||
/* Stale Invoice Cleanup*/
|
||||
$schedule->job(new CleanStaleInvoiceOrder)->hourly()->withoutOverlapping()->name('stale-invoice-job')->onOneServer();
|
||||
|
||||
/* Sends recurring invoices*/
|
||||
$schedule->job(new RecurringExpensesCron)->dailyAt('00:10')->withoutOverlapping()->name('recurring-expense-job')->onOneServer();
|
||||
|
||||
|
@ -534,8 +534,6 @@ class BillingPortalPurchasev2 extends Component
|
||||
->adjustInventory()
|
||||
->save();
|
||||
|
||||
CleanStaleInvoiceOrder::dispatch($this->invoice->id, $this->company->db)->delay(600);
|
||||
|
||||
Cache::put($this->hash, [
|
||||
'subscription_id' => $this->subscription->id,
|
||||
'email' => $this->email ?? $this->contact->email,
|
||||
|
@ -30,7 +30,7 @@ class CleanStaleInvoiceOrder implements ShouldQueue
|
||||
* @param int invoice_id
|
||||
* @param string $db
|
||||
*/
|
||||
public function __construct(private int $invoice_id, private string $db){}
|
||||
public function __construct(){}
|
||||
|
||||
/**
|
||||
* @param InvoiceRepository $repo
|
||||
@ -38,13 +38,38 @@ class CleanStaleInvoiceOrder implements ShouldQueue
|
||||
*/
|
||||
public function handle(InvoiceRepository $repo) : void
|
||||
{
|
||||
MultiDB::setDb($this->db);
|
||||
|
||||
$invoice = Invoice::withTrashed()->find($this->invoice_id);
|
||||
if (! config('ninja.db.multi_db_enabled')) {
|
||||
|
||||
if($invoice->is_proforma){
|
||||
$invoice->is_proforma = false;
|
||||
$repo->delete($invoice);
|
||||
Invoice::query()
|
||||
->withTrashed()
|
||||
->where('is_proforma', 1)
|
||||
->where('created_at', '<', now()->subHour())
|
||||
->cursor()
|
||||
->each(function ($invoice) use ($repo) {
|
||||
$invoice->is_proforma = false;
|
||||
$repo->delete($invoice);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
foreach (MultiDB::$dbs as $db)
|
||||
{
|
||||
|
||||
MultiDB::setDB($db);
|
||||
|
||||
Invoice::query()
|
||||
->withTrashed()
|
||||
->where('is_proforma', 1)
|
||||
->where('created_at', '<', now()->subHour())
|
||||
->cursor()
|
||||
->each(function ($invoice) use ($repo) {
|
||||
$invoice->is_proforma = false;
|
||||
$repo->delete($invoice);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user