Advertisement
Guest User

Untitled

a guest
Feb 20th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2.  
  3. namespace OneTimeNote\Commands;
  4.  
  5. use OneTimeNote\Repositories\NoteRepositoryInterface as Note;
  6. use Illuminate\Console\Command;
  7. use Symfony\Component\Console\Input\InputOption;
  8. use Symfony\Component\Console\Input\InputArgument;
  9.  
  10.  
  11. class OneTimeNoteDeleteCommand extends Command {
  12.  
  13.     protected $note;
  14.  
  15.     /**
  16.      * The console command name.
  17.      *
  18.      * @var string
  19.      */
  20.     protected $name = 'oneTimeNote:delete';
  21.  
  22.     /**
  23.      * The console command description.
  24.      *
  25.      * @var string
  26.      */
  27.     protected $description = 'Delete all notes older than specified number of days. 30 by default.';
  28.  
  29.     /**
  30.      * Create a new command instance.
  31.      *
  32.      * @return void
  33.      */
  34.     public function __construct(Note $note)
  35.     {
  36.         parent::__construct();
  37.         $this->note = $note;
  38.     }
  39.  
  40.     /**
  41.      * Execute the console command.
  42.      *
  43.      * @return mixed
  44.      */
  45.     public function fire()
  46.     {
  47.         $days = $this->option('days');
  48.  
  49.         if (!$days) {
  50.             $days = 30;
  51.         }
  52.  
  53.         $this->note->deleteNotesOlderThan($days);
  54.  
  55.         $this->info('Success - Notes older than ' . $days . ' days(s) have been deleted.');
  56.     }
  57.  
  58.     /**
  59.      * Get the console command options.
  60.      *
  61.      * @return array
  62.      */
  63.     protected function getOptions()
  64.     {
  65.         return array(
  66.             array('days', null, InputOption::VALUE_OPTIONAL, 'Removes a note that is N old.', null),
  67.         );
  68.     }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement