From 1c9fafbf3b817ae6fb038c1f25f9e4fd817df929 Mon Sep 17 00:00:00 2001 From: marcus Date: Tue, 7 Oct 2008 11:38:32 +0000 Subject: Closes #409: PHP update script to update core added git-svn-id: https://code.elgg.org/elgg/trunk@2208 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/version.php | 65 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 4 deletions(-) (limited to 'engine/lib/version.php') diff --git a/engine/lib/version.php b/engine/lib/version.php index 58f3cbde6..4799b1a85 100644 --- a/engine/lib/version.php +++ b/engine/lib/version.php @@ -9,7 +9,58 @@ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 * @copyright Curverider Ltd 2008 * @link http://elgg.org/ - */ + */ + + /** + * Run any php upgrade scripts which are required + * + * @param unknown_type $version + */ + function upgrade_code($version) + { + global $CONFIG; + + // Elgg and its database must be installed to upgrade it! + if (!is_db_installed() || !is_installed()) return false; + + $version = (int) $version; + + if ($handle = opendir($CONFIG->path . 'engine/lib/upgrades/')) { + + $upgrades = array(); + + while ($updatefile = readdir($handle)) { + + // Look for upgrades and add to upgrades list + if (!is_dir($CONFIG->path . 'engine/lib/upgrades/' . $updatefile)) { + if (preg_match('/([0-9]*)\.php/',$updatefile,$matches)) { + $core_version = (int) $matches[1]; + if ($core_version > $version) { + $upgrades[] = $updatefile; + } + } + } + + } + + // Sort and execute + asort($upgrades); + if (sizeof($upgrades) > 0) { + foreach($upgrades as $upgrade) { + try { + @include($CONFIG->path . 'engine/lib/upgrades/' . $upgrade); + } catch (Exception $e) { + error_log($e->getmessage()); + } + + } + } + + return true; + } + + return false; + } /** * Get the current version information @@ -53,11 +104,17 @@ function version_upgrade() { $dbversion = (int) datalist_get('version'); + + // Upgrade database db_upgrade($dbversion); + system_message(elgg_echo('upgrade:db')); + + // Upgrade core + if (upgrade_code($dbversion)) + system_message(elgg_echo('upgrade:core')); + + // Update the version datalist_set('version', get_version()); - system_message(elgg_echo('upgrade:db')); - //forward(); - //exit; } -- cgit v1.2.3