From 96031d570093d321dab15d5a7ceec899af0fa7e5 Mon Sep 17 00:00:00 2001 From: marcus Date: Fri, 22 May 2009 16:33:19 +0000 Subject: Refs #965: Allowing upgrades to be loaded from other locations. git-svn-id: https://code.elgg.org/elgg/trunk@3301 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/database.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'engine/lib/database.php') diff --git a/engine/lib/database.php b/engine/lib/database.php index 9db5cf37c..4aa879920 100644 --- a/engine/lib/database.php +++ b/engine/lib/database.php @@ -515,23 +515,36 @@ } } - - function db_upgrade($version) { + + /** + * Upgrade the database schema in an ordered sequence. + * + * Makes use of schema upgrade files + * + * This is a about as core as it comes, so don't start running this from your plugins! + * + * @param int $version The version you are upgrading from (usually given in the Elgg version format of YYYYMMDDXX - see version.php for example) + * @param string $fromdir Optional directory to load upgrades from (default: engine/schema/upgrades/) + * @return bool + */ + function db_upgrade($version, $fromdir = "") { global $CONFIG; // Elgg and its database must be installed to upgrade it! - if (!is_db_installed() || !is_installed()) return false; + if (!is_db_installed() || !is_installed()) return false; - $version = (int) $version; + $version = (int) $version; + if (!$fromdir) + $fromdir = $CONFIG->path . 'engine/schema/upgrades/'; - if ($handle = opendir($CONFIG->path . 'engine/schema/upgrades/')) { + if ($handle = opendir($fromdir)) { $sqlupgrades = array(); while ($sqlfile = readdir($handle)) { - if (!is_dir($CONFIG->path . 'engine/schema/upgrades/' . $sqlfile)) { + if (!is_dir($fromdir . $sqlfile)) { if (preg_match('/([0-9]*)\.sql/',$sqlfile,$matches)) { $sql_version = (int) $matches[1]; if ($sql_version > $version) { @@ -546,7 +559,7 @@ if (sizeof($sqlupgrades) > 0) { foreach($sqlupgrades as $sqlfile) { try { - run_sql_script($CONFIG->path . 'engine/schema/upgrades/' . $sqlfile); + run_sql_script($fromdir . $sqlfile); } catch (DatabaseException $e) { error_log($e->getmessage()); } -- cgit v1.2.3