mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-05 03:34:36 -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\SystemMaintenance;
|
||||||
use App\Jobs\Ninja\TaskScheduler;
|
use App\Jobs\Ninja\TaskScheduler;
|
||||||
use App\Jobs\Quote\QuoteCheckExpired;
|
use App\Jobs\Quote\QuoteCheckExpired;
|
||||||
|
use App\Jobs\Subscription\CleanStaleInvoiceOrder;
|
||||||
use App\Jobs\Util\DiskCleanup;
|
use App\Jobs\Util\DiskCleanup;
|
||||||
use App\Jobs\Util\ReminderJob;
|
use App\Jobs\Util\ReminderJob;
|
||||||
use App\Jobs\Util\SchedulerCheck;
|
use App\Jobs\Util\SchedulerCheck;
|
||||||
@ -68,6 +69,9 @@ class Kernel extends ConsoleKernel
|
|||||||
/* Sends recurring invoices*/
|
/* Sends recurring invoices*/
|
||||||
$schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping()->name('recurring-invoice-job')->onOneServer();
|
$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*/
|
/* Sends recurring invoices*/
|
||||||
$schedule->job(new RecurringExpensesCron)->dailyAt('00:10')->withoutOverlapping()->name('recurring-expense-job')->onOneServer();
|
$schedule->job(new RecurringExpensesCron)->dailyAt('00:10')->withoutOverlapping()->name('recurring-expense-job')->onOneServer();
|
||||||
|
|
||||||
|
@ -534,8 +534,6 @@ class BillingPortalPurchasev2 extends Component
|
|||||||
->adjustInventory()
|
->adjustInventory()
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
CleanStaleInvoiceOrder::dispatch($this->invoice->id, $this->company->db)->delay(600);
|
|
||||||
|
|
||||||
Cache::put($this->hash, [
|
Cache::put($this->hash, [
|
||||||
'subscription_id' => $this->subscription->id,
|
'subscription_id' => $this->subscription->id,
|
||||||
'email' => $this->email ?? $this->contact->email,
|
'email' => $this->email ?? $this->contact->email,
|
||||||
|
@ -30,7 +30,7 @@ class CleanStaleInvoiceOrder implements ShouldQueue
|
|||||||
* @param int invoice_id
|
* @param int invoice_id
|
||||||
* @param string $db
|
* @param string $db
|
||||||
*/
|
*/
|
||||||
public function __construct(private int $invoice_id, private string $db){}
|
public function __construct(){}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param InvoiceRepository $repo
|
* @param InvoiceRepository $repo
|
||||||
@ -38,13 +38,38 @@ class CleanStaleInvoiceOrder implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle(InvoiceRepository $repo) : void
|
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::query()
|
||||||
|
->withTrashed()
|
||||||
|
->where('is_proforma', 1)
|
||||||
|
->where('created_at', '<', now()->subHour())
|
||||||
|
->cursor()
|
||||||
|
->each(function ($invoice) use ($repo) {
|
||||||
$invoice->is_proforma = false;
|
$invoice->is_proforma = false;
|
||||||
$repo->delete($invoice);
|
$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