fredyounan
10/25/2014 - 9:14 AM

CleanDirs.php

<?php

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class CleanDirs extends Command {

    protected $name = 'cleandirs';

    protected $description = 'Cleans directories.';

    public function __construct()
    {
        parent::__construct();
    }

    public function fire()
    {
        $now = time();
        foreach(File::directories('public/uploads/temp') as $dir ){
            $dirtime = filemtime($dir);
            
            if( $now-$dirtime > 3600){
                File::deleteDirectory($dir);
                $this->info('Directory '.$dir.' was deleted');
            }
        }
    }

    protected function getArguments()
    {
        return array(
            array('example', InputArgument::OPTIONAL, 'An example argument.'),
        );
    }

    protected function getOptions()
    {
        return array(
            array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
        );
    }

}