diff --git a/app/Console/Commands/SendReminders.php b/app/Console/Commands/SendReminders.php index 480b2dfabd31..3ee5032ed240 100644 --- a/app/Console/Commands/SendReminders.php +++ b/app/Console/Commands/SendReminders.php @@ -172,6 +172,9 @@ class SendReminders extends Command $config = (array) json_decode($scheduledReport->config); $reportType = $config['report_type']; + // send email as user + auth()->onceUsingId($user->id); + $report = dispatch(new RunReport($scheduledReport->user, $reportType, $config, true)); $file = dispatch(new ExportReportResults($scheduledReport->user, $config['export_format'], $reportType, $report->exportParams)); @@ -180,6 +183,8 @@ class SendReminders extends Command } $scheduledReport->updateSendDate(); + + auth()->logout(); } } diff --git a/app/Jobs/RunReport.php b/app/Jobs/RunReport.php index 333b142d02bf..4d915fdd9139 100644 --- a/app/Jobs/RunReport.php +++ b/app/Jobs/RunReport.php @@ -61,11 +61,6 @@ class RunReport extends Job $endDate = $config['end_date']; } - // send email as user - if (App::runningInConsole() && $this->user) { - auth()->onceUsingId($this->user->id); - } - $report = new $reportClass($startDate, $endDate, $isExport, $config); $report->run(); @@ -77,10 +72,6 @@ class RunReport extends Job $report->exportParams = array_merge($params, $report->results()); - if (App::runningInConsole() && $this->user) { - auth()->logout(); - } - return $report; } }