From 5140046cb60f2eef5777051d13ecafa7858b582c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Nov 2022 11:09:48 +1100 Subject: [PATCH 1/8] Minor fixes for logging --- app/Jobs/Util/VersionCheck.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Jobs/Util/VersionCheck.php b/app/Jobs/Util/VersionCheck.php index cdb2a280a89c..7ee5a047d358 100644 --- a/app/Jobs/Util/VersionCheck.php +++ b/app/Jobs/Util/VersionCheck.php @@ -37,13 +37,14 @@ class VersionCheck implements ShouldQueue { $version_file = trim(@file_get_contents(config('ninja.version_url'))); - nlog("latest version = {$version_file}"); - if (Ninja::isSelfHost() && $version_file) { Account::whereNotNull('id')->update(['latest_version' => $version_file]); } if (Ninja::isSelfHost()) { + + nlog("latest version = {$version_file}"); + $account = Account::first(); if (! $account) { From a91feab3b65c1cb0473d9849503e4dd433456356 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Nov 2022 12:10:18 +1100 Subject: [PATCH 2/8] Smooth out cron jobs --- app/Console/Kernel.php | 2 +- app/Jobs/Ninja/SystemMaintenance.php | 4 ---- app/Jobs/Util/ReminderJob.php | 21 +++++++++++---------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index fb7fa77b3ec1..cd578176e0c2 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -84,7 +84,7 @@ class Kernel extends ConsoleKernel $schedule->job(new TaskScheduler())->dailyAt('06:50')->withoutOverlapping(); /* Performs system maintenance such as pruning the backup table */ - $schedule->job(new SystemMaintenance)->weekly()->withoutOverlapping(); + $schedule->job(new SystemMaintenance)->sundays()->at('02:30')->withoutOverlapping(); /* Pulls in bank transactions from third party services */ $schedule->job(new BankTransactionSync)->dailyAt('04:10')->withoutOverlapping(); diff --git a/app/Jobs/Ninja/SystemMaintenance.php b/app/Jobs/Ninja/SystemMaintenance.php index de3571304c08..01219ce4b9cc 100644 --- a/app/Jobs/Ninja/SystemMaintenance.php +++ b/app/Jobs/Ninja/SystemMaintenance.php @@ -49,10 +49,6 @@ class SystemMaintenance implements ShouldQueue nlog('Starting System Maintenance'); - if (Ninja::isHosted()) { - return; - } - $delete_pdf_days = config('ninja.maintenance.delete_pdfs'); nlog("Number of days to keep PDFs {$delete_pdf_days}"); diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index 64e6faf13cef..6a2f55d754a8 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -87,7 +87,7 @@ class ReminderJob implements ShouldQueue $query->where('is_disabled', 0); }) ->with('invitations')->cursor()->each(function ($invoice) { - if ($invoice->isPayable()) { + if ($invoice->refresh() && $invoice->isPayable()) { //Attempts to prevent duplicates from sending if($invoice->reminder_last_sent && Carbon::parse($invoice->reminder_last_sent)->startOfDay()->eq(now()->startOfDay())){ @@ -97,9 +97,8 @@ class ReminderJob implements ShouldQueue $reminder_template = $invoice->calculateTemplate('invoice'); nlog("reminder template = {$reminder_template}"); - $invoice = $this->calcLateFee($invoice, $reminder_template); $invoice->service()->touchReminder($reminder_template)->save(); - $invoice->service()->touchPdf(true); + $invoice = $this->calcLateFee($invoice, $reminder_template); //20-04-2022 fixes for endless reminders - generic template naming was wrong $enabled_reminder = 'enable_'.$reminder_template; @@ -220,16 +219,18 @@ class ReminderJob implements ShouldQueue $invoice->client->service()->updateBalance($invoice->balance - $temp_invoice_balance); $invoice->ledger()->updateInvoiceBalance($invoice->balance - $temp_invoice_balance, "Late Fee Adjustment for invoice {$invoice->number}"); - $transaction = [ - 'invoice' => $invoice->transaction_event(), - 'payment' => [], - 'client' => $invoice->client->transaction_event(), - 'credit' => [], - 'metadata' => ['setLateFee'], - ]; + // $transaction = [ + // 'invoice' => $invoice->transaction_event(), + // 'payment' => [], + // 'client' => $invoice->client->transaction_event(), + // 'credit' => [], + // 'metadata' => ['setLateFee'], + // ]; // TransactionLog::dispatch(TransactionEvent::CLIENT_STATUS, $transaction, $invoice->company->db); + $invoice->service()->touchPdf(true); + return $invoice; } } From b2c9f33170e19e9316f777d0049c226a2547a9d7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Nov 2022 12:15:21 +1100 Subject: [PATCH 3/8] updates for SMS confirmations --- app/Http/Requests/Twilio/ConfirmSmsRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Requests/Twilio/ConfirmSmsRequest.php b/app/Http/Requests/Twilio/ConfirmSmsRequest.php index 537dcbab7da4..f8e98bb9ddc7 100644 --- a/app/Http/Requests/Twilio/ConfirmSmsRequest.php +++ b/app/Http/Requests/Twilio/ConfirmSmsRequest.php @@ -24,7 +24,7 @@ class ConfirmSmsRequest extends Request */ public function authorize() : bool { - return auth()->user()->isAdmin(); + return true; } public function rules() From 65a792edbf21647f916a787bb4488629e696ae91 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Nov 2022 12:21:03 +1100 Subject: [PATCH 4/8] Update twilio sms authorize() method --- app/Http/Requests/Twilio/GenerateSmsRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Requests/Twilio/GenerateSmsRequest.php b/app/Http/Requests/Twilio/GenerateSmsRequest.php index 9c25ec18ef3f..ccf20040b15e 100644 --- a/app/Http/Requests/Twilio/GenerateSmsRequest.php +++ b/app/Http/Requests/Twilio/GenerateSmsRequest.php @@ -24,7 +24,7 @@ class GenerateSmsRequest extends Request */ public function authorize() : bool { - return auth()->user(); + return true; } From dc8adf8378e949a211d055fceb0a9cf753f39508 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Nov 2022 12:38:09 +1100 Subject: [PATCH 5/8] Improve cron definitions to prevent race conditions --- app/Console/Kernel.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index cd578176e0c2..47ceee908af3 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -48,46 +48,46 @@ class Kernel extends ConsoleKernel $schedule->job(new VersionCheck)->daily(); /* Checks and cleans redundant files */ - $schedule->job(new DiskCleanup)->dailyAt('02:10')->withoutOverlapping(); + $schedule->job(new DiskCleanup)->dailyAt('02:10')->withoutOverlapping()->name('disk-cleanup-job')->onOneServer(); /* Send reminders */ - $schedule->job(new ReminderJob)->hourly()->withoutOverlapping(); + $schedule->job(new ReminderJob)->hourly()->withoutOverlapping()->name('reminder-job')->onOneServer(); /* Returns the number of jobs in the queue */ $schedule->job(new QueueSize)->everyFiveMinutes()->withoutOverlapping(); /* Checks for large companies and marked them as is_large */ - $schedule->job(new CompanySizeCheck)->dailyAt('23:20')->withoutOverlapping(); + $schedule->job(new CompanySizeCheck)->dailyAt('23:20')->withoutOverlapping()->name('company-size-job')->onOneServer(); /* Pulls in the latest exchange rates */ $schedule->job(new UpdateExchangeRates)->dailyAt('23:30')->withoutOverlapping(); /* Runs cleanup code for subscriptions */ - $schedule->job(new SubscriptionCron)->dailyAt('00:01')->withoutOverlapping(); + $schedule->job(new SubscriptionCron)->dailyAt('00:01')->withoutOverlapping()->name('subscription-job')->onOneServer(); /* Sends recurring invoices*/ - $schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping(); + $schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping()->name('recurring-invoice-job')->onOneServer(); /* Sends recurring invoices*/ - $schedule->job(new RecurringExpensesCron)->dailyAt('00:10')->withoutOverlapping(); + $schedule->job(new RecurringExpensesCron)->dailyAt('00:10')->withoutOverlapping()->name('recurring-expense-job')->onOneServer(); /* Fires notifications for expired Quotes */ - $schedule->job(new QuoteCheckExpired)->dailyAt('05:10')->withoutOverlapping(); + $schedule->job(new QuoteCheckExpired)->dailyAt('05:10')->withoutOverlapping()->name('quote-expired-job')->onOneServer(); /* Performs auto billing */ - $schedule->job(new AutoBillCron)->dailyAt('06:20')->withoutOverlapping(); + $schedule->job(new AutoBillCron)->dailyAt('06:20')->withoutOverlapping()->name('auto-bill-job')->onOneServer(); /* Checks the status of the scheduler */ $schedule->job(new SchedulerCheck)->dailyAt('01:10')->withoutOverlapping(); /* Checks for scheduled tasks */ - $schedule->job(new TaskScheduler())->dailyAt('06:50')->withoutOverlapping(); + $schedule->job(new TaskScheduler())->dailyAt('06:50')->withoutOverlapping()->name('task-scheduler-job')->onOneServer(); /* Performs system maintenance such as pruning the backup table */ - $schedule->job(new SystemMaintenance)->sundays()->at('02:30')->withoutOverlapping(); + $schedule->job(new SystemMaintenance)->sundays()->at('02:30')->withoutOverlapping()->name('system-maintenance-job')->onOneServer(); /* Pulls in bank transactions from third party services */ - $schedule->job(new BankTransactionSync)->dailyAt('04:10')->withoutOverlapping(); + $schedule->job(new BankTransactionSync)->dailyAt('04:10')->withoutOverlapping()->name('bank-trans-sync-job')->onOneServer(); if (Ninja::isSelfHost()) { From dbdda5dd037bb05dda462cff7197f961c04cbfbf Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Nov 2022 12:42:02 +1100 Subject: [PATCH 6/8] clean up request --- app/Http/Requests/Report/GenericReportRequest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Http/Requests/Report/GenericReportRequest.php b/app/Http/Requests/Report/GenericReportRequest.php index 2e963adeacef..a9b34d194a55 100644 --- a/app/Http/Requests/Report/GenericReportRequest.php +++ b/app/Http/Requests/Report/GenericReportRequest.php @@ -32,8 +32,6 @@ class GenericReportRequest extends Request return [ 'date_range' => 'bail|required|string', - // 'start_date' => [Rule::requiredIf($this->date_range === 'custom')], - // 'end_date' => [Rule::requiredIf($this->date_range === 'custom')], 'end_date' => 'bail|required_if:date_range,custom|nullable|date', 'start_date' => 'bail|required_if:date_range,custom|nullable|date', 'report_keys' => 'present|array', From 667c1848dc06833c87ed01ea8dc22ce3afd553c4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Nov 2022 12:48:42 +1100 Subject: [PATCH 7/8] Improve validation layer for reports --- app/Http/Requests/Report/GenericReportRequest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Http/Requests/Report/GenericReportRequest.php b/app/Http/Requests/Report/GenericReportRequest.php index a9b34d194a55..9cfddf60f433 100644 --- a/app/Http/Requests/Report/GenericReportRequest.php +++ b/app/Http/Requests/Report/GenericReportRequest.php @@ -55,6 +55,12 @@ class GenericReportRequest extends Request $input['send_email'] = true; } + if (array_key_exists('date_range', $input) && $input['date_range'] != 'custom') { + $input['start_date'] = null; + $input['end_date'] = null; + } + + $this->replace($input); } } From d279a1254791d46334df0878e759db542899ea71 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Nov 2022 14:14:56 +1100 Subject: [PATCH 8/8] minor refactor for reminder jobs --- app/Jobs/Util/ReminderJob.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index 6a2f55d754a8..f5c64f38fcb9 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -87,7 +87,8 @@ class ReminderJob implements ShouldQueue $query->where('is_disabled', 0); }) ->with('invitations')->cursor()->each(function ($invoice) { - if ($invoice->refresh() && $invoice->isPayable()) { + // if ($invoice->refresh() && $invoice->isPayable()) { + if ($invoice->isPayable()) { //Attempts to prevent duplicates from sending if($invoice->reminder_last_sent && Carbon::parse($invoice->reminder_last_sent)->startOfDay()->eq(now()->startOfDay())){