Working on multi-db

This commit is contained in:
David Bomba 2021-02-10 13:26:05 +11:00
parent 313488dc60
commit 6cc02243f5
2 changed files with 39 additions and 3 deletions

View File

@ -11,6 +11,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Libraries\MultiDB;
use App\Models\Design; use App\Models\Design;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use stdClass; use stdClass;
@ -47,6 +48,23 @@ class DesignUpdate extends Command
* @return mixed * @return mixed
*/ */
public function handle() public function handle()
{
if (! config('ninja.db.multi_db_enabled')) {
$this->processReminders();
} else {
//multiDB environment, need to
foreach (MultiDB::$dbs as $db) {
MultiDB::setDB($db);
$this->processReminders($db);
}
}
}
private function handleOnDb()
{ {
foreach (Design::whereIsCustom(false)->get() as $design) { foreach (Design::whereIsCustom(false)->get() as $design) {
$invoice_design = new \App\Services\PdfMaker\Design(strtolower($design->name)); $invoice_design = new \App\Services\PdfMaker\Design(strtolower($design->name));

View File

@ -13,6 +13,7 @@ namespace App\Console\Commands;
use App\Jobs\Ninja\SendReminders; use App\Jobs\Ninja\SendReminders;
use App\Jobs\Util\WebHookHandler; use App\Jobs\Util\WebHookHandler;
use App\Libraries\MultiDB;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\Quote; use App\Models\Quote;
use App\Models\Webhook; use App\Models\Webhook;
@ -58,6 +59,24 @@ class SendRemindersCron extends Command
} }
private function webHookOverdueInvoices() private function webHookOverdueInvoices()
{
if (! config('ninja.db.multi_db_enabled')) {
$this->executeWebhooks();
} else {
//multiDB environment, need to
foreach (MultiDB::$dbs as $db) {
MultiDB::setDB($db);
$this->executeWebhooks();
}
}
}
private function executeWebhooks()
{ {
$invoices = Invoice::where('is_deleted', 0) $invoices = Invoice::where('is_deleted', 0)
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
@ -68,10 +87,7 @@ class SendRemindersCron extends Command
$invoices->each(function ($invoice) { $invoices->each(function ($invoice) {
WebHookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company); WebHookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company);
}); });
}
private function webHookExpiredQuotes()
{
$quotes = Quote::where('is_deleted', 0) $quotes = Quote::where('is_deleted', 0)
->where('status_id', Quote::STATUS_SENT) ->where('status_id', Quote::STATUS_SENT)
->whereDate('due_date', '<=', now()->subDays(1)->startOfDay()) ->whereDate('due_date', '<=', now()->subDays(1)->startOfDay())
@ -81,4 +97,6 @@ class SendRemindersCron extends Command
WebHookHandler::dispatch(Webhook::EVENT_EXPIRED_QUOTE, $quote, $quote->company); WebHookHandler::dispatch(Webhook::EVENT_EXPIRED_QUOTE, $quote, $quote->company);
}); });
} }
} }