Skip to content

Commit

Permalink
Merge pull request #20 from daniellienert/task/adjust-logger-for-flow-6
Browse files Browse the repository at this point in the history
TASK: Adjust logger calls for Flow 6.0
  • Loading branch information
aertmann committed Aug 20, 2019
2 parents c1eb870 + 7e61225 commit 24df87c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
24 changes: 16 additions & 8 deletions Classes/Aspects/ThumbnailAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
namespace MOC\ImageOptimizer\Aspects;

use Neos\Eel\CompilingEvaluator;
use Neos\Eel\Exception;
use Neos\Eel\Utility;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
use Neos\Flow\Log\SystemLoggerInterface;
use Neos\Flow\Package\PackageManagerInterface;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Package\Exception\UnknownPackageException;
use Neos\Flow\Package\PackageManager;
use Neos\Flow\ResourceManagement\ResourceManager;
use Neos\Media\Domain\Model\Thumbnail;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;

/**
* @Flow\Scope("singleton")
Expand All @@ -16,14 +21,14 @@
class ThumbnailAspect
{
/**
* @var SystemLoggerInterface
* @var LoggerInterface
* @Flow\Inject
*/
protected $systemLogger;

/**
* @Flow\Inject
* @var PackageManagerInterface
* @var PackageManager
*/
protected $packageManager;

Expand Down Expand Up @@ -65,12 +70,14 @@ public function injectSettings(array $settings)
* process it, import it and set that as the thumbnail resource.
*
* @Flow\AfterReturning("method(Neos\Media\Domain\Model\Thumbnail->refresh())")
* @param \Neos\Flow\Aop\JoinPointInterface $joinPoint The current join point
* @param JoinPointInterface $joinPoint The current join point
* @return void
* @throws Exception
* @throws UnknownPackageException
*/
public function optimizeThumbnail(JoinPointInterface $joinPoint)
{
/** @var \Neos\Media\Domain\Model\Thumbnail $thumbnail */
/** @var Thumbnail $thumbnail */
$thumbnail = $joinPoint->getProxy();
$thumbnailResource = $thumbnail->getResource();
if (!$thumbnailResource) {
Expand All @@ -86,7 +93,7 @@ public function optimizeThumbnail(JoinPointInterface $joinPoint)
$imageType = $thumbnailResource->getMediaType();

if (!array_key_exists($imageType, $this->settings['formats'])) {
$this->systemLogger->log(sprintf('Unsupported type "%s" skipped in optimizeThumbnail', $imageType), LOG_INFO);
$this->systemLogger->info(sprintf('Unsupported type "%s" skipped in optimizeThumbnail', $imageType), LogEnvironment::fromMethodName(__METHOD__));
return;
}

Expand All @@ -111,6 +118,7 @@ public function optimizeThumbnail(JoinPointInterface $joinPoint)
$output = [];
exec($cmd, $output, $result);
$failed = (int)$result !== 0;
$this->systemLogger->log($cmd . ' (' . ($failed ? 'Error: ' . $result : 'OK') . ')', $failed ? LOG_ERR : LOG_INFO, $output);

$this->systemLogger->log($failed ? LogLevel::ERROR : LogLevel::INFO, $cmd . ' (' . ($failed ? 'Error: ' . $result : 'OK') . ')', array_merge(LogEnvironment::fromMethodName(__METHOD__), $output));
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Using jpegtran, optipng, gifsicle and svgo or alternative customizible ones for

Should work with Linux, FreeBSD, OSX, SunOS & Windows (only tested Linux & FreeBSD so far).

Compatible with Neos 1.x - 4.x / Flow 1.x - 5.x
Compatible with Neos 1.x - 5.x / Flow 1.x - 6.x

##### Only supports local file system (no CDN support yet) (see #10)

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"neos/media": ">3"
"neos/media": ">=5"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 24df87c

Please sign in to comment.