Browse Source

Fixed: Only import urls passend to the function, not existing photos from the temp folder

Tobias Reich 9 years ago
parent
commit
1dece87434
1 changed files with 19 additions and 5 deletions
  1. 19 5
      php/modules/Import.php

+ 19 - 5
php/modules/Import.php

@@ -32,6 +32,8 @@ class Import extends Module {
 
 	static function url($urls, $albumID = 0) {
 
+		global $database, $plugins, $settings;
+
 		$error = false;
 
 		# Parse
@@ -40,6 +42,9 @@ class Import extends Module {
 
 		foreach ($urls as &$url) {
 
+			# Validate photo type and extension even when Import::photo (=> $photo->add) will do the same.
+			# This prevents us from downloading invalid photos.
+
 			# Verify extension
 			$extension = getExtension($url);
 			if (!in_array(strtolower($extension), Photo::$validExtensions, true)) {
@@ -58,14 +63,23 @@ class Import extends Module {
 			$filename	= $pathinfo['filename'] . '.' . $pathinfo['extension'];
 			$tmp_name	= LYCHEE_DATA . $filename;
 
-			if (@copy($url, $tmp_name)===false) $error = true;
+			if (@copy($url, $tmp_name)===false) {
+				$error = true;
+				Log::error($database, __METHOD__, __LINE__, 'Could not copy file (' . $tmp_name . ') to temp-folder (' . $tmp_name . ')');
+				continue;
+			}
 
-		}
+			# Import photo
+			if (!Import::photo($database, $plugins, $settings, $tmp_name, $albumID)) {
+				$error = true;
+				Log::error($database, __METHOD__, __LINE__, 'Could not import file: ' . $tmp_name);
+				continue;
+			}
 
-		$import = Import::server($albumID, LYCHEE_DATA);
+		}
 
-		if ($error===false&&$import===true) return true;
-		else return false;
+		if ($error===false) return true;
+		return false;
 
 	}