]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
CLI installer: manual enable/auto disable, checking for empty config values
authorSteve Clay <steve@mrclay.org>
Sat, 13 Oct 2012 02:05:20 +0000 (22:05 -0400)
committerSteve Clay <steve@mrclay.org>
Sat, 13 Oct 2012 02:05:20 +0000 (22:05 -0400)
install/ElggInstaller.php
install/cli/sample_installer.php

index 03c84a43e1bd073a9d830c6f28cb80c09942095a..934b38d28f1afd20663331e67b2c8550447bcaf0 100644 (file)
@@ -157,7 +157,7 @@ class ElggInstaller {
                        'password',
                );
                foreach ($requiredParams as $key) {
-                       if (!array_key_exists($key, $params)) {
+                       if (empty($params[$key])) {
                                $msg = elgg_echo('install:error:requiredfield', array($key));
                                throw new InstallationException($msg);
                        }
index 954169a6aae6e3a61f991c94cde3345ae6fc27ce..0bae0cd23f1b5a2b9587ac2ee43441ca29baa268 100644 (file)
@@ -3,10 +3,27 @@
  * Sample cli installer script
  */
 
+$enabled = false;
+
+// Do not edit below this line. //////////////////////////////
+
+
+if (!$enabled) {
+       echo "To enable this script, change \$enabled to true.\n";
+       echo "You *must* disable this script after a successful installation.\n";
+       exit;
+}
+
+if (PHP_SAPI !== 'cli') {
+       echo "You must use the command line to run this script.";
+       exit;
+}
+
 require_once(dirname(dirname(__FILE__)) . "/ElggInstaller.php");
 
 $installer = new ElggInstaller();
 
+// none of the following may be empty
 $params = array(
        // database parameters
        'dbuser' => '',
@@ -28,3 +45,21 @@ $params = array(
 
 // install and create the .htaccess file
 $installer->batchInstall($params, TRUE);
+
+// at this point installation has completed (otherwise an exception halted execution).
+
+// try to rewrite the script to disable it.
+if (is_writable(__FILE__)) {
+       $code = file_get_contents(__FILE__);
+       if (preg_match('~\\$enabled\\s*=\\s*(true|1)\\s*;~i', $code)) {
+               // looks safe to rewrite
+               $code = preg_replace('~\\$enabled\\s*=\\s*(true|1)\\s*;~i', '$enabled = false;', $code);
+               file_put_contents(__FILE__, $code);
+
+               echo "\nNote: This script has been disabled for your safety.\n";
+               exit;
+       }
+}
+
+echo "\nWarning: You *must* disable this script by setting \$enabled = false;.\n";
+echo "Leaving this script enabled could endanger your installation.\n";