diff --git a/app/Console/Commands/SendRecurringInvoices.php b/app/Console/Commands/SendRecurringInvoices.php index 6a13dc3563..18443d5010 100644 --- a/app/Console/Commands/SendRecurringInvoices.php +++ b/app/Console/Commands/SendRecurringInvoices.php @@ -10,6 +10,7 @@ use App\Services\PaymentService; use DateTime; use Illuminate\Console\Command; use Symfony\Component\Console\Input\InputOption; +use Auth; /** * Class SendRecurringInvoices. @@ -91,12 +92,14 @@ class SendRecurringInvoices extends Command $account = $recurInvoice->account; $account->loadLocalizationSettings($recurInvoice->client); + Auth::loginUsingId($recurInvoice->user_id); $invoice = $this->invoiceRepo->createRecurringInvoice($recurInvoice); if ($invoice && ! $invoice->isPaid()) { $this->info('Sending Invoice'); $this->mailer->sendInvoice($invoice); } + Auth::logout(); } $delayedAutoBillInvoices = Invoice::with('account.timezone', 'recurring_invoice', 'invoice_items', 'client', 'user') @@ -115,7 +118,9 @@ class SendRecurringInvoices extends Command if ($invoice->getAutoBillEnabled() && $invoice->client->autoBillLater()) { $this->info('Processing Autobill-delayed Invoice ' . $invoice->id); + Auth::loginUsingId($invoice->user_id); $this->paymentService->autoBillInvoice($invoice); + Auth::logout(); } } diff --git a/app/Ninja/Repositories/ActivityRepository.php b/app/Ninja/Repositories/ActivityRepository.php index dc1d879939..135e0da0ac 100644 --- a/app/Ninja/Repositories/ActivityRepository.php +++ b/app/Ninja/Repositories/ActivityRepository.php @@ -9,6 +9,7 @@ use Auth; use DB; use Request; use Utils; +use App; class ActivityRepository { @@ -56,9 +57,9 @@ class ActivityRepository } else { $activity->user_id = $entity->user_id; $activity->account_id = $entity->account_id; - $activity->is_system = true; } + $activity->is_system = App::runningInConsole(); $activity->token_id = session('token_id'); return $activity;