diff options
author | Cash Costello <cash.costello@gmail.com> | 2012-01-24 20:49:06 -0500 |
---|---|---|
committer | Cash Costello <cash.costello@gmail.com> | 2012-01-24 20:49:06 -0500 |
commit | 54bef9fc0b85acaf6950e618bd02aa50befd2acc (patch) | |
tree | 338179e8632d3b09de532a7aea4278ebc555ed81 /engine | |
parent | be523eb86e6578030e022da4ff2143087a82eb67 (diff) | |
parent | a2cfbdeb100324090ffe19d58aeb71c2def83ac8 (diff) | |
download | elgg-54bef9fc0b85acaf6950e618bd02aa50befd2acc.tar.gz elgg-54bef9fc0b85acaf6950e618bd02aa50befd2acc.tar.bz2 |
Merge pull request #150 from cash/boot
Fixes #4317 cleans up the boot process
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/cache.php | 19 | ||||
-rw-r--r-- | engine/lib/configuration.php | 83 | ||||
-rw-r--r-- | engine/lib/database.php | 27 | ||||
-rw-r--r-- | engine/lib/elgglib.php | 28 | ||||
-rw-r--r-- | engine/lib/languages.php | 2 | ||||
-rw-r--r-- | engine/lib/sessions.php | 10 | ||||
-rw-r--r-- | engine/lib/sites.php | 40 | ||||
-rw-r--r-- | engine/lib/views.php | 2 | ||||
-rw-r--r-- | engine/start.php | 101 |
9 files changed, 129 insertions, 183 deletions
diff --git a/engine/lib/cache.php b/engine/lib/cache.php index e71ef332d..47c3af73c 100644 --- a/engine/lib/cache.php +++ b/engine/lib/cache.php @@ -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 diff --git a/engine/lib/configuration.php b/engine/lib/configuration.php index 144b99fff..cccd69105 100644 --- a/engine/lib/configuration.php +++ b/engine/lib/configuration.php @@ -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,33 +534,47 @@ 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, '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/", ); @@ -571,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; @@ -610,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; +} diff --git a/engine/lib/database.php b/engine/lib/database.php index 444bb7cc4..cc2b99f6a 100644 --- a/engine/lib/database.php +++ b/engine/lib/database.php @@ -189,22 +189,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. * * Database link resources are stored in the {@link $dblink} global. These @@ -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'); diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 5a8c89a56..476408c61 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -2056,6 +2056,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. * * Handles core actions for comments, the JS pagehandler, and the shutdown function. @@ -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); diff --git a/engine/lib/languages.php b/engine/lib/languages.php index 0400843af..80c789ced 100644 --- a/engine/lib/languages.php +++ b/engine/lib/languages.php @@ -311,5 +311,3 @@ function elgg_languages_init() { } elgg_register_event_handler('init', 'system', 'elgg_languages_init'); - -register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/"); diff --git a/engine/lib/sessions.php b/engine/lib/sessions.php index 97a05e2e8..9982d9fe8 100644 --- a/engine/lib/sessions.php +++ b/engine/lib/sessions.php @@ -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); diff --git a/engine/lib/sites.php b/engine/lib/sites.php index 337b2d180..850092cad 100644 --- a/engine/lib/sites.php +++ b/engine/lib/sites.php @@ -231,43 +231,6 @@ function get_site_domain($guid) { } /** - * 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 * * @param sting $hook unit_test @@ -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'); diff --git a/engine/lib/views.php b/engine/lib/views.php index e59edac96..0a7969ae3 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -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'); diff --git a/engine/start.php b/engine/start.php index ee878126f..506e27380 100644 --- a/engine/start.php +++ b/engine/start.php @@ -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. @@ -52,56 +52,35 @@ if (!isset($CONFIG)) { $lib_dir = dirname(__FILE__) . '/lib/'; -/** - * The minimum required libs to bootstrap an Elgg installation. - * - * @var array - */ -$required_files = array( - 'elgglib.php', 'views.php', 'access.php', 'system_log.php', 'export.php', - 'sessions.php', 'languages.php', 'pageowner.php', 'input.php', 'cache.php', - 'output.php' -); - -// include bootstraping libs -foreach ($required_files as $file) { - $path = $lib_dir . $file; - if (!include($path)) { - echo "Could not load file '$path'. " - . 'Please check your Elgg installation for all required files.'; - exit; - } +// Load the bootstrapping library +$path = $lib_dir . 'elgglib.php'; +if (!include_once($path)) { + echo "Could not load file '$path'. Please check your Elgg installation for all required files."; + exit; } -// Register the error handler -set_error_handler('_elgg_php_error_handler'); -set_exception_handler('_elgg_php_exception_handler'); - -/** - * Load the system settings - */ +// Load the system settings if (!include_once(dirname(__FILE__) . "/settings.php")) { - $msg = elgg_echo('InstallationException:CannotLoadSettings'); + $msg = 'Elgg could not load the settings file. It does not exist or there is a file permissions issue.'; throw new InstallationException($msg); } // load the rest of the library files from engine/lib/ $lib_files = array( - // these need to be loaded first. - 'database.php', 'actions.php', - - 'admin.php', 'annotations.php', 'calendar.php', - 'configuration.php', 'cron.php', 'entities.php', 'export.php', - 'extender.php', 'filestore.php', 'group.php', - 'location.php', 'mb_wrapper.php', 'memcache.php', 'metadata.php', - 'metastrings.php', 'navigation.php', 'notification.php', 'objects.php', - 'opendd.php', 'pagehandler.php', 'pam.php', 'plugins.php', - 'private_settings.php', 'relationships.php', 'river.php', 'sites.php', - 'statistics.php', 'tags.php', 'user_settings.php', 'users.php', - 'upgrade.php', 'web_services.php', 'widgets.php', 'xml.php', 'xml-rpc.php', + 'access.php', 'actions.php', 'admin.php', 'annotations.php', 'cache.php', + 'calendar.php', 'configuration.php', 'cron.php', 'database.php', + 'entities.php', 'export.php', 'extender.php', 'filestore.php', 'group.php', + 'input.php', 'languages.php', 'location.php', 'mb_wrapper.php', + 'memcache.php', 'metadata.php', 'metastrings.php', 'navigation.php', + 'notification.php', 'objects.php', 'opendd.php', 'output.php', + 'pagehandler.php', 'pageowner.php', 'pam.php', 'plugins.php', + 'private_settings.php', 'relationships.php', 'river.php', 'sessions.php', + 'sites.php', 'statistics.php', 'system_log.php', 'tags.php', + 'user_settings.php', 'users.php', 'upgrade.php', 'views.php', + 'web_services.php', 'widgets.php', 'xml.php', 'xml-rpc.php', - //backwards compatibility + // backward compatibility 'deprecated-1.7.php', 'deprecated-1.8.php', ); @@ -109,48 +88,22 @@ foreach ($lib_files as $file) { $file = $lib_dir . $file; elgg_log("Loading $file..."); if (!include_once($file)) { - $msg = sprintf(elgg_echo('InstallationException:MissingLibrary'), $file); + $msg = "Could not load $file"; throw new InstallationException($msg); } } -// 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'); |