Improved error handling when album/photo not found

This commit is contained in:
Tobias Reich 2016-02-13 23:37:25 +01:00
parent 109880475a
commit a02ba0143f
2 changed files with 52 additions and 6 deletions

View File

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

View File

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