From 22ee0127205da3470c97222e6ae0f1f13c86b074 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 9 Jan 2009 18:33:48 +0000 Subject: Stage 1 of the installer. basically check that we can start as far as Kohana correctly --- core/helpers/module.php | 26 +++--- index.php | 14 ++- installer/controllers/installer.php | 80 ++++++++++++++++ installer/helpers/system_check.php | 180 ++++++++++++++++++++++++++++++++++++ installer/views/installer.html.php | 48 ++++++++++ installer/views/installer.txt.2.php | 119 ++++++++++++++++++++++++ installer/views/installer.txt.php | 44 +++++++++ 7 files changed, 494 insertions(+), 17 deletions(-) create mode 100644 installer/controllers/installer.php create mode 100644 installer/helpers/system_check.php create mode 100644 installer/views/installer.html.php create mode 100644 installer/views/installer.txt.2.php create mode 100644 installer/views/installer.txt.php diff --git a/core/helpers/module.php b/core/helpers/module.php index 4b98674e..de81c0bb 100644 --- a/core/helpers/module.php +++ b/core/helpers/module.php @@ -1,3 +1,4 @@ + find_all(); - } catch (Exception $e) { + // Check that we are installed. If not then head over to the installer. + $installed = Kohana::config("gallery.installed", false, false); + if (empty($installed)) { + $kohana_modules[] = DOCROOT . "installer"; + Kohana::config_set('core.modules', $kohana_modules); + $routes = Kohana::config("routes"); + $routes["_default"] = "installer"; + Kohana::config_set("routes", $routes); return; } - restore_error_handler(); + self::$module_names = array(); + self::$modules = array(); + + $modules = ORM::factory("module")->find_all(); try { foreach ($modules as $module) { diff --git a/index.php b/index.php index cec905a1..b1f9eccb 100644 --- a/index.php +++ b/index.php @@ -45,6 +45,14 @@ define('MODPATH', strtr(realpath('modules') . '/', DIRECTORY_SEPARATOR, '/')); define('THEMEPATH', strtr(realpath('themes') . '/', DIRECTORY_SEPARATOR, '/')); define('SYSPATH', strtr(realpath('kohana') . '/', DIRECTORY_SEPARATOR, '/')); +if (!file_exists('var')) { + include DOCROOT . "installer/helpers/system_check.php"; + if (system_check::failed()) { + system_check::display_requirements(); + die; + } +} + // Force a test run if we're in command line mode. if (PHP_SAPI == 'cli') { array_splice($_SERVER['argv'], 1, 0, 'gallery_unit_test'); @@ -54,11 +62,7 @@ if (PHP_SAPI == 'cli') { @copy("var/database.php", VARPATH . "database.php"); } else { define('TEST_MODE', 0); - if (file_exists('var')) { - define('VARPATH', strtr(realpath('var') . '/', DIRECTORY_SEPARATOR, '/')); - } else { - define('VARPATH', strtr(getcwd() . '/var/', DIRECTORY_SEPARATOR, '/')); - } + define('VARPATH', strtr(realpath('var') . '/', DIRECTORY_SEPARATOR, '/')); } // Initialize. diff --git a/installer/controllers/installer.php b/installer/controllers/installer.php new file mode 100644 index 00000000..9c9491b7 --- /dev/null +++ b/installer/controllers/installer.php @@ -0,0 +1,80 @@ +template->syscheck = new View("install.html"); + $this->template->syscheck->errors = $this->_get_config_errors(); + $this->template->syscheck->modules = array(); + } + + private function _get_config_errors() { + $errors = array(); + if (!file_exists(VARPATH)) { + $error = new stdClass(); + $error->message = "Missing: " . VARPATH; + $error->instructions[] = "mkdir " . VARPATH; + $error->instructions[] = "chmod 777 " . VARPATH; + $errors[] = $error; + } else if (!is_writable(VARPATH)) { + $error = new stdClass(); + $error->message = "Not writable: " . VARPATH; + $error->instructions[] = "chmod 777 " . VARPATH; + $errors[] = $error; + } + + $db_php = VARPATH . "database.php"; + if (!file_exists($db_php)) { + $error = new stdClass(); + $error->message = "Missing: $db_php
Run the following commands..."; + $error->instructions[] = "cp " . DOCROOT . "kohana/config/database.php $db_php"; + $error->instructions[] = "chmod 644 $db_php"; + $error->message2 = "...then edit this file and enter your database configuration settings."; + $errors[] = $error; + } else if (!is_readable($db_php)) { + $error = new stdClass(); + $error->message = "Not readable: $db_php"; + $error->instructions[] = "chmod 644 $db_php"; + $error->message2 = "Then edit this file and enter your database configuration settings."; + $errors[] = $error; + } else { + $old_handler = set_error_handler(array("Welcome_Controller", "_error_handler")); + try { + Database::instance()->connect(); + } catch (Exception $e) { + $error = new stdClass(); + $error->message = "Database error: {$e->getMessage()}"; + $db_name = Kohana::config("database.default.connection.database"); + if (strchr($error->message, "Unknown database")) { + $error->instructions[] = "mysqladmin -uroot create $db_name"; + } else { + $error->instructions = array(); + $error->message2 = "Check " . VARPATH . "database.php"; + } + $errors[] = $error; + } + set_error_handler($old_handler); + } + + return $errors; + } + +} \ No newline at end of file diff --git a/installer/helpers/system_check.php b/installer/helpers/system_check.php new file mode 100644 index 00000000..b0bd7e12 --- /dev/null +++ b/installer/helpers/system_check.php @@ -0,0 +1,180 @@ + true, + "text" => sprintf("Gallery3 requires PHP 5.2 or newer, current version: %s.", PHP_VERSION)); + $failed = true; + } else { + self::$messages["PHP Version"] = array("error" => false, + "text" => PHP_VERSION); + } + + + if (!(is_dir(SYSPATH) AND is_file(SYSPATH.'core/Bootstrap'.EXT))) { + self::$messages["Kohana Directory"] = array("error" => true, + "text" => "The configured Kohana directory does not exist or does not contain the required files."); + } else { + self::$messages["Kohana Directory"] = array("error" => false, + "text" => SYSPATH); + } + + if (!(is_dir(APPPATH) AND is_file(APPPATH.'config/config'.EXT))) { + self::$messages["Application Directory"] = array("error" => true, + "text" => "The configured Gallery3 application directory does not exist or does not contain the required files."); + $failed = true; + } else { + self::$messages["Application Directory"] = array("error" => false, + "text" => APPPATH); + } + + if (!(is_dir(MODPATH))) { + self::$messages["Modules Directory"] = array("error" => true, + "text" => "The configured Gallery3 modules directory does not exist or does not contain the required files."); + $failed = true; + } else { + self::$messages["Modules Directory"] = array("error" => false, + "text" => MODPATH); + } + + if (!(is_dir(THEMEPATH))) { + self::$messages["Theme Directory"] = array("error" => true, + "text" => "The configured Gallery3 themes directory does not exist or does not contain the required files."); + $failed = true; + } else { + self::$messages["Themes Directory"] = array("error" => false, + "text" => THEMEPATH); + } + + if (!@preg_match("/^.$/u", utf8_encode("\xF1"))) { + self::$messages["PCRE UTF-8"] = array("error" => true, + "text" => "Perl-Compatible Regular Expressions has not been compiled with UTF-8 support.", + "html" => "PCRE has not been compiled with UTF-8 support."); + $failed = true; + } else if (!@preg_match("/^\pL$/u", utf8_encode("\xF1"))) { + self::$messages["PCRE UTF-8"] = array("error" => true, + "text" => "Perl-Compatible Regular Expressions has not been compiled with Unicode support.", + "html" => "PCRE has not been compiled with Unicode property support."); + $failed = true; + } else { + self::$messages["PCRE UTF-8"] = array("error" => false, + "text" => "Pass"); + } + + if (!(class_exists("ReflectionClass"))) { + self::$messages["Reflection Enabled"] = array("error" => true, + "text" => "PHP relection is either not loaded or not compiled in.", + "html" => "PHP relection is either not loaded or not compiled in."); + $failed = true; + } else { + self::$messages["Reflection Enabled"] = array("error" => false, + "text" => "Pass"); + } + + if (!(function_exists("filter_list"))) { + self::$messages["Filters Enabled"] = array("error" => true, + "text" => "The filter extension is either not loaded or not compiled in.", + "html" => "The filter extension is either not loaded or not compiled in."); + $failed = true; + } else { + self::$messages["Filters Enabled"] = array("error" => false, + "text" => "Pass"); + } + + if (!(extension_loaded("iconv"))) { + self::$messages["Iconv Loaded"] = array("error" => true, + "text" => "The iconv extension is not loaded.", + "html" => "The iconv extension is not loaded."); + $failed = true; + } else { + self::$messages["Iconv Enabled"] = array("error" => false, + "text" => "Pass"); + } + + if (extension_loaded("mbstring") && + (ini_get("mbstring.func_overload") & MB_OVERLOAD_STRING)) { + self::$messages["Mbstring Overloaded"] = array("error" => true, + "text" => "The mbstring extension is overloading PHP's native string functions.", + "html" => "The mbstring extension is overloading PHP's native string functions."); + $failed = true; + } else { + self::$messages["MbString Overloaded"] = array("error" => false, + "text" => "Pass"); + } + + if (!(isset($_SERVER["REQUEST_URI"]) || isset($_SERVER["PHP_SELF"]))) { + self::$messages["URI Determination"] = array("error" => true, + "text" => "Neither \$_SERVER['REQUEST_URI'] or \$_SERVER['PHP_SELF'] is available.", + "html" => "Neither \$_SERVER['REQUEST_URI'] or \$_SERVER['PHP_SELF'] is available."); + $failed = true; + } else { + self::$messages["URI Determination"] = array("error" => false, + "text" => "Pass"); + } + + $short_tags = ini_get("short_open_tag"); + if (empty($short_tags)) { + self::$messages["Short Tags"] = array("error" => true, + "text" => "Gallery3 requires that PHP short tags be enabled.", + "html" => "Gallery3 requires that PHP short tags be enabled"); + $failed = true; + } else { + self::$messages["Short Tags"] = array("error" => false, + "text" => "Pass"); + } + return $failed; + } + + public static function display_requirements() { + if (PHP_SAPI == 'cli') { + print self::_render("installer/views/installer.txt"); + } else { + print self::_render("installer/views/installer.html"); + } + } + + private static function _render($view) { + if ($view == '') + return; + + // Buffering on + ob_start(); + + try + { + // Views are straight HTML pages with embedded PHP, so importing them + // this way insures that $this can be accessed as if the user was in + // the controller, which gives the easiest access to libraries in views + include realpath($view . EXT); + } + catch (Exception $e) + { + // Display the exception using its internal __toString method + echo $e; + } + + // Fetch the output and close the buffer + return ob_get_clean(); + } +} \ No newline at end of file diff --git a/installer/views/installer.html.php b/installer/views/installer.html.php new file mode 100644 index 00000000..fef71834 --- /dev/null +++ b/installer/views/installer.html.php @@ -0,0 +1,48 @@ + + + + + + + + Gallery3 Requirements Verification + + + + + +

Environment Tests

+ +

The following tests have been run to determine if Gallery3 will work in your environment. If any of the tests have failed, consult the + documentation for more information on how to correct the problem.

+ +
+ + + $msg): ?> + + + + + + +
"> + +
+
+ + \ No newline at end of file diff --git a/installer/views/installer.txt.2.php b/installer/views/installer.txt.2.php new file mode 100644 index 00000000..b40373c0 --- /dev/null +++ b/installer/views/installer.txt.2.php @@ -0,0 +1,119 @@ +PHP Version // // + // // // + // // // + // // // + // // // + // Gallery3 requires PHP 5.2 or newer, this version is . // // + // // // + // // // + // // // + // System Directory // // + // // // + // // // + // // // + // The configured system directory does not exist or does not contain required files. // // + // // // + // // // + // // // + // Application Directory // // + // // // + // // // + // // // + // The configured application directory does not exist or does not contain required files. // // + // // // + // // // + // // // + // Modules Directory // // + // // // + // // // + // // // + // The configured modules directory does not exist or does not contain required files. // // + // // // + // // // + // // // + // PCRE UTF-8 // // + // // // + // PCRE has not been compiled with UTF-8 support. // // + // // // + // PCRE has not been compiled with Unicode property support. // // + // // // + // Pass // // + // // // + // // // + // // // + // Reflection Enabled // // + // // // + // Pass // // + // // // + // PHP reflection is either not loaded or not compiled in. // // + // // // + // // // + // // // + // Filters Enabled // // + // // // + // Pass // // + // // // + // The filter extension is either not loaded or not compiled in. // // + // // // + // // // + // // // + // Iconv Extension Loaded // // + // // // + // Pass // // + // // // + // The iconv extension is not loaded. // // + // // // + // // // + // // // + // // // + // Mbstring Not Overloaded // // + // // // + // Pass // // + // // // + // The mbstring extension is overloading PHP's native string functions. // // + // // // + // // // + // // // + // URI Determination // // + // // // + // Pass // // + // // // + // Neither $_SERVER['REQUEST_URI'] or $_SERVER['PHP_SELF'] is available. // // + // // // + // // // + // // // + // PHP Short Tags // // + // // // + // Pass // // + // // // + // Gallery3 needs php short tags enabled. // // + // // // + // // // + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + diff --git a/installer/views/installer.txt.php b/installer/views/installer.txt.php new file mode 100644 index 00000000..5c98752f --- /dev/null +++ b/installer/views/installer.txt.php @@ -0,0 +1,44 @@ + $msg) { + print_msg($header, $msg["text"], $msg["error"]); +} + +echo "+", str_repeat("-", 98), "+\n"; +flush(); \ No newline at end of file -- cgit v1.2.3