diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index c0547d0c24d7..fa3590b75f47 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -10,6 +10,7 @@ use Mail; use Symfony\Component\Console\Input\InputOption; use Utils; use App\Models\Contact; +use App\Models\Invoice; use App\Models\Invitation; /* @@ -71,6 +72,7 @@ class CheckData extends Command if (! $this->option('client_id')) { $this->checkBlankInvoiceHistory(); $this->checkPaidToDate(); + $this->checkDraftSentInvoices(); } $this->checkBalances(); @@ -88,8 +90,6 @@ class CheckData extends Command $this->logMessage('Done: ' . strtoupper($this->isValid ? RESULT_SUCCESS : RESULT_FAILURE)); $errorEmail = env('ERROR_EMAIL'); - $this->info($this->log); - if ($errorEmail) { Mail::raw($this->log, function ($message) use ($errorEmail, $database) { $message->to($errorEmail) @@ -103,9 +103,29 @@ class CheckData extends Command private function logMessage($str) { + $this->info($str); $this->log .= $str . "\n"; } + private function checkDraftSentInvoices() + { + $invoices = Invoice::whereInvoiceStatusId(INVOICE_STATUS_SENT) + ->whereIsPublic(false) + ->withTrashed() + ->get(); + + $this->logMessage(count($invoices) . ' draft sent invoices'); + + if ($this->option('fix') == 'true') { + foreach ($invoices as $invoice) { + if ($invoice->is_deleted) { + $invoice->unsetEventDispatcher(); + } + $invoice->markSent(); + } + } + } + private function checkOAuth() { // check for duplicate oauth ids