mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Separation of logging for reminders
This commit is contained in:
parent
76a8dafbaa
commit
7d17fcc779
@ -44,3 +44,29 @@ function nlog($output, $context = []): void
|
||||
$output = null;
|
||||
$context = null;
|
||||
}
|
||||
|
||||
|
||||
function nrlog($output, $context = []): void
|
||||
{
|
||||
if (! config('ninja.expanded_logging')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (gettype($output) == 'object') {
|
||||
$output = print_r($output, 1);
|
||||
}
|
||||
|
||||
// $trace = debug_backtrace();
|
||||
|
||||
if (Ninja::isHosted()) {
|
||||
try {
|
||||
info($output);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
} else {
|
||||
\Illuminate\Support\Facades\Log::channel('invoiceninja-reminders')->info($output, $context);
|
||||
}
|
||||
|
||||
$output = null;
|
||||
$context = null;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class ReminderJob implements ShouldQueue
|
||||
Auth::logout();
|
||||
|
||||
if (! config('ninja.db.multi_db_enabled')) {
|
||||
nlog("Sending invoice reminders on ".now()->format('Y-m-d h:i:s'));
|
||||
nrlog("Sending invoice reminders on ".now()->format('Y-m-d h:i:s'));
|
||||
|
||||
Invoice::query()
|
||||
->where('is_deleted', 0)
|
||||
@ -84,7 +84,7 @@ class ReminderJob implements ShouldQueue
|
||||
foreach (MultiDB::$dbs as $db) {
|
||||
MultiDB::setDB($db);
|
||||
|
||||
nlog("Sending invoice reminders on db {$db} ".now()->format('Y-m-d h:i:s'));
|
||||
nrlog("Sending invoice reminders on db {$db} ".now()->format('Y-m-d h:i:s'));
|
||||
|
||||
Invoice::query()
|
||||
->where('is_deleted', 0)
|
||||
@ -121,12 +121,12 @@ class ReminderJob implements ShouldQueue
|
||||
if ($invoice->isPayable()) {
|
||||
//Attempts to prevent duplicates from sending
|
||||
if ($invoice->reminder_last_sent && Carbon::parse($invoice->reminder_last_sent)->startOfDay()->eq(now()->startOfDay())) {
|
||||
nlog("caught a duplicate reminder for invoice {$invoice->number}");
|
||||
nrlog("caught a duplicate reminder for invoice {$invoice->number}");
|
||||
return;
|
||||
}
|
||||
|
||||
$reminder_template = $invoice->calculateTemplate('invoice');
|
||||
nlog("reminder template = {$reminder_template}");
|
||||
nrlog("reminder template = {$reminder_template}");
|
||||
$invoice->service()->touchReminder($reminder_template)->save();
|
||||
$fees = $this->calcLateFee($invoice, $reminder_template);
|
||||
|
||||
@ -149,7 +149,7 @@ class ReminderJob implements ShouldQueue
|
||||
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
|
||||
if ($invitation->contact && !$invitation->contact->trashed() && $invitation->contact->email) {
|
||||
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
|
||||
nlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}");
|
||||
nrlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}");
|
||||
$invoice->entityEmailEvent($invitation, $reminder_template);
|
||||
$invoice->sendEvent(Webhook::EVENT_REMIND_INVOICE, "client");
|
||||
}
|
||||
@ -220,7 +220,7 @@ class ReminderJob implements ShouldQueue
|
||||
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
|
||||
if ($invitation->contact && !$invitation->contact->trashed() && $invitation->contact->email) {
|
||||
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
|
||||
nlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}");
|
||||
nrlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}");
|
||||
$invoice->entityEmailEvent($invitation, $reminder_template);
|
||||
$invoice->sendEvent(Webhook::EVENT_REMIND_INVOICE, "client");
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ class InvoiceService
|
||||
|
||||
/*When a reminder is sent we want to touch the dates they were sent*/
|
||||
public function touchReminder(string $reminder_template)
|
||||
{
|
||||
{ nrlog(now()->format('Y-m-d h:i:s') . " INV #{$this->invoice->number} : Touching Reminder => {$reminder_template}");
|
||||
switch ($reminder_template) {
|
||||
case 'reminder1':
|
||||
$this->invoice->reminder1_sent = now();
|
||||
|
@ -58,7 +58,12 @@ return [
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'days' => 7,
|
||||
],
|
||||
|
||||
'invoiceninja-reminders' => [
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/invoiceninja-reminders.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'days' => 90,
|
||||
],
|
||||
'stack' => [
|
||||
'driver' => 'stack',
|
||||
'channels' => ['single'],
|
||||
|
Loading…
x
Reference in New Issue
Block a user