Photo add function only adds the first file in the array

This commit is contained in:
Tobias Reich 2016-02-13 23:36:34 +01:00
parent 3c45bbf4d1
commit 109880475a
2 changed files with 155 additions and 155 deletions

View File

@ -4,7 +4,11 @@ namespace Lychee\Modules;
final class Import {
private function photo($path, $albumID = 0, $description = '', $tags = '') {
/**
* Creates an array similar to a file upload array and adds the photo to Lychee.
* @return boolean Returns true when photo import was successful.
*/
private function photo($path, $albumID = 0) {
// No need to validate photo type and extension in this function.
// $photo->add will take care of it.
@ -21,7 +25,7 @@ final class Import {
$nameFile[0]['size'] = $size;
$nameFile[0]['error'] = UPLOAD_ERR_OK;
if (!$photo->add($nameFile, $albumID, $description, $tags, true)) return false;
if ($photo->add($nameFile, $albumID, true)===false) return false;
return true;
}
@ -140,7 +144,7 @@ final class Import {
$contains['photos'] = true;
if (!$this->photo($file, $albumID)) {
if ($this->photo($file, $albumID)===false) {
$error = true;
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not import file (' . $file . ')');
continue;

View File

@ -79,7 +79,8 @@ final class Photo {
}
foreach ($files as $file) {
// Only process the first photo in the array
$file = $files[0];
// Check if file exceeds the upload_max_filesize directive
if ($file['error']===UPLOAD_ERR_INI_SIZE) {
@ -204,9 +205,6 @@ final class Photo {
// Use title of file if IPTC title missing
if ($info['title']==='') $info['title'] = substr(basename($file['name'], $extension), 0, 30);
// Use description parameter if set
if ($description==='') $description = $info['description'];
if ($exists===false) {
// Set orientation based on EXIF data
@ -236,7 +234,7 @@ final class Photo {
}
// Save to DB
$values = array(LYCHEE_TABLE_PHOTOS, $id, $info['title'], $photo_name, $description, $tags, $info['type'], $info['width'], $info['height'], $info['size'], $info['iso'], $info['aperture'], $info['make'], $info['model'], $info['shutter'], $info['focal'], $info['takestamp'], $path_thumb, $albumID, $public, $star, $checksum, $medium);
$values = array(LYCHEE_TABLE_PHOTOS, $id, $info['title'], $photo_name, $info['description'], '', $info['type'], $info['width'], $info['height'], $info['size'], $info['iso'], $info['aperture'], $info['make'], $info['model'], $info['shutter'], $info['focal'], $info['takestamp'], $path_thumb, $albumID, $public, $star, $checksum, $medium);
$query = Database::prepare(Database::get(), "INSERT INTO ? (id, title, url, description, tags, type, width, height, size, iso, aperture, make, model, shutter, focal, takestamp, thumbUrl, album, public, star, checksum, medium) VALUES ('?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?')", $values);
$result = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
@ -245,8 +243,6 @@ final class Photo {
Response::error('Could not save photo in database!');
}
}
// Call plugins
Plugins::get()->activate(__METHOD__, 1, func_get_args());