From 0f2e67985d80ad91cd000e33d6e8a7751121d370 Mon Sep 17 00:00:00 2001 From: marcus Date: Tue, 17 Jun 2008 16:49:21 +0000 Subject: CLOSED - #34: Install process must be completely graphical http://trac.elgg.org/elgg/ticket/34 git-svn-id: https://code.elgg.org/elgg/trunk@951 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 25 +++++++++++++++++----- engine/lib/input.php | 9 +++++--- engine/lib/install.php | 23 ++++++++++++++++++++ engine/settings.example.php | 10 ++++----- engine/start.php | 51 +++++++++++++++++++++++++++++++++------------ 5 files changed, 92 insertions(+), 26 deletions(-) (limited to 'engine') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 1c4d02138..af48a2200 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -514,14 +514,29 @@ $sanitised = true; - if (!file_exists(dirname(dirname(__FILE__)) . "/settings.php")) { - register_error(elgg_view("messages/sanitisation/settings")); - $sanitised = false; + if (!file_exists(dirname(dirname(__FILE__)) . "/settings.php")) { + // See if we are being asked to save the file + $save_vars = get_input('db_install_vars'); + $result = ""; + if ($save_vars) + { + $result = create_settings($save_vars, dirname(dirname(__FILE__)) . "/settings.example.php"); + + if (file_put_contents(dirname(dirname(__FILE__)) . "/settings.php", $result)) + $result = ""; // blank result to stop it being displayed in textarea + + } + + // Recheck to see if the file is still missing + if (!file_exists(dirname(dirname(__FILE__)) . "/settings.php")) { + register_error(elgg_view("messages/sanitisation/settings", array('settings.php' => $result))); + $sanitised = false; + } } if (!file_exists(dirname(dirname(dirname(__FILE__))) . "/.htaccess")) { if (!@copy(dirname(dirname(dirname(__FILE__))) . "/htaccess_dist", dirname(dirname(dirname(__FILE__))) . "/.htaccess")) { - register_error(elgg_view("messages/sanitisation/htaccess")); + register_error(elgg_view("messages/sanitisation/htaccess", array('.htaccess' => file_get_contents(dirname(dirname(dirname(__FILE__))) . "/htaccess_dist")))); $sanitised = false; } } @@ -899,7 +914,7 @@ error_log("*** FATAL EXCEPTION *** : " . $exception); $body = elgg_view("messages/exceptions/exception",array('object' => $exception)); - echo page_draw("We've encountered a problem.", $body); + echo page_draw(elgg_echo('exception:title'), $body); } diff --git a/engine/lib/input.php b/engine/lib/input.php index 9244c16f3..f42aa7a25 100644 --- a/engine/lib/input.php +++ b/engine/lib/input.php @@ -20,9 +20,12 @@ function get_input($variable, $default = "") { - if (isset($_REQUEST[$variable])) { - $value = $_REQUEST[$variable]; - return trim($_REQUEST[$variable]); + if (isset($_REQUEST[$variable])) { + + if (is_array($_REQUEST[$variable])) + return $_REQUEST[$variable]; + else + return trim($_REQUEST[$variable]); } global $CONFIG; diff --git a/engine/lib/install.php b/engine/lib/install.php index 16f000ee7..b348ab9b2 100644 --- a/engine/lib/install.php +++ b/engine/lib/install.php @@ -38,6 +38,29 @@ return datalist_get('installed'); } + + /** + * Copy and create a new settings.php from settings.example.php, substituting the variables in + * $vars where appropriate. + * + * $vars is an associate array of $key => $value, where $key is the variable text you wish to substitute (eg + * CONFIG_DBNAME will replace {{CONFIG_DBNAME}} in the settings file. + * + * @param array $vars The array of vars + * @param string $in_file Optional input file (if not settings.example.php) + * @return string The file containing substitutions. + */ + function create_settings(array $vars, $in_file="engine/settings.example.php") + { + $file = file_get_contents($in_file); + + if (!$file) return false; + + foreach ($vars as $k => $v) + $file = str_replace("{{".$k."}}", $v, $file); + + return $file; + } /** * Initialisation for installation functions diff --git a/engine/settings.example.php b/engine/settings.example.php index 6d947a8ba..94b6d5f37 100644 --- a/engine/settings.example.php +++ b/engine/settings.example.php @@ -24,22 +24,22 @@ */ // Database username - $CONFIG->dbuser = ""; + $CONFIG->dbuser = "{{CONFIG_DBUSER}}"; // Database password - $CONFIG->dbpass = ""; + $CONFIG->dbpass = "{{CONFIG_DBPASS}}"; // Database name - $CONFIG->dbname = ""; + $CONFIG->dbname = "{{CONFIG_DBNAME}}"; // Database server // (For most configurations, you can leave this as 'localhost') - $CONFIG->dbhost = "localhost"; + $CONFIG->dbhost = "{{CONFIG_DBHOST}}"; // Database table prefix // If you're sharing a database with other applications, you will want to use this // to differentiate Elgg's tables. - $CONFIG->dbprefix = "elgg"; + $CONFIG->dbprefix = "{{CONFIG_DBPREFIX}}"; /* * Multiple database connections diff --git a/engine/start.php b/engine/start.php index 4682e35b2..ac8d186de 100644 --- a/engine/start.php +++ b/engine/start.php @@ -11,6 +11,8 @@ * @copyright Curverider Ltd 2008 * @link http://elgg.org/ */ + + /** * Load important prerequisites @@ -22,20 +24,38 @@ } if (!@include_once(dirname(__FILE__) . "/lib/elgglib.php")) { // Main Elgg library - throw new InstallationException("Elgg could not load its main library."); + echo "Elgg could not load its main library."; + exit; } if (!@include_once(dirname(__FILE__) . "/lib/system_log.php")) { // Logging library - throw new InstallationException("Error in installation: could not load the System Log library."); + echo "Error in installation: could not load the System Log library."; + exit; } if (!@include_once(dirname(__FILE__) . "/lib/export.php")) { // Export library - throw new InstallationException("Error in installation: could not load the Export library."); + echo "Error in installation: could not load the Export library."; + exit; } - if (!@include_once(dirname(__FILE__) . "/lib/languages.php")) { // Main Elgg library - throw new InstallationException("Error in installation: could not load the languages library."); - } + if (!@include_once(dirname(__FILE__) . "/lib/languages.php")) { // Languages library + echo "Error in installation: could not load the languages library."; + exit; + } + + if (!@include_once(dirname(__FILE__) . "/lib/input.php")) { // Input library + echo "Error in installation: could not load the input library."; + exit; + } + + if (!@include_once(dirname(__FILE__) . "/lib/install.php")) { // Installation library + echo "Error in installation: could not load the installation library."; + exit; + } + + // Use fallback view until sanitised + $oldview = get_input('view'); + set_input('view', 'failsafe'); /** * Set light mode default @@ -118,21 +138,23 @@ load_plugins(); } else { // End portion for sanitised installs only - - throw new InstallationException("Once you've corrected any configuration issues, press reload to try again."); + + throw new InstallationException(elgg_echo('installation:error:configuration')); } // Autodetect some default configuration settings - set_default_config(); + set_default_config(); + // Trigger events - trigger_elgg_event('boot', 'system'); + trigger_elgg_event('boot', 'system'); + // Forward if we haven't been installed if ((!is_installed() || !is_db_installed()) && !substr_count($_SERVER["PHP_SELF"],"install.php") && !substr_count($_SERVER["PHP_SELF"],"action_handler.php")) { header("Location: install.php"); exit; - } - + } + // Trigger events if (!substr_count($_SERVER["PHP_SELF"],"install.php") && !substr_count($_SERVER["PHP_SELF"],"setup.php") && @@ -143,5 +165,8 @@ //forward("setup.php"); } } - + + + // System booted, return to normal view + set_input('view', $oldview); ?> \ No newline at end of file -- cgit v1.2.3