@@ -15,102 +15,102 @@ |
||
15 | 15 | */ |
16 | 16 | class ThumbnailAspect |
17 | 17 | { |
18 | - /** |
|
19 | - * @var SystemLoggerInterface |
|
20 | - * @Flow\Inject |
|
21 | - */ |
|
22 | - protected $systemLogger; |
|
23 | - |
|
24 | - /** |
|
25 | - * @Flow\Inject |
|
26 | - * @var PackageManagerInterface |
|
27 | - */ |
|
28 | - protected $packageManager; |
|
29 | - |
|
30 | - /** |
|
31 | - * @Flow\Inject |
|
32 | - * @var ResourceManager |
|
33 | - */ |
|
34 | - protected $resourceManager; |
|
35 | - |
|
36 | - /** |
|
37 | - * @Flow\Inject |
|
38 | - * @var CompilingEvaluator |
|
39 | - */ |
|
40 | - protected $eelEvaluator; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - protected $settings; |
|
46 | - |
|
47 | - /** |
|
48 | - * @param array $settings |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function injectSettings(array $settings) |
|
52 | - { |
|
53 | - $this->settings = $settings; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * After a thumbnail has been refreshed the resource is optimized, meaning the |
|
58 | - * image is only optimized once when created. |
|
59 | - * |
|
60 | - * A new resource is generated for every thumbnail, meaning the original is |
|
61 | - * never touched. |
|
62 | - * |
|
63 | - * Only local file system target is supported to keep it from being blocking. |
|
64 | - * It would however be possible to create a local copy of the resource, |
|
65 | - * process it, import it and set that as the thumbnail resource. |
|
66 | - * |
|
67 | - * @Flow\AfterReturning("method(Neos\Media\Domain\Model\Thumbnail->refresh())") |
|
68 | - * @param \Neos\Flow\Aop\JoinPointInterface $joinPoint The current join point |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public function optimizeThumbnail(JoinPointInterface $joinPoint) |
|
72 | - { |
|
73 | - /** @var \Neos\Media\Domain\Model\Thumbnail $thumbnail */ |
|
74 | - $thumbnail = $joinPoint->getProxy(); |
|
75 | - $thumbnailResource = $thumbnail->getResource(); |
|
76 | - if (!$thumbnailResource) { |
|
77 | - return; |
|
78 | - } |
|
79 | - |
|
80 | - $streamMetaData = stream_get_meta_data($thumbnailResource->getStream()); |
|
81 | - $pathAndFilename = $streamMetaData['uri']; |
|
82 | - |
|
83 | - $useGlobalBinary = $this->settings['useGlobalBinary']; |
|
84 | - $binaryRootPath = 'Private/Library/node_modules/'; |
|
85 | - $file = escapeshellarg($pathAndFilename); |
|
86 | - $imageType = $thumbnailResource->getMediaType(); |
|
87 | - |
|
88 | - if (!array_key_exists($imageType, $this->settings['formats'])) { |
|
89 | - $this->systemLogger->log(sprintf('Unsupported type "%s" skipped in optimizeThumbnail', $imageType), LOG_INFO); |
|
90 | - return; |
|
91 | - } |
|
92 | - |
|
93 | - $librarySettings = $this->settings['formats'][$imageType]; |
|
94 | - |
|
95 | - if ($librarySettings['enabled'] === false) { |
|
96 | - return; |
|
97 | - } |
|
98 | - |
|
99 | - if ($librarySettings['useGlobalBinary'] === true) { |
|
100 | - $useGlobalBinary = true; |
|
101 | - } |
|
102 | - |
|
103 | - $library = $librarySettings['library']; |
|
104 | - $binaryPath = $librarySettings['binaryPath']; |
|
105 | - $eelExpression = $librarySettings['arguments']; |
|
106 | - $parameters = array_merge($librarySettings['parameters'], ['file' => $file]); |
|
107 | - $arguments = Utility::evaluateEelExpression($eelExpression, $this->eelEvaluator, $parameters); |
|
108 | - |
|
109 | - $binaryPath = $useGlobalBinary === true ? $this->settings['globalBinaryPath'] . $library : $this->packageManager->getPackage('MOC.ImageOptimizer')->getResourcesPath() . $binaryRootPath . $binaryPath; |
|
110 | - $cmd = escapeshellcmd($binaryPath) . ' ' . $arguments; |
|
111 | - $output = []; |
|
112 | - exec($cmd, $output, $result); |
|
113 | - $failed = (int)$result !== 0; |
|
114 | - $this->systemLogger->log($cmd . ' (' . ($failed ? 'Error: ' . $result : 'OK') . ')', $failed ? LOG_ERR : LOG_INFO, $output); |
|
115 | - } |
|
18 | + /** |
|
19 | + * @var SystemLoggerInterface |
|
20 | + * @Flow\Inject |
|
21 | + */ |
|
22 | + protected $systemLogger; |
|
23 | + |
|
24 | + /** |
|
25 | + * @Flow\Inject |
|
26 | + * @var PackageManagerInterface |
|
27 | + */ |
|
28 | + protected $packageManager; |
|
29 | + |
|
30 | + /** |
|
31 | + * @Flow\Inject |
|
32 | + * @var ResourceManager |
|
33 | + */ |
|
34 | + protected $resourceManager; |
|
35 | + |
|
36 | + /** |
|
37 | + * @Flow\Inject |
|
38 | + * @var CompilingEvaluator |
|
39 | + */ |
|
40 | + protected $eelEvaluator; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + protected $settings; |
|
46 | + |
|
47 | + /** |
|
48 | + * @param array $settings |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function injectSettings(array $settings) |
|
52 | + { |
|
53 | + $this->settings = $settings; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * After a thumbnail has been refreshed the resource is optimized, meaning the |
|
58 | + * image is only optimized once when created. |
|
59 | + * |
|
60 | + * A new resource is generated for every thumbnail, meaning the original is |
|
61 | + * never touched. |
|
62 | + * |
|
63 | + * Only local file system target is supported to keep it from being blocking. |
|
64 | + * It would however be possible to create a local copy of the resource, |
|
65 | + * process it, import it and set that as the thumbnail resource. |
|
66 | + * |
|
67 | + * @Flow\AfterReturning("method(Neos\Media\Domain\Model\Thumbnail->refresh())") |
|
68 | + * @param \Neos\Flow\Aop\JoinPointInterface $joinPoint The current join point |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public function optimizeThumbnail(JoinPointInterface $joinPoint) |
|
72 | + { |
|
73 | + /** @var \Neos\Media\Domain\Model\Thumbnail $thumbnail */ |
|
74 | + $thumbnail = $joinPoint->getProxy(); |
|
75 | + $thumbnailResource = $thumbnail->getResource(); |
|
76 | + if (!$thumbnailResource) { |
|
77 | + return; |
|
78 | + } |
|
79 | + |
|
80 | + $streamMetaData = stream_get_meta_data($thumbnailResource->getStream()); |
|
81 | + $pathAndFilename = $streamMetaData['uri']; |
|
82 | + |
|
83 | + $useGlobalBinary = $this->settings['useGlobalBinary']; |
|
84 | + $binaryRootPath = 'Private/Library/node_modules/'; |
|
85 | + $file = escapeshellarg($pathAndFilename); |
|
86 | + $imageType = $thumbnailResource->getMediaType(); |
|
87 | + |
|
88 | + if (!array_key_exists($imageType, $this->settings['formats'])) { |
|
89 | + $this->systemLogger->log(sprintf('Unsupported type "%s" skipped in optimizeThumbnail', $imageType), LOG_INFO); |
|
90 | + return; |
|
91 | + } |
|
92 | + |
|
93 | + $librarySettings = $this->settings['formats'][$imageType]; |
|
94 | + |
|
95 | + if ($librarySettings['enabled'] === false) { |
|
96 | + return; |
|
97 | + } |
|
98 | + |
|
99 | + if ($librarySettings['useGlobalBinary'] === true) { |
|
100 | + $useGlobalBinary = true; |
|
101 | + } |
|
102 | + |
|
103 | + $library = $librarySettings['library']; |
|
104 | + $binaryPath = $librarySettings['binaryPath']; |
|
105 | + $eelExpression = $librarySettings['arguments']; |
|
106 | + $parameters = array_merge($librarySettings['parameters'], ['file' => $file]); |
|
107 | + $arguments = Utility::evaluateEelExpression($eelExpression, $this->eelEvaluator, $parameters); |
|
108 | + |
|
109 | + $binaryPath = $useGlobalBinary === true ? $this->settings['globalBinaryPath'] . $library : $this->packageManager->getPackage('MOC.ImageOptimizer')->getResourcesPath() . $binaryRootPath . $binaryPath; |
|
110 | + $cmd = escapeshellcmd($binaryPath) . ' ' . $arguments; |
|
111 | + $output = []; |
|
112 | + exec($cmd, $output, $result); |
|
113 | + $failed = (int)$result !== 0; |
|
114 | + $this->systemLogger->log($cmd . ' (' . ($failed ? 'Error: ' . $result : 'OK') . ')', $failed ? LOG_ERR : LOG_INFO, $output); |
|
115 | + } |
|
116 | 116 | } |
@@ -106,11 +106,11 @@ |
||
106 | 106 | $parameters = array_merge($librarySettings['parameters'], ['file' => $file]); |
107 | 107 | $arguments = Utility::evaluateEelExpression($eelExpression, $this->eelEvaluator, $parameters); |
108 | 108 | |
109 | - $binaryPath = $useGlobalBinary === true ? $this->settings['globalBinaryPath'] . $library : $this->packageManager->getPackage('MOC.ImageOptimizer')->getResourcesPath() . $binaryRootPath . $binaryPath; |
|
110 | - $cmd = escapeshellcmd($binaryPath) . ' ' . $arguments; |
|
109 | + $binaryPath = $useGlobalBinary === true ? $this->settings['globalBinaryPath'].$library : $this->packageManager->getPackage('MOC.ImageOptimizer')->getResourcesPath().$binaryRootPath.$binaryPath; |
|
110 | + $cmd = escapeshellcmd($binaryPath).' '.$arguments; |
|
111 | 111 | $output = []; |
112 | 112 | exec($cmd, $output, $result); |
113 | 113 | $failed = (int)$result !== 0; |
114 | - $this->systemLogger->log($cmd . ' (' . ($failed ? 'Error: ' . $result : 'OK') . ')', $failed ? LOG_ERR : LOG_INFO, $output); |
|
114 | + $this->systemLogger->log($cmd.' ('.($failed ? 'Error: '.$result : 'OK').')', $failed ? LOG_ERR : LOG_INFO, $output); |
|
115 | 115 | } |
116 | 116 | } |