aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/database.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib/database.php')
-rw-r--r--engine/lib/database.php47
1 files changed, 46 insertions, 1 deletions
diff --git a/engine/lib/database.php b/engine/lib/database.php
index a071a4f6f..f1b4a5871 100644
--- a/engine/lib/database.php
+++ b/engine/lib/database.php
@@ -400,7 +400,11 @@
$statement = trim($statement);
$statement = str_replace("prefix_",$CONFIG->dbprefix,$statement);
if (!empty($statement)) {
- $result = update_data($statement);
+ try {
+ $result = update_data($statement);
+ } catch (DatabaseException $e) {
+ $errors[] = $e->getMessage();
+ }
}
}
if (!empty($errors)) {
@@ -414,6 +418,47 @@
throw new DatabaseException(sprintf(elgg_echo('DatabaseException:ScriptNotFound'), $scriptlocation));
}
+ }
+
+ function db_upgrade($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/schema/upgrades/')) {
+
+ $sqlupgrades = array();
+
+ while ($sqlfile = readdir($handle)) {
+
+ if (!is_dir($CONFIG->path . 'engine/schema/upgrades/' . $sqlfile)) {
+ if (preg_match('/([0-9]*)\.sql/',$sqlfile,$matches)) {
+ $sql_version = (int) $matches[1];
+ if ($sql_version > $version) {
+ $sqlupgrades[] = $sqlfile;
+ }
+ }
+ }
+
+ }
+
+ asort($sqlupgrades);
+ if (sizeof($sqlupgrades) > 0) {
+ foreach($sqlupgrades as $sqlfile) {
+ try {
+ run_sql_script($CONFIG->path . 'engine/schema/upgrades/' . $sqlfile);
+ } catch (DatabaseException $e) {
+ error_log($e->getmessage());
+ }
+ }
+ }
+
+ }
+
}
/**