aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2012-01-24 20:49:06 -0500
committerCash Costello <cash.costello@gmail.com>2012-01-24 20:49:06 -0500
commit54bef9fc0b85acaf6950e618bd02aa50befd2acc (patch)
tree338179e8632d3b09de532a7aea4278ebc555ed81 /engine/lib
parentbe523eb86e6578030e022da4ff2143087a82eb67 (diff)
parenta2cfbdeb100324090ffe19d58aeb71c2def83ac8 (diff)
downloadelgg-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/lib')
-rw-r--r--engine/lib/cache.php19
-rw-r--r--engine/lib/configuration.php83
-rw-r--r--engine/lib/database.php27
-rw-r--r--engine/lib/elgglib.php28
-rw-r--r--engine/lib/languages.php2
-rw-r--r--engine/lib/sessions.php10
-rw-r--r--engine/lib/sites.php40
-rw-r--r--engine/lib/views.php2
8 files changed, 102 insertions, 109 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');