Browse Source

Write config.ini with quotes - fixes #259

This also updates the installer to save most
config values directly to the database, instead
of relying on Config::importAll to import the
values from config.ini and rewrite the file on
the first run, which never really made sense.

Eventually I plan to implement #215 by replacing
config.ini with a config.php file, which will
work around issues like this more permanently.
Alan Hardman 3 years ago
parent
commit
5a7e4fa188
2 changed files with 33 additions and 43 deletions
  1. 9 9
      app/model/config.php
  2. 24 34
      install.php

+ 9 - 9
app/model/config.php

@@ -38,13 +38,13 @@ class Config extends \Model {
 	 */
 	public static function importAll() {
 		$f3 = \Base::instance();
-		$root = $f3->get('ROOT').$f3->get('BASE');
+		$root = $f3->get("ROOT") . $f3->get("BASE");
 
 		// Import existing config
-		$ini = parse_ini_file($root.'/config.ini');
-		$ini = $ini + parse_ini_file($root.'/config-base.ini');
+		$ini = parse_ini_file($root."/config.ini");
+		$ini = $ini + parse_ini_file($root."/config-base.ini");
 		foreach($ini as $key => $val) {
-			if(substr($key, 0, 3) == 'db.') {
+			if(substr($key, 0, 3) == "db.") {
 				continue;
 			}
 			$conf = new Config;
@@ -55,11 +55,11 @@ class Config extends \Model {
 
 		// Write new config.ini
 		$data = "[globals]\n";
-		$data .= "db.host={$ini['db.host']}\n";
-		$data .= "db.user={$ini['db.user']}\n";
-		$data .= "db.pass={$ini['db.pass']}\n";
-		$data .= "db.name={$ini['db.name']}\n";
-		file_put_contents($root.'/config.ini', $data);
+		$data .= "db.host=\"{$ini['db.host']}\"\n";
+		$data .= "db.user=\"{$ini['db.user']}\"\n";
+		$data .= "db.pass=\"{$ini['db.pass']}\"\n";
+		$data .= "db.name=\"{$ini['db.name']}\"\n";
+		file_put_contents($root . "/config.ini", $data);
 	}
 
 	/**

+ 24 - 34
install.php

@@ -56,7 +56,7 @@ if($_POST) {
 		$security = \Helper\Security::instance();
 		$user = new \Model\User;
 		$user->role = "admin";
-		$user->rank = 5; // superadmin
+		$user->rank = \Model\User::RANK_SUPER;
 		$user->name = "Admin";
 		$user->username = $post["user-username"] ?: "admin";
 		$user->email = $post["user-email"];
@@ -73,42 +73,32 @@ if($_POST) {
 			mkdir("log", 0777, true);
 		}
 
-		// Build custom config string
-		$config = "[globals]";
+		// Save configruation options
 		if(!empty($post["language"])) {
-			$config .= "\nLANGUAGE={$post['language']}";
+			\Model\Config::setVal("LANGUAGE", $post["language"]);
 		}
-
-		if($post["parser"] != "both") {
-			$config .= "\n\n; Parser options";
-			if($post["parser"] != "markdown") {
-				$config .= "\nparse.markdown=false";
-			}
-			if($post["parser"] != "textile") {
-				$config .= "\nparse.textile=false";
-			}
+		if($post["parser"] == "both") {
+			\Model\Config::setVal("parse.markdown", 1);
+			\Model\Config::setVal("parse.textile", 1);
+		} elseif($post["parser"] == "markdown") {
+			\Model\Config::setVal("parse.markdown", 0);
+			\Model\Config::setVal("parse.textile", 1);
+		} elseif($post["parser"] == "textile") {
+			\Model\Config::setVal("parse.markdown", 1);
+			\Model\Config::setVal("parse.textile", 0);
 		}
-
-		// Write configuration file
-		file_put_contents("config.ini",
-"$config
-
-; Database
-db.host={$post['db-host']}
-db.port={$post['db-port']}
-db.user={$post['db-user']}
-db.pass={$post['db-pass']}
-db.name={$post['db-name']}
-
-; Global site configuration
-site.name={$post['site-name']}
-site.timezone={$post['site-timezone']}
-site.public_registration={$post['site-public_registration']}
-site.db_sessions=1
-
-; Email
-mail.from={$post['mail-from']}
-	");
+		\Model\Config::setVal("site.name", $post['site-name']);
+		\Model\Config::setVal("site.timezone", $post['site-timezone']);
+		\Model\Config::setVal("site.public_registration", $post['site-public_registration']);
+		\Model\Config::setVal("mail.from", $post['mail-from']);
+
+		// Write database connection file
+		$data = "[globals]\n";
+		$data .= "db.host=\"{$post['db-host']}\"\n";
+		$data .= "db.user=\"{$post['db-user']}\"\n";
+		$data .= "db.pass=\"{$post['db-pass']}\"\n";
+		$data .= "db.name=\"{$post['db-name']}\"\n";
+		file_put_contents("config.ini", $data);
 
 		$f3->set("success", "Installation complete.");
 	} catch(PDOException $e) {