Sfoglia il codice sorgente

config.php plutôt que application.ini

Implémente https://github.com/marienfressinaud/FreshRSS/issues/272
Alexandre Alapetite 12 anni fa
parent
commit
415d7a5a71
4 ha cambiato i file con 48 aggiunte e 43 eliminazioni
  1. 1 0
      data/.gitignore
  2. 2 6
      lib/Minz/Configuration.php
  3. 1 1
      public/index.php
  4. 44 36
      public/install.php

+ 1 - 0
data/.gitignore

@@ -1,4 +1,5 @@
 application.ini
+config.php
 *_user.php
 *.sqlite
 touch.txt

+ 2 - 6
lib/Minz/Configuration.php

@@ -8,7 +8,7 @@
  * La classe Configuration permet de gérer la configuration de l'application
  */
 class Minz_Configuration {
-	const CONF_PATH_NAME = '/application.ini';
+	const CONF_PATH_NAME = '/config.php';
 
 	/**
 	 * VERSION est la version actuelle de MINZ
@@ -126,10 +126,7 @@ class Minz_Configuration {
 			);
 		}
 
-		$ini_array = parse_ini_file (
-			DATA_PATH . self::CONF_PATH_NAME,
-			true
-		);
+		$ini_array = include(DATA_PATH . self::CONF_PATH_NAME);
 
 		if (!$ini_array) {
 			throw new Minz_PermissionDeniedException (
@@ -147,7 +144,6 @@ class Minz_Configuration {
 		}
 		$general = $ini_array['general'];
 
-
 		// sel_application est obligatoire
 		if (!isset ($general['sel_application'])) {
 			throw new Minz_BadConfigurationException (

+ 1 - 1
public/index.php

@@ -29,7 +29,7 @@ if (file_exists ('install.php')) {
 		$dateLastModification = max(
 			@filemtime(DATA_PATH . '/touch.txt'),
 			@filemtime(LOG_PATH . '/application.log'),
-			@filemtime(DATA_PATH . '/application.ini')
+			@filemtime(DATA_PATH . '/config.php')
 		);
 		$_SERVER['QUERY_STRING'] .= '&utime=' . file_get_contents(DATA_PATH . '/touch.txt');	//For ETag
 		if (httpConditional($dateLastModification, 0, 0, false, false, true)) {

+ 44 - 36
public/install.php

@@ -261,23 +261,29 @@ function saveStep3 () {
 		$_SESSION['bd_prefix'] = addslashes ($_POST['prefix']);
 		$_SESSION['bd_prefix_user'] = $_SESSION['bd_prefix'] . (empty($_SESSION['default_user']) ? '' : ($_SESSION['default_user'] . '_'));
 
-		$file_conf = DATA_PATH . '/application.ini';
-		$f = fopen ($file_conf, 'w');
-		writeLine ($f, '[general]');
-		writeLine ($f, 'environment = "' . empty($_SESSION['environment']) ? 'production' : $_SESSION['environment'] . '"');
-		writeLine ($f, 'use_url_rewriting = false');
-		writeLine ($f, 'sel_application = "' . $_SESSION['sel_application'] . '"');
-		writeLine ($f, 'base_url = ""');
-		writeLine ($f, 'title = "' . $_SESSION['title'] . '"');
-		writeLine ($f, 'default_user = "' . $_SESSION['default_user'] . '"');
-		writeLine ($f, '[db]');
-		writeLine ($f, 'type = "' . $_SESSION['bd_type'] . '"');
-		writeLine ($f, 'host = "' . $_SESSION['bd_host'] . '"');
-		writeLine ($f, 'user = "' . $_SESSION['bd_user'] . '"');
-		writeLine ($f, 'password = "' . $_SESSION['bd_password'] . '"');
-		writeLine ($f, 'base = "' . $_SESSION['bd_base'] . '"');
-		writeLine ($f, 'prefix = "' . $_SESSION['bd_prefix'] . '"');
-		fclose ($f);
+		$ini_array = array(
+			'general' => array(
+				'environment' => empty($_SESSION['environment']) ? 'production' : $_SESSION['environment'],
+				'use_url_rewriting' => false,
+				'sel_application' => $_SESSION['sel_application'],
+				'base_url' => '',
+				'title' => $_SESSION['title'],
+				'default_user' => $_SESSION['default_user'],
+			),
+			'db' => array(
+				'type' => $_SESSION['bd_type'],
+				'host' => $_SESSION['bd_host'],
+				'user' => $_SESSION['bd_user'],
+				'password' => $_SESSION['bd_password'],
+				'base' => $_SESSION['bd_base'],
+				'prefix' => $_SESSION['bd_prefix'],
+			),
+		);
+		file_put_contents(DATA_PATH . '/config.php', "<?php\n return " . var_export($ini_array, true));
+
+		if (file_exists(DATA_PATH . '/config.php') && file_exists(DATA_PATH . '/application.ini')) {
+			@unlink(DATA_PATH . '/application.ini');	//v0.6
+		}
 
 		$res = checkBD ();
 
@@ -474,25 +480,27 @@ function checkStep () {
 function checkStep0 () {
 	moveOldFiles() && removeOldFiles();
 
-	if (file_exists(DATA_PATH . '/application.ini')) {
+	if (file_exists(DATA_PATH . '/config.php')) {
+		$ini_array = include(DATA_PATH . '/config.php');
+	elseif (file_exists(DATA_PATH . '/application.ini')) {
 		$ini_array = parse_ini_file(DATA_PATH . '/application.ini', true);
-		if ($ini_array) {
-			$ini_general = isset($ini_array['general']) ? $ini_array['general'] : null;
-			if ($ini_general) {
-				$keys = array('environment', 'sel_application', 'title', 'default_user');
-				foreach ($keys as $key) {
-					if ((empty($_SESSION[$key])) && isset($ini_general[$key])) {
-						$_SESSION[$key] = $ini_general[$key];
-					}
+	}
+	if ($ini_array) {
+		$ini_general = isset($ini_array['general']) ? $ini_array['general'] : null;
+		if ($ini_general) {
+			$keys = array('environment', 'sel_application', 'title', 'default_user');
+			foreach ($keys as $key) {
+				if ((empty($_SESSION[$key])) && isset($ini_general[$key])) {
+					$_SESSION[$key] = $ini_general[$key];
 				}
 			}
-			$ini_db = isset($ini_array['db']) ? $ini_array['db'] : null;
-			if ($ini_db) {
-				$keys = array('type', 'host', 'user', 'password', 'base', 'prefix');
-				foreach ($keys as $key) {
-					if ((!isset($_SESSION['bd_' . $key])) && isset($ini_db[$key])) {
-						$_SESSION['bd_' . $key] = $ini_db[$key];
-					}
+		}
+		$ini_db = isset($ini_array['db']) ? $ini_array['db'] : null;
+		if ($ini_db) {
+			$keys = array('type', 'host', 'user', 'password', 'base', 'prefix');
+			foreach ($keys as $key) {
+				if ((!isset($_SESSION['bd_' . $key])) && isset($ini_db[$key])) {
+					$_SESSION['bd_' . $key] = $ini_db[$key];
 				}
 			}
 		}
@@ -569,7 +577,7 @@ function checkStep2 () {
 	);
 }
 function checkStep3 () {
-	$conf = file_exists (DATA_PATH . '/application.ini');
+	$conf = file_exists (DATA_PATH . '/config.php');
 
 	$bd = isset ($_SESSION['bd_type']) &&
 	      isset ($_SESSION['bd_host']) &&
@@ -651,8 +659,8 @@ function checkBD () {
 		$error = true;
 	}
 
-	if ($error && file_exists (DATA_PATH . '/application.ini')) {
-		unlink (DATA_PATH . '/application.ini');
+	if ($error && file_exists (DATA_PATH . '/config.php')) {
+		unlink (DATA_PATH . '/config.php');
 	}
 
 	return !$error;