From b3bf72d0faa76ffe3bb62141fca55d4decec19cf Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 24 Apr 2008 13:19:32 +0000 Subject: The beginnings of a db upgrade system. See lib/version.php, /version.php and the datalist functions in elgglib.php. git-svn-id: https://code.elgg.org/elgg/trunk@519 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 41 ++++++++++++++++++++++++++++++++++++++++- engine/lib/version.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ engine/schema/mysql.sql | 29 ++++++++++++++++++----------- version.php | 22 ++++++++++++++++++++++ 4 files changed, 129 insertions(+), 12 deletions(-) create mode 100644 engine/lib/version.php create mode 100644 version.php diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 2f9396da1..78afe49ce 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -812,12 +812,51 @@ */ function __elgg_php_exception_handler($exception) { - + error_log("*** FATAL EXCEPTION *** : " . $exception); $body = elgg_view("messages/exceptions/exception",array('object' => $exception)); echo page_draw("We've encountered a problem.", $body); } + + /** + * Data lists + */ + + /** + * Get the value of a particular piece of data in the datalist + * + * @param string $name The name of the datalist + * @return string|false Depending on success + */ + function datalist_get($name) { + + global $CONFIG; + $name = sanitise_string($name); + if ($row = get_data_row("select value from {$CONFIG->prefix}datalists where name = '{$name}'")) { + return $row->value; + } + return false; + + } + + /** + * Sets the value for a system-wide piece of data (overwriting a previous value if it exists) + * + * @param string $name The name of the datalist + * @param string $value The new value + * @return true + */ + function datalist_set($name, $value) { + + global $CONFIG; + $name = sanitise_string($name); + $value = sanitise_string($value); + delete_data("delete from {$CONFIG->prefix}datalists where name = '{$name}'"); + insert_data("insert into {$CONFIG->prefix}datalists set name = '{$name}', value = '{$value}'"); + return true; + + } ?> \ No newline at end of file diff --git a/engine/lib/version.php b/engine/lib/version.php new file mode 100644 index 000000000..ee707ca1d --- /dev/null +++ b/engine/lib/version.php @@ -0,0 +1,49 @@ +path . "version.php")) { + if ($humanreadable) return $version; + return $release; + } + + return false; + + } + + /** + * Determines whether or not the database needs to be upgraded. + * + * @return true|false Depending on whether or not the db version matches the code version + */ + function db_upgrade_check() { + + $dbversion = (int) get_datalist('version'); + $version = get_version(); + + if ($version > $dbversion) { + return true; + } + return false; + + } + +?> \ No newline at end of file diff --git a/engine/schema/mysql.sql b/engine/schema/mysql.sql index ae5dbe033..f037ac32c 100644 --- a/engine/schema/mysql.sql +++ b/engine/schema/mysql.sql @@ -43,7 +43,7 @@ CREATE TABLE `prefix_entity_subtypes` ( PRIMARY KEY (`id`), UNIQUE KEY (`type`, `subtype`) -) ENGINE=MyISAM; +) ; -- Describe relationships between entities, can describe friendships but also site membership, depending on context CREATE TABLE `prefix_entity_relationships` ( @@ -54,7 +54,7 @@ CREATE TABLE `prefix_entity_relationships` ( `guid_two` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY (`guid_one`,`relationship`,`guid_two`) -) ENGINE=MyISAM ; +) ; -- -- *** Access controls *** @@ -68,7 +68,7 @@ CREATE TABLE `prefix_access_groups` ( `site_guid` bigint(20) unsigned NOT NULL default '0', PRIMARY KEY (`id`), KEY `name` (`name`) -) ENGINE=MyISAM ; +) ; -- Dumping data for table `access_groups` INSERT INTO `prefix_access_groups` (`id`, `name`, `site_guid`) VALUES @@ -81,7 +81,7 @@ CREATE TABLE `prefix_access_group_membership` ( `user_guid` int(11) NOT NULL, `access_group_id` int(11) NOT NULL, PRIMARY KEY (`user_guid`,`access_group_id`) -) ENGINE=MyISAM ; +) ; -- @@ -97,7 +97,7 @@ CREATE TABLE `prefix_objects_entity` ( `description` text NOT NULL, PRIMARY KEY (`guid`) -) ENGINE=MyISAM ; +) ; -- Extra information relating to "sites" CREATE TABLE `prefix_sites_entity` ( @@ -109,7 +109,7 @@ CREATE TABLE `prefix_sites_entity` ( PRIMARY KEY (`guid`), UNIQUE KEY (`url`) -) ENGINE=MyISAM ; +) ; -- Extra information relating to "users" CREATE TABLE `prefix_users_entity` ( @@ -131,7 +131,7 @@ CREATE TABLE `prefix_users_entity` ( PRIMARY KEY (`guid`), KEY `password` (`password`), FULLTEXT KEY `name` (`name`) -) ENGINE=MyISAM ; +) ; -- TODO: Collection @@ -157,7 +157,7 @@ CREATE TABLE `prefix_annotations` ( `time_created` int(11) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM; +) ; -- Table structure for metadata CREATE TABLE `prefix_metadata` ( @@ -176,7 +176,7 @@ CREATE TABLE `prefix_metadata` ( PRIMARY KEY (`id`) -) ENGINE=MyISAM; +) ; -- Meta strings table (avoids storing text strings more than once) CREATE TABLE `prefix_metastrings` ( @@ -185,7 +185,7 @@ CREATE TABLE `prefix_metastrings` ( PRIMARY KEY (`id`), UNIQUE KEY (`string`) -) ENGINE=MyISAM; +) ; -- -- *** Misc *** @@ -217,5 +217,12 @@ CREATE TABLE `prefix_users_apisessions` ( PRIMARY KEY (`id`), UNIQUE KEY (`user_guid`,`site_guid`) -) ENGINE=MyISAM; +) ; + +-- Datalists for things like db version +CREATE TABLE `prefix_datalists` ( + `name` varchar(16) NOT NULL, + `value` text NOT NULL, + KEY `name` (`name`) +); diff --git a/version.php b/version.php new file mode 100644 index 000000000..3b4b203f4 --- /dev/null +++ b/version.php @@ -0,0 +1,22 @@ + \ No newline at end of file -- cgit v1.2.3