Routes cache should be used for all driver types

Minor cleanup of MediaManager class
This commit is contained in:
Samuel Georges 2015-05-02 11:58:09 +10:00
parent b361b013e2
commit f49775d547
2 changed files with 17 additions and 14 deletions

View File

@ -89,11 +89,7 @@ class Router
$fileName = null; $fileName = null;
$urlList = []; $urlList = [];
$cacheable = Config::get('cms.enableRoutesCache') && in_array( $cacheable = Config::get('cms.enableRoutesCache');
Cache::getDefaultDriver(),
['apc', 'memcached', 'redis', 'array']
);
if ($cacheable) { if ($cacheable) {
$fileName = $this->getCachedUrlFileName($url, $urlList); $fileName = $this->getCachedUrlFileName($url, $urlList);
if (is_array($fileName)) { if (is_array($fileName)) {

View File

@ -819,8 +819,9 @@ class MediaManager extends WidgetBase
$height = $thumbnailInfo['height']; $height = $thumbnailInfo['height'];
$lastModified = $thumbnailInfo['lastModified']; $lastModified = $thumbnailInfo['lastModified'];
if (!is_numeric($width) || !is_numeric($height) || !is_numeric($lastModified)) if (!is_numeric($width) || !is_numeric($height) || !is_numeric($lastModified)) {
throw new ApplicationException('Invalid input data'); throw new ApplicationException('Invalid input data');
}
if (!$thumbnailParams) { if (!$thumbnailParams) {
$thumbnailParams = $this->getThumbnailParams(); $thumbnailParams = $this->getThumbnailParams();
@ -835,8 +836,9 @@ class MediaManager extends WidgetBase
$library = MediaLibrary::instance(); $library = MediaLibrary::instance();
$tempFilePath = $this->getLocalTempFilePath($path); $tempFilePath = $this->getLocalTempFilePath($path);
if (!@File::put($tempFilePath, $library->get($path))) if (!@File::put($tempFilePath, $library->get($path))) {
throw new SystemException('Error saving remote file to a temporary location'); throw new SystemException('Error saving remote file to a temporary location');
}
// Resize the thumbnail and save to the thumbnails directory // Resize the thumbnail and save to the thumbnails directory
$this->resizeImage($fullThumbnailPath, $thumbnailParams, $tempFilePath); $this->resizeImage($fullThumbnailPath, $thumbnailParams, $tempFilePath);
@ -849,11 +851,13 @@ class MediaManager extends WidgetBase
]); ]);
} }
catch (Exception $ex) { catch (Exception $ex) {
if ($tempFilePath) if ($tempFilePath) {
File::delete($tempFilePath); File::delete($tempFilePath);
}
if ($fullThumbnailPath) if ($fullThumbnailPath) {
$this->copyBrokenImage($fullThumbnailPath); $this->copyBrokenImage($fullThumbnailPath);
}
$markup = $this->makePartial('thumbnail-image', ['isError' => true]); $markup = $this->makePartial('thumbnail-image', ['isError' => true]);
@ -861,19 +865,21 @@ class MediaManager extends WidgetBase
traceLog($ex->getMessage()); traceLog($ex->getMessage());
} }
if ($markup && ($id = $thumbnailInfo['id'])) if ($markup && ($id = $thumbnailInfo['id'])) {
return [ return [
'id'=>$id, 'id' => $id,
'markup'=>$markup 'markup' => $markup
]; ];
}
} }
protected function resizeImage($fullThumbnailPath, $thumbnailParams, $tempFilePath) protected function resizeImage($fullThumbnailPath, $thumbnailParams, $tempFilePath)
{ {
$thumbnailDir = dirname($fullThumbnailPath); $thumbnailDir = dirname($fullThumbnailPath);
if (!File::isDirectory($thumbnailDir)) { if (!File::isDirectory($thumbnailDir)) {
if (File::makeDirectory($thumbnailDir, 0777, true) === false) if (File::makeDirectory($thumbnailDir, 0777, true) === false) {
throw new SystemException('Error creating thumbnail directory'); throw new SystemException('Error creating thumbnail directory');
}
} }
$targetDimensions = $this->getTargetDimensions($thumbnailParams['width'], $thumbnailParams['height'], $tempFilePath); $targetDimensions = $this->getTargetDimensions($thumbnailParams['width'], $thumbnailParams['height'], $tempFilePath);
@ -895,8 +901,9 @@ class MediaManager extends WidgetBase
protected function getBrokenImageHash() protected function getBrokenImageHash()
{ {
if ($this->brokenImageHash) if ($this->brokenImageHash) {
return $this->brokenImageHash; return $this->brokenImageHash;
}
$fullPath = $this->getBrokenImagePath(); $fullPath = $this->getBrokenImagePath();
return $this->brokenImageHash = hash_file('crc32', $fullPath); return $this->brokenImageHash = hash_file('crc32', $fullPath);