ClearMediaTempCommand::execute()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 13
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 2
nop 2
crap 12
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
namespace AnimeDb\Bundle\AppBundle\Command;
10
11
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use Symfony\Component\Filesystem\Filesystem;
15
use Symfony\Component\Finder\Finder;
16
17
/**
18
 * Clear the media temporary folder of images.
19
 */
20
class ClearMediaTempCommand extends ContainerAwareCommand
21
{
22
    protected function configure()
23
    {
24
        $this->setName('animedb:clear-media-temp')
25
            ->setDescription('Clear the media temporary folder of images');
26
    }
27
28
    /**
29
     * @param InputInterface $input
30
     * @param OutputInterface $output
31
     *
32
     * @return bool
33
     */
34
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        $start = microtime(true);
37
38
        if (file_exists($dir = $this->getContainer()->getParameter('kernel.root_dir').'/../web/media/tmp/')) {
39
            $fs = new Filesystem();
40
41
            $finder = new Finder();
42
            $finder->in($dir)->date('< 1 hour ago')->ignoreUnreadableDirs();
43
            /* @var $file \SplFileInfo */
44
            foreach ($finder as $file) {
45
                $fs->remove($file->getRealPath());
46
            }
47
        }
48
49
        $output->writeln('Time: <info>'.round((microtime(true) - $start) * 1000, 2).'</info> s.');
50
    }
51
}
52