Browse Source

Ajout de messages en cas de mauvaise configuration

Si fichier de conf inaccessible / mal configuré ou fichier de log
inaccessible, on affiche des messages plus explicites qu'une page
blanche
Marien Fressinaud 12 years ago
parent
commit
a1fa4a445a

+ 11 - 3
lib/minz/Configuration.php

@@ -13,7 +13,7 @@ class Configuration {
 	/**
 	/**
 	 * VERSION est la version actuelle de MINZ
 	 * VERSION est la version actuelle de MINZ
 	 */
 	 */
-	const VERSION = '1.3.1';
+	const VERSION = '1.3.1.freshrss';  // version spéciale FreshRSS
 
 
 	/**
 	/**
 	 * valeurs possibles pour l'"environment"
 	 * valeurs possibles pour l'"environment"
@@ -98,10 +98,10 @@ class Configuration {
 		try {
 		try {
 			self::parseFile ();
 			self::parseFile ();
 			self::setReporting ();
 			self::setReporting ();
-		} catch (BadConfigurationException $e) {
-			throw $e;
 		} catch (FileNotExistException $e) {
 		} catch (FileNotExistException $e) {
 			throw $e;
 			throw $e;
+		} catch (BadConfigurationException $e) {
+			throw $e;
 		}
 		}
 	}
 	}
 
 
@@ -117,11 +117,19 @@ class Configuration {
 				MinzException::ERROR
 				MinzException::ERROR
 			);
 			);
 		}
 		}
+
 		$ini_array = parse_ini_file (
 		$ini_array = parse_ini_file (
 			APP_PATH . self::CONF_PATH_NAME,
 			APP_PATH . self::CONF_PATH_NAME,
 			true
 			true
 		);
 		);
 
 
+		if (!$ini_array) {
+			throw new PermissionDeniedException (
+				APP_PATH . self::CONF_PATH_NAME,
+				MinzException::ERROR
+			);
+		}
+
 		// [general] est obligatoire
 		// [general] est obligatoire
 		if (!isset ($ini_array['general'])) {
 		if (!isset ($ini_array['general'])) {
 			throw new BadConfigurationException (
 			throw new BadConfigurationException (

+ 11 - 7
lib/minz/FrontController.php

@@ -41,7 +41,7 @@ class FrontController {
 			Configuration::init ();
 			Configuration::init ();
 
 
 			Request::init ();
 			Request::init ();
-			
+
 			$this->router = new Router ();
 			$this->router = new Router ();
 			$this->router->init ();
 			$this->router->init ();
 		} catch (RouteNotFoundException $e) {
 		} catch (RouteNotFoundException $e) {
@@ -52,7 +52,7 @@ class FrontController {
 			);
 			);
 		} catch (MinzException $e) {
 		} catch (MinzException $e) {
 			Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
 			Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
-			$this->killApp ();
+			$this->killApp ($e->getMessage ());
 		}
 		}
 		
 		
 		$this->dispatcher = Dispatcher::getInstance ($this->router);
 		$this->dispatcher = Dispatcher::getInstance ($this->router);
@@ -94,12 +94,16 @@ class FrontController {
 			$this->dispatcher->run ();
 			$this->dispatcher->run ();
 			Response::send ();
 			Response::send ();
 		} catch (MinzException $e) {
 		} catch (MinzException $e) {
-			Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
+			try {
+				Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
+			} catch (PermissionDeniedException $e) {
+				$this->killApp ($e->getMessage ());
+			}
 
 
 			if ($e instanceof FileNotExistException ||
 			if ($e instanceof FileNotExistException ||
-			    $e instanceof ControllerNotExistException ||
-			    $e instanceof ControllerNotActionControllerException ||
-			    $e instanceof ActionException) {
+					$e instanceof ControllerNotExistException ||
+					$e instanceof ControllerNotActionControllerException ||
+					$e instanceof ActionException) {
 				Error::error (
 				Error::error (
 					404,
 					404,
 					array ('error' => array ($e->getMessage ())),
 					array ('error' => array ($e->getMessage ())),
@@ -118,6 +122,6 @@ class FrontController {
 		if ($txt == '') {
 		if ($txt == '') {
 			$txt = 'See logs files';
 			$txt = 'See logs files';
 		}
 		}
-		exit ('### Application problem ###'."\n".$txt);
+		exit ('### Application problem ###<br />'."\n".$txt);
 	}
 	}
 }
 }

+ 3 - 6
lib/minz/Minz_Log.php

@@ -65,12 +65,9 @@ class Minz_Log {
 				fwrite ($file, $log); 
 				fwrite ($file, $log); 
 				fclose ($file);
 				fclose ($file);
 			} else {
 			} else {
-				Error::error (
-					500,
-					array ('error' => array (
-						'Permission is denied for `'
-						. $file_name . '`')
-					)
+				throw new PermissionDeniedException (
+					$file_name,
+					MinzException::ERROR
 				);
 				);
 			}
 			}
 		}
 		}

+ 2 - 2
lib/minz/exceptions/MinzException.php

@@ -19,7 +19,7 @@ class MinzException extends Exception {
 class PermissionDeniedException extends MinzException {
 class PermissionDeniedException extends MinzException {
 	public function __construct ($file_name, $code = self::ERROR) {
 	public function __construct ($file_name, $code = self::ERROR) {
 		$message = 'Permission is denied for `' . $file_name.'`';
 		$message = 'Permission is denied for `' . $file_name.'`';
-		
+
 		parent::__construct ($message, $code);
 		parent::__construct ($message, $code);
 	}
 	}
 }
 }
@@ -33,7 +33,7 @@ class FileNotExistException extends MinzException {
 class BadConfigurationException extends MinzException {
 class BadConfigurationException extends MinzException {
 	public function __construct ($part_missing, $code = self::ERROR) {
 	public function __construct ($part_missing, $code = self::ERROR) {
 		$message = '`' . $part_missing
 		$message = '`' . $part_missing
-		         . '` in the configuration file is missing';
+		         . '` in the configuration file is missing or is misconfigured';
 		
 		
 		parent::__construct ($message, $code);
 		parent::__construct ($message, $code);
 	}
 	}

+ 1 - 1
public/index.php

@@ -55,6 +55,6 @@ if (file_exists (PUBLIC_PATH . '/install.php')) {
 		$front_controller->run ();
 		$front_controller->run ();
 	} catch (PDOConnectionException $e) {
 	} catch (PDOConnectionException $e) {
 		Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
 		Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
-		print '### Application problem ###'."\n".'See logs files';
+		print '### Application problem ###<br />'."\n".'See logs files';
 	}
 	}
 }
 }