Commit 34ad5e7b authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Added check to ignore files when searching for upgrades. Perform upgrades

in a transaction (however MySQL doesn't support DDL in transactions...).

Fixed load_config to check for value set in the config file instead of the
database properly.

Added a couple of XMLDB helper functions to prevent fatal errors and enable
logging.
parent 17c6a9f4
......@@ -77,7 +77,7 @@ function check_upgrades($name = null) {
//if (strpos($name, 'artefact.') === 0) {
// $plugins[] = substr($name, 9);
//}
if (!empty($name) && $name != 'core') {
if (!empty($name)) {
$plugins[] = explode('.', $name);
}
else {
......@@ -90,6 +90,9 @@ function check_upgrades($name = null) {
if (!empty($installing) && $dir != 'internal') {
continue;
}
if (!is_dir(get_config('docroot') . $plugin . '/' . $dir)) {
continue;
}
$plugins[] = array($plugin, $dir);
}
}
......@@ -150,9 +153,11 @@ function check_upgrades($name = null) {
}
function upgrade_core($upgrade) {
global $db;
$location = get_config('libroot') . '/db/';
$db->StartTrans();
if (!empty($upgrade->install)) {
$status = install_from_xmldb_file($location . 'install.xml');
}
......@@ -166,18 +171,25 @@ function upgrade_core($upgrade) {
$status = set_config('version', $upgrade->to);
$status = $status && set_config('release', $upgrade->torelease);
if ($db->HasFailedTrans()) {
$status = false;
}
$db->CompleteTrans();
return $status;
}
function upgrade_plugin($upgrade) {
global $db;
$plugintype = '';
$pluginname = '';
list($plugintype, $pluginname) = explode('.', $upgrade->name);
log_dbg($plugintype . ' ' . $pluginname);
$location = get_config('dirroot') . $plugintype . '/' . $pluginname . '/db/';
$db->StartTrans();
if (!empty($upgrade->install)) {
// @todo add to installed_artefacts
......@@ -196,7 +208,8 @@ function upgrade_plugin($upgrade) {
$status = $function($upgrade->from);
}
if (!$status) {
if (!$status || $db->HasFailedTrans()) {
$db->CompleteTrans();
throw new DatalibException("Failed to upgrade $upgrade->name");
}
......@@ -205,6 +218,11 @@ function upgrade_plugin($upgrade) {
// @todo here is where plugins register events and set their crons up
if ($db->HasFailedTrans()) {
$status = false;
}
$db->CompleteTrans();
return $status;
}
......@@ -448,7 +466,7 @@ function load_config() {
}
foreach ($dbconfig as $cfg) {
if (isset($CFG->{$cfg->field}) && $CFG->{$cfg->field} != $CFG->value) {
if (isset($CFG->{$cfg->field}) && $CFG->{$cfg->field} != $cfg->value) {
// @todo warn that we're overriding db config with $CFG
continue;
}
......@@ -691,4 +709,15 @@ function safe_require($plugintype, $pluginname, $filename, $function='require',
}
/**
* Used by XMLDB
*/
function debugging ($message, $level) {
log_dbg($message);
}
function xmldb_dbg($message) {
log_warn($message);
}
define('DEBUG_DEVELOPER', 'whocares');
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment