|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PiedWeb\CMSBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
6
|
|
|
use Liip\ImagineBundle\Imagine\Cache\CacheManager; |
|
7
|
|
|
use Liip\ImagineBundle\Imagine\Data\DataManager; |
|
8
|
|
|
use Liip\ImagineBundle\Imagine\Filter\FilterManager; |
|
9
|
|
|
use PiedWeb\CMSBundle\EventListener\MediaCacheGeneratorTrait; |
|
10
|
|
|
use Symfony\Component\Console\Command\Command; |
|
11
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
|
16
|
|
|
|
|
17
|
|
|
class MediaCommand extends Command |
|
18
|
|
|
{ |
|
19
|
|
|
use MediaCacheGeneratorTrait; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var EntityManagerInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $em; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $webDir; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
private $staticDir; |
|
35
|
|
|
|
|
36
|
|
|
private $params; |
|
37
|
|
|
|
|
38
|
|
|
protected $redirections = ''; |
|
39
|
|
|
|
|
40
|
|
|
private $cacheManager; |
|
41
|
|
|
private $dataManager; |
|
42
|
|
|
private $filterManager; |
|
43
|
|
|
|
|
44
|
|
|
public function __construct( |
|
45
|
|
|
EntityManagerInterface $em, |
|
46
|
|
|
ParameterBagInterface $params, |
|
47
|
|
|
CacheManager $cacheManager, |
|
48
|
|
|
DataManager $dataManager, |
|
49
|
|
|
FilterManager $filterManager, |
|
50
|
|
|
string $webDir |
|
51
|
|
|
) { |
|
52
|
|
|
$this->em = $em; |
|
53
|
|
|
$this->params = $params; |
|
54
|
|
|
$this->webDir = $webDir; |
|
55
|
|
|
$this->cacheManager = $cacheManager; |
|
56
|
|
|
$this->dataManager = $dataManager; |
|
57
|
|
|
$this->filterManager = $filterManager; |
|
58
|
|
|
$this->staticDir = $this->webDir.'/../static'; |
|
59
|
|
|
$this->projectDir = $this->webDir.'/..'; |
|
60
|
|
|
|
|
61
|
|
|
parent::__construct(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
protected function configure() |
|
65
|
|
|
{ |
|
66
|
|
|
$this |
|
67
|
|
|
->setName('media:cache:generate') |
|
68
|
|
|
->setDescription('Generate all images cache') |
|
69
|
|
|
->addArgument('media', InputArgument::OPTIONAL, |
|
70
|
|
|
'Image file path for which to generate the cached images.'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
74
|
|
|
{ |
|
75
|
|
|
if ($input->getArgument('media')) { |
|
76
|
|
|
$medias = $this->em->getRepository($this->params->get('app.entity_media'))->findByMedia($input->getArgument('media')); |
|
|
|
|
|
|
77
|
|
|
} else { |
|
78
|
|
|
$medias = $this->em->getRepository($this->params->get('app.entity_media'))->findAll(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$progressBar = new ProgressBar($output, count($medias)); |
|
82
|
|
|
$progressBar->start(); |
|
83
|
|
|
foreach ($medias as $media) { |
|
84
|
|
|
if (false !== strpos($media->getMimeType(), 'image/')) { |
|
85
|
|
|
$this->generateCache($media); |
|
86
|
|
|
} |
|
87
|
|
|
$progressBar->advance(); |
|
88
|
|
|
} |
|
89
|
|
|
$progressBar->finish(); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.