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

MediaCleanupCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 2
c 4
b 1
f 0
lcom 0
cbo 4
dl 0
loc 19
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 10 1
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