}\r
\r
}\r
- \r
- function db_upgrade($version) {\r
+
+ /**
+ * 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
+ */\r
+ function db_upgrade($version, $fromdir = "") {\r
\r
global $CONFIG;\r
\r
// Elgg and its database must be installed to upgrade it!\r
- if (!is_db_installed() || !is_installed()) return false;\r
+ if (!is_db_installed() || !is_installed()) return false;
\r
- $version = (int) $version;\r
+ $version = (int) $version;
+ if (!$fromdir)
+ $fromdir = $CONFIG->path . 'engine/schema/upgrades/';\r
\r
- if ($handle = opendir($CONFIG->path . 'engine/schema/upgrades/')) {\r
+ if ($handle = opendir($fromdir)) {\r
\r
$sqlupgrades = array();\r
\r
while ($sqlfile = readdir($handle)) {\r
\r
- if (!is_dir($CONFIG->path . 'engine/schema/upgrades/' . $sqlfile)) {\r
+ if (!is_dir($fromdir . $sqlfile)) {\r
if (preg_match('/([0-9]*)\.sql/',$sqlfile,$matches)) {\r
$sql_version = (int) $matches[1];\r
if ($sql_version > $version) {\r
if (sizeof($sqlupgrades) > 0) {\r
foreach($sqlupgrades as $sqlfile) {\r
try {\r
- run_sql_script($CONFIG->path . 'engine/schema/upgrades/' . $sqlfile);\r
+ run_sql_script($fromdir . $sqlfile);\r
} catch (DatabaseException $e) {\r
error_log($e->getmessage());\r
}\r