Completed
Push — master ( 219f9c...015b0d )
by Benjamin
23:07 queued 20:27
created

MediaCleanupCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 2
1
<?php
2
3
namespace Alpixel\Bundle\MediaBundle\Command;
4
5
use Alpixel\Bundle\CronBundle\Annotation\CronJob;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * @CronJob("PT1D")
12
 */
13
class MediaCleanupCommand extends ContainerAwareCommand
14
{
15
    public function configure()
16
    {
17
        $this->setName('alpixel:media:cleanup')
18
             ->setDescription('Cleaning unused media');
19
    }
20
21
    public function execute(InputInterface $input, OutputInterface $output)
22
    {
23
        $container = $this->getContainer();
24
25
        $medias = $container->get('doctrine.orm.entity_manager')
26
                            ->getRepository('AlpixelMediaBundle:Media')
27
                            ->findExpiredMedias();
28
        $container->get('alpixel_media.manager')->cleanup();
29
        $output->writeln(sprintf('%s medias deleted', count($medias)));
30
    }
31
}
32