From 1ddd2769acb377f0872fb938d499df4b88ba24f0 Mon Sep 17 00:00:00 2001 From: Joshua Dwire Date: Thu, 24 Mar 2016 13:02:45 -0400 Subject: [PATCH] Add command to remove orphaned documents --- .../Commands/RemoveOrphanedDocuments.php | 41 +++++++++++++++++++ app/Console/Kernel.php | 1 + 2 files changed, 42 insertions(+) create mode 100644 app/Console/Commands/RemoveOrphanedDocuments.php diff --git a/app/Console/Commands/RemoveOrphanedDocuments.php b/app/Console/Commands/RemoveOrphanedDocuments.php new file mode 100644 index 000000000000..3c7fe1bb537f --- /dev/null +++ b/app/Console/Commands/RemoveOrphanedDocuments.php @@ -0,0 +1,41 @@ +info(date('Y-m-d').' Running RemoveOrphanedDocuments...'); + + $documents = Document::whereRaw('invoice_id IS NULL AND expense_id IS NULL AND updated_at <= ?', array(new DateTime('-1 hour'))) + ->get(); + + $this->info(count($documents).' orphaned document(s) found'); + + foreach ($documents as $document) { + $document->delete(); + } + + $this->info('Done'); + } + + protected function getArguments() + { + return array( + //array('example', InputArgument::REQUIRED, 'An example argument.'), + ); + } + + protected function getOptions() + { + return array( + //array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null), + ); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index d04eab9fad91..af5bbe7bc9d2 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -13,6 +13,7 @@ class Kernel extends ConsoleKernel */ protected $commands = [ 'App\Console\Commands\SendRecurringInvoices', + 'App\Console\Commands\RemoveOrphanedDocuments', 'App\Console\Commands\ResetData', 'App\Console\Commands\CheckData', 'App\Console\Commands\SendRenewalInvoices',