]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
cleans up the boot process
authorCash Costello <cash.costello@gmail.com>
Sat, 21 Jan 2012 15:44:47 +0000 (10:44 -0500)
committerCash Costello <cash.costello@gmail.com>
Sat, 21 Jan 2012 15:44:47 +0000 (10:44 -0500)
engine/lib/cache.php
engine/lib/configuration.php
engine/lib/database.php
engine/lib/elgglib.php
engine/lib/languages.php
engine/lib/sessions.php
engine/lib/sites.php
engine/lib/views.php
engine/start.php

index e71ef332d13df7d01093d475e13191d1e23ad6ec..47c3af73c7efbaf1feed6fffb497cfe569453929 100644 (file)
@@ -352,3 +352,22 @@ function elgg_invalidate_simplecache() {
 
        return $return;
 }
+
+function elgg_cache_init() {
+       $viewtype = elgg_get_viewtype();
+
+       // Regenerate the simple cache if expired.
+       // Don't do it on upgrade because upgrade does it itself.
+       // @todo - move into function and perhaps run off init system event
+       if (!defined('UPGRADING')) {
+               $lastupdate = datalist_get("simplecache_lastupdate_$viewtype");
+               $lastcached = datalist_get("simplecache_lastcached_$viewtype");
+               if ($lastupdate == 0 || $lastcached < $lastupdate) {
+                       elgg_regenerate_simplecache($viewtype);
+                       $lastcached = datalist_get("simplecache_lastcached_$viewtype");
+               }
+               $CONFIG->lastcache = $lastcached;
+       }
+}
+
+elgg_register_event_handler('ready', 'system', 'elgg_cache_init');
\ No newline at end of file
index 12ca665bfd66eb8104a537414d94e8a8466e4b4d..cccd69105b5559bfdb865a9645dec6c86098fb8e 100644 (file)
@@ -518,10 +518,10 @@ function get_all_config($site_guid = 0) {
        $site_guid = (int) $site_guid;
 
        if ($site_guid == 0) {
-               $site_guid = (int) $CONFIG->site_id;
+               $site_guid = (int) $CONFIG->site_guid;
        }
 
-       if ($result = get_data("SELECT * from {$CONFIG->dbprefix}config where site_guid = {$site_guid}")) {
+       if ($result = get_data("SELECT * FROM {$CONFIG->dbprefix}config WHERE site_guid = $site_guid")) {
                foreach ($result as $r) {
                        $name = $r->name;
                        $value = $r->value;
@@ -534,37 +534,49 @@ function get_all_config($site_guid = 0) {
 }
 
 /**
- * Sets defaults for or attempts to autodetect some common config values and
- * loads them into $CONFIG.
+ * Loads configuration related to this site
  *
- * @return true
+ * This loads from the config database table and the site entity
  * @access private
  */
-function set_default_config() {
+function _elgg_load_site_config() {
        global $CONFIG;
 
-       $install_root = str_replace("\\", "/", dirname(dirname(dirname(__FILE__))));
-
-       // @todo this seldom works right.
-       $pathpart = str_replace("//", "/", str_replace($_SERVER['DOCUMENT_ROOT'], "", $install_root));
-       if (substr($pathpart, 0, 1) != "/") {
-               $pathpart = "/" . $pathpart;
+       $CONFIG->site_guid = (int) datalist_get('default_site');
+       $CONFIG->site_id = $CONFIG->site_guid;
+       $CONFIG->site = get_entity($CONFIG->site_guid);
+       if (!$CONFIG->site) {
+               throw new InstallationException(elgg_echo('InstallationException:SiteNotInstalled'));
        }
-       $www_root = "http://" . $_SERVER['HTTP_HOST'] . $pathpart;
 
+       $CONFIG->wwwroot = $CONFIG->site->url;
+       $CONFIG->sitename = $CONFIG->site->name;
+       $CONFIG->sitedescription = $CONFIG->site->description;
+       $CONFIG->siteemail = $CONFIG->site->email;
+       $CONFIG->url = $CONFIG->wwwroot;
+
+       get_all_config();
+}
+
+/**
+ * Loads configuration related to Elgg as an application
+ *
+ * This loads from the datalists database table
+ * @access private
+ */
+function _elgg_load_application_config() {
+       global $CONFIG;
+
+       $install_root = str_replace("\\", "/", dirname(dirname(dirname(__FILE__))));
        $defaults = array(
                'path'                  =>      "$install_root/",
                'view_path'             =>      "$install_root/views/",
                'plugins_path'  =>      "$install_root/mod/",
-               'wwwroot'               =>      $www_root,
-               'url'                   =>      $www_root,
-               'site_name'             =>      'New Elgg site',
                'language'              =>      'en',
 
-               // compatibility with old names for ppl not using get_config()
+               // compatibility with old names for plugins not using elgg_get_config()
                'viewpath'              =>      "$install_root/views/",
                'pluginspath'   =>      "$install_root/mod/",
-               'sitename'              =>      'New Elgg site',
        );
 
        foreach ($defaults as $name => $value) {
@@ -573,25 +585,6 @@ function set_default_config() {
                }
        }
 
-       $CONFIG->context = array();
-
-       return true;
-}
-
-/**
- * Loads values into $CONFIG.
- *
- * If Elgg is installed, this function pulls all rows from dbprefix_config
- * and cherry picks some values from dbprefix_datalists.  This also extracts
- * some commonly used values from the default site object.
- *
- * @elgg_event boot system
- * @return true|null
- * @access private
- */
-function configuration_boot() {
-       global $CONFIG;
-
        $path = datalist_get('path');
        if (!empty($path)) {
                $CONFIG->path = $path;
@@ -612,16 +605,12 @@ function configuration_boot() {
        } else {
                $CONFIG->viewpath_cache_enabled = 1;
        }
-       if (isset($CONFIG->site) && ($CONFIG->site instanceof ElggSite)) {
-               $CONFIG->wwwroot = $CONFIG->site->url;
-               $CONFIG->sitename = $CONFIG->site->name;
-               $CONFIG->sitedescription = $CONFIG->site->description;
-               $CONFIG->siteemail = $CONFIG->site->email;
-       }
-       $CONFIG->url = $CONFIG->wwwroot;
 
-       // Load default settings from database
-       get_all_config();
-}
+       // initialize context here so it is set before the get_input call
+       $CONFIG->context = array();
 
-elgg_register_event_handler('boot', 'system', 'configuration_boot', 10);
+       // needs to be set before system, init for links in html head
+       $viewtype = get_input('view', 'default');
+       $lastcached = datalist_get("simplecache_lastcached_$viewtype");
+       $CONFIG->lastcache = $lastcached;
+}
index 444bb7cc4b3e535ec7df04406cc4440b3ec8be81..cc2b99f6ac43c9c088555e26306f684ba4e3cdac 100644 (file)
@@ -188,22 +188,6 @@ function db_delayedexecution_shutdown_hook() {
        }
 }
 
-/**
- * Registers shutdown functions for database profiling and delayed queries.
- *
- * @note Database connections are established upon first call to database.
- *
- * @return true
- * @elgg_event_handler boot system
- * @access private
- */
-function init_db() {
-       register_shutdown_function('db_delayedexecution_shutdown_hook');
-       register_shutdown_function('db_profiling_shutdown_hook');
-
-       return true;
-}
-
 /**
  * Returns (if required, also creates) a database link resource.
  *
@@ -757,6 +741,13 @@ function sanitize_int($int, $signed = true) {
 }
 
 /**
- * @elgg_register_event boot system init_db
+ * Registers shutdown functions for database profiling and delayed queries.
+ *
+ * @access private
  */
-elgg_register_event_handler('boot', 'system', 'init_db', 0);
+function init_db() {
+       register_shutdown_function('db_delayedexecution_shutdown_hook');
+       register_shutdown_function('db_profiling_shutdown_hook');
+}
+
+elgg_register_event_handler('init', 'system', 'init_db');
index 38ae73d82b6762d473ef75b9bc9b7ddf5e6bb806..98e7af2a97c66458f9041697e64a7f9d34c8646f 100644 (file)
@@ -2055,6 +2055,33 @@ function elgg_walled_garden() {
        }
 }
 
+/**
+ * Boots the engine
+ *
+ * 1. sets error handlers
+ * 2. connects to database
+ * 3. verifies the installation suceeded
+ * 4. loads application configuration
+ * 5. loads site configuration
+ *
+ * @access private
+ */
+function _elgg_engine_boot() {
+       // Register the error handlers
+       set_error_handler('_elgg_php_error_handler');
+       set_exception_handler('_elgg_php_exception_handler');
+
+       register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/");
+
+       setup_db_connections();
+
+       verify_installation();
+
+       _elgg_load_application_config();
+
+       _elgg_load_site_config();
+}
+
 /**
  * Elgg's main init.
  *
@@ -2178,6 +2205,7 @@ define('REFERRER', -1);
 define('REFERER', -1);
 
 elgg_register_event_handler('init', 'system', 'elgg_init');
+elgg_register_event_handler('boot', 'system', '_elgg_engine_boot', 1);
 elgg_register_plugin_hook_handler('unit_test', 'system', 'elgg_api_test');
 
 elgg_register_event_handler('init', 'system', 'add_custom_menu_items', 1000);
index 207fe4c99aa00033cea1202f3fc73856cb299110..80c789cedd51f659d8340f7c35d6086b655c288a 100644 (file)
@@ -301,14 +301,6 @@ function get_missing_language_keys($language) {
        return false;
 }
 
-/**
- * Load translations
- * @access private
- */
-function elgg_language_boot() {
-       register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/");
-}
-
 /**
  * Initialize the language library
  * @access private
@@ -318,5 +310,4 @@ function elgg_languages_init() {
        elgg_register_simplecache_view("cache/js/languages/$lang");
 }
 
-elgg_register_event_handler('boot', 'system', 'elgg_language_boot', 1);
 elgg_register_event_handler('init', 'system', 'elgg_languages_init');
index 97a05e2e8afa295fe984bedb424448d8b49210cf..9982d9fe8f42e065337645bbdf6b66ab22caea95 100644 (file)
@@ -355,7 +355,7 @@ function logout() {
        session_destroy();
 
        // starting a default session to store any post-logout messages.
-       session_init(NULL, NULL, NULL);
+       _elgg_session_boot(NULL, NULL, NULL);
        $_SESSION['msg'] = $old_msg;
 
        return TRUE;
@@ -379,7 +379,7 @@ function logout() {
  * @return bool
  * @access private
  */
-function session_init($event, $object_type, $object) {
+function _elgg_session_boot($event, $object_type, $object) {
        global $DB_PREFIX, $CONFIG;
 
        // Use database for sessions
@@ -444,8 +444,8 @@ function session_init($event, $object_type, $object) {
                set_last_action($_SESSION['guid']);
        }
 
-       elgg_register_action("login", '', 'public');
-       elgg_register_action("logout");
+       elgg_register_action('login', '', 'public');
+       elgg_register_action('logout');
 
        // Register a default PAM handler
        register_pam_handler('pam_auth_userpass');
@@ -655,4 +655,4 @@ function _elgg_session_gc($maxlifetime) {
        return true;
 }
 
-elgg_register_event_handler("boot", "system", "session_init", 20);
+elgg_register_event_handler('boot', 'system', '_elgg_session_boot', 2);
index 337b2d180056355de0db9a66e07223a26c028a34..850092cada234023ce5efdafbb2b77c1d6d7371b 100644 (file)
@@ -230,43 +230,6 @@ function get_site_domain($guid) {
        return false;
 }
 
-/**
- * Initialise site handling
- *
- * Called at the beginning of system running, to set the ID of the current site.
- * This is 0 by default, but plugins may alter this behaviour by attaching functions
- * to the sites init event and changing $CONFIG->site_id.
- *
- * @uses $CONFIG
- *
- * @param string $event       Event API required parameter
- * @param string $object_type Event API required parameter
- * @param null   $object      Event API required parameter
- *
- * @return true
- * @access private
- */
-function sites_boot($event, $object_type, $object) {
-       global $CONFIG;
-
-       $site = elgg_trigger_plugin_hook("siteid", "system");
-       if ($site === null || $site === false) {
-               $CONFIG->site_id = (int) datalist_get('default_site');
-       } else {
-               $CONFIG->site_id = $site;
-       }
-       $CONFIG->site_guid = $CONFIG->site_id;
-       $CONFIG->site = get_entity($CONFIG->site_guid);
-
-       return true;
-}
-
-// Register event handlers
-elgg_register_event_handler('boot', 'system', 'sites_boot', 2);
-
-// Register with unit test
-elgg_register_plugin_hook_handler('unit_test', 'system', 'sites_test');
-
 /**
  * Unit tests for sites
  *
@@ -283,3 +246,6 @@ function sites_test($hook, $type, $value, $params) {
        $value[] = "{$CONFIG->path}engine/tests/objects/sites.php";
        return $value;
 }
+
+// Register with unit test
+elgg_register_plugin_hook_handler('unit_test', 'system', 'sites_test');
index e59edac9604afea22f9652f4e1f2464aea7a659c..0a7969ae3578077a2e13790f176169b7a01780e0 100644 (file)
@@ -1671,5 +1671,5 @@ function elgg_views_boot() {
        }
 }
 
-elgg_register_event_handler('boot', 'system', 'elgg_views_boot', 1000);
+elgg_register_event_handler('boot', 'system', 'elgg_views_boot');
 elgg_register_event_handler('init', 'system', 'elgg_views_handle_deprecated_views');
index b4f9d6fdaa444f4dc06a3ba00279deb441f6020c..506e273806afa671ea79d19508d323964bb1e18e 100644 (file)
@@ -1,12 +1,12 @@
 <?php
 /**
- * Bootstraps and starts the Elgg engine.
+ * Bootstraps the Elgg engine.
  *
  * This file loads the full Elgg engine, checks the installation
- * state, then emits a series of events to finish booting Elgg:
+ * state, and triggers a series of events to finish booting Elgg:
  *     - {@elgg_event boot system}
- *     - {@elgg_event plugins_boot system}
  *     - {@elgg_event init system}
+ *     - {@elgg_event ready system}
  *
  * If Elgg is fully uninstalled, the browser will be redirected to an
  * installation page.
@@ -93,47 +93,17 @@ foreach ($lib_files as $file) {
        }
 }
 
-// Register the error handler
-set_error_handler('_elgg_php_error_handler');
-set_exception_handler('_elgg_php_exception_handler');
-
-// connect to db
-setup_db_connections();
-
-// confirm that the installation completed successfully
-verify_installation();
-
-// Autodetect some default configuration settings
-set_default_config();
-
-// needs to be set for links in html head
-$viewtype = get_input('view', 'default');
-$lastcached = datalist_get("simplecache_lastcached_$viewtype");
-$CONFIG->lastcache = $lastcached;
-
-// Trigger boot events for core. Plugins can't hook
-// into this because they haven't been loaded yet.
+// Connect to database, load language files, load configuration, init session
+// Plugins can't use this event because they haven't been loaded yet.
 elgg_trigger_event('boot', 'system');
 
 // Load the plugins that are active
 elgg_load_plugins();
+// @todo deprecate as plugins can use 'init', 'system' event
 elgg_trigger_event('plugins_boot', 'system');
 
-// Trigger system init event for plugins
+// Complete the boot process for both engine and plugins
 elgg_trigger_event('init', 'system');
 
-// Regenerate the simple cache if expired.
-// Don't do it on upgrade because upgrade does it itself.
-// @todo - move into function and perhaps run off init system event
-if (!defined('UPGRADING')) {
-       $lastupdate = datalist_get("simplecache_lastupdate_$viewtype");
-       $lastcached = datalist_get("simplecache_lastcached_$viewtype");
-       if ($lastupdate == 0 || $lastcached < $lastupdate) {
-               elgg_regenerate_simplecache($viewtype);
-               $lastcached = datalist_get("simplecache_lastcached_$viewtype");
-       }
-       $CONFIG->lastcache = $lastcached;
-}
-
 // System loaded and ready
 elgg_trigger_event('ready', 'system');