Improved handling of permission errors with the medium-folder

This commit is contained in:
Tobias Reich 2014-12-06 14:29:17 +01:00
parent a4c09288dc
commit 39084c5a5a

View File

@ -45,8 +45,7 @@ class Photo extends Module {
# Check permissions # Check permissions
if (hasPermissions(LYCHEE_UPLOADS)===false|| if (hasPermissions(LYCHEE_UPLOADS)===false||
hasPermissions(LYCHEE_UPLOADS_BIG)===false|| hasPermissions(LYCHEE_UPLOADS_BIG)===false||
hasPermissions(LYCHEE_UPLOADS_THUMB)===false|| hasPermissions(LYCHEE_UPLOADS_THUMB)===false) {
hasPermissions(LYCHEE_UPLOADS_MEDIUM)===false) {
Log::error($this->database, __METHOD__, __LINE__, 'An upload-folder is missing or not readable and writable'); Log::error($this->database, __METHOD__, __LINE__, 'An upload-folder is missing or not readable and writable');
exit('Error: An upload-folder is missing or not readable and writable!'); exit('Error: An upload-folder is missing or not readable and writable!');
} }
@ -334,32 +333,51 @@ class Photo extends Module {
# Call plugins # Call plugins
$this->plugins(__METHOD__, 0, func_get_args()); $this->plugins(__METHOD__, 0, func_get_args());
# Set to true when creation of medium-photo failed
$error = false;
# Size of the medium-photo # Size of the medium-photo
# When changing these values, # When changing these values,
# also change the size detection in the front-end # also change the size detection in the front-end
$newWidth = 1920; $newWidth = 1920;
$newHeight = 1080; $newHeight = 1080;
# Check permissions
if (hasPermissions(LYCHEE_UPLOADS_MEDIUM)===false) {
# Permissions are missing
Log::notice($this->database, __METHOD__, __LINE__, 'Skipped creation of medium-photo, because uploads/medium/ is missing or not readable and writable.');
$error = true;
}
# Is photo big enough? # Is photo big enough?
# Is medium activated? # Is medium activated?
# Is Imagick installed and activated? # Is Imagick installed and activated?
if (($width>$newWidth||$height>$newHeight)&& if (($error===false)&&
($width>$newWidth||$height>$newHeight)&&
($this->settings['medium']==='1')&& ($this->settings['medium']==='1')&&
(extension_loaded('imagick')&&$this->settings['imagick']==='1')) { (extension_loaded('imagick')&&$this->settings['imagick']==='1')) {
# $info = getimagesize($url);
$newUrl = LYCHEE_UPLOADS_MEDIUM . $filename; $newUrl = LYCHEE_UPLOADS_MEDIUM . $filename;
# Read image # Read image
$medium = new Imagick(); $medium = new Imagick();
$medium->readImage($url); $medium->readImage($url);
# Adjust image
$medium->scaleImage($newWidth, $newHeight, true); $medium->scaleImage($newWidth, $newHeight, true);
$medium->writeImage($newUrl);
# Save image
try { $medium->writeImage($newUrl); }
catch (ImagickException $err) {
Log::notice($this->database, __METHOD__, __LINE__, 'Could not save medium-photo: ' . $err->getMessage());
$error = true;
}
$medium->clear(); $medium->clear();
$medium->destroy(); $medium->destroy();
$error = false;
} else { } else {
# Photo too small or # Photo too small or