Преглед на файлове

Add log in fever api saving process (#2664)

Before, there was no user log when the fever api credential saving process
was failing. There was one though for the admin user but it did not appear
in the interface.
Now, there is a user log showing what the problem is. The admin log is still
there but catch only unknown errors.

See #2663
Alexis Degrugillier преди 6 години
родител
ревизия
d3735d04fc
променени са 1 файла, в които са добавени 16 реда и са изтрити 8 реда
  1. 16 8
      app/Controllers/userController.php

+ 16 - 8
app/Controllers/userController.php

@@ -59,14 +59,22 @@ class FreshRSS_user_Controller extends Minz_ActionController {
 			$apiPasswordHash = self::hashPassword($apiPasswordPlain);
 			$userConfig->apiPasswordHash = $apiPasswordHash;
 
-			@mkdir(DATA_PATH . '/fever/', 0770, true);
-			self::deleteFeverKey($user);
-			$userConfig->feverKey = strtolower(md5($user . ':' . $apiPasswordPlain));
-			$ok = file_put_contents(DATA_PATH . '/fever/.key-' . sha1(FreshRSS_Context::$system_conf->salt) . '-' . $userConfig->feverKey . '.txt', $user) !== false;
-
-			if (!$ok) {
-				Minz_Log::warning('Could not save API credentials for fever API', ADMIN_LOG);
-				return $ok;
+			$feverPath = DATA_PATH . '/fever/';
+
+			if (!file_exists($feverPath)) {
+				@mkdir($feverPath, 0770, true);
+			}
+
+			if (!is_writable($feverPath)) {
+				Minz_Log::error("Could not save Fever API credentials. The directory does not have write access.");
+			} else {
+				self::deleteFeverKey($user);
+				$userConfig->feverKey = strtolower(md5("{$user}:{$apiPasswordPlain}"));
+				$ok = file_put_contents($feverPath . '.key-' . sha1(FreshRSS_Context::$system_conf->salt) . '-' . $userConfig->feverKey . '.txt', $user) !== false;
+
+				if (!$ok) {
+					Minz_Log::warning('Could not save Fever API credentials. Unknown error.', ADMIN_LOG);
+				}
 			}
 		}