Improved error handling when album/photo not found

pull/462/head
Tobias Reich 8 years ago
parent 109880475a
commit a02ba0143f

@ -401,7 +401,7 @@ final class Album {
// Get album object
$album = $album->fetch_object();
// Photo not found
// Album not found?
if ($album===null) {
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified album');
return false;
@ -563,6 +563,12 @@ final class Album {
// Get album object
$album = $albums->fetch_object();
// Album not found?
if ($album===null) {
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified album');
return false;
}
// Call plugins
Plugins::get()->activate(__METHOD__, 1, func_get_args());
@ -593,6 +599,12 @@ final class Album {
// Get album object
$album = $albums->fetch_object();
// Album not found?
if ($album===null) {
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified album');
return false;
}
// Call plugins
Plugins::get()->activate(__METHOD__, 1, func_get_args());
@ -701,6 +713,12 @@ final class Album {
// Get album object
$album = $albums->fetch_object();
// Album not found?
if ($album===null) {
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified album');
return false;
}
// Call plugins
Plugins::get()->activate(__METHOD__, 1, func_get_args());

@ -33,16 +33,20 @@ final class Photo {
}
public function add(array $files, $albumID = 0, $description = '', $tags = '', $returnOnError = false) {
// Use $returnOnError if you want to handle errors by your own
// e.g. when calling this functions inside an if-condition
/**
* Creats new photo(s).
* Exits on error.
* Use $returnOnError if you want to handle errors by your own.
* @return boolean Returns true when successful.
*/
public function add(array $files, $albumID = 0, $returnOnError = false) {
// Check permissions
if (hasPermissions(LYCHEE_UPLOADS)===false||
hasPermissions(LYCHEE_UPLOADS_BIG)===false||
hasPermissions(LYCHEE_UPLOADS_THUMB)===false) {
Log::error(Database::get(), __METHOD__, __LINE__, 'An upload-folder is missing or not readable and writable');
if ($returnOnError===true) return false;
Response::error('An upload-folder is missing or not readable and writable!');
}
@ -649,6 +653,12 @@ final class Photo {
// Get photo object
$photo = $photos->fetch_assoc();
// Photo not found?
if ($photo===null) {
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified photo');
return false;
}
// Parse photo
$photo['sysdate'] = date('d M. Y', substr($photo['id'], 0, -4));
if (strlen($photo['takestamp'])>1) $photo['takedate'] = date('d M. Y', $photo['takestamp']);
@ -676,6 +686,12 @@ final class Photo {
// Get album object
$album = $albums->fetch_assoc();
// Photo not found?
if ($photo===null) {
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified album');
return false;
}
// Parse album
$photo['public'] = ($album['public']==='1' ? '2' : $photo['public']);
@ -823,7 +839,7 @@ final class Photo {
// Get photo object
$photo = $photos->fetch_object();
// Photo not found
// Photo not found?
if ($photo===null) {
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified photo');
return false;
@ -977,6 +993,12 @@ final class Photo {
// Get photo object
$photo = $photos->fetch_object();
// Photo not found?
if ($photo===null) {
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified photo');
return false;
}
// Check if public
if ($photo->public==='1') {
@ -1027,6 +1049,12 @@ final class Photo {
// Get photo object
$photo = $photos->fetch_object();
// Photo not found?
if ($photo===null) {
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified photo');
return false;
}
// Invert public
$public = ($photo->public==0 ? 1 : 0);

Loading…
Cancel
Save