Add command to remove orphaned documents
This commit is contained in:
parent
d328db2f54
commit
1ddd2769ac
2 changed files with 42 additions and 0 deletions
41
app/Console/Commands/RemoveOrphanedDocuments.php
Normal file
41
app/Console/Commands/RemoveOrphanedDocuments.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php namespace App\Console\Commands;
|
||||
|
||||
use DateTime;
|
||||
use App\Models\Document;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class RemoveOrphanedDocuments extends Command
|
||||
{
|
||||
protected $name = 'ninja:remove-orphaned-documents';
|
||||
protected $description = 'Removes old documents not associated with an expense or invoice';
|
||||
|
||||
public function fire()
|
||||
{
|
||||
$this->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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue