Permalink
Browse files

Merge branch 'w06_MDL-26219_20_upgradelog' of git://github.com/skodak…

…/moodle
  • Loading branch information...
2 parents 20ba9a2 + bb8b297 commit 8fc84ff1c1f60c91c0ec51562005894aab6c84e2 @stronk7 stronk7 committed Feb 7, 2011
Showing with 74 additions and 33 deletions.
  1. +4 −3 lib/db/install.xml
  2. +17 −0 lib/db/upgrade.php
  3. +52 −29 lib/upgradelib.php
  4. +1 −1 version.php
View
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20110125" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20110206" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@@ -50,8 +50,9 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="type"/>
<FIELD NAME="type" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="false" COMMENT="type: 0==info, 1==notice, 2==error" PREVIOUS="id" NEXT="plugin"/>
<FIELD NAME="plugin" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" PREVIOUS="type" NEXT="version"/>
- <FIELD NAME="version" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" COMMENT="plugin or main version if known" PREVIOUS="plugin" NEXT="info"/>
- <FIELD NAME="info" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="version" NEXT="details"/>
+ <FIELD NAME="version" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" COMMENT="plugin or main version if known" PREVIOUS="plugin" NEXT="targetversion"/>
+ <FIELD NAME="targetversion" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" COMMENT="version of plugin or core specified in version.php at the time of upgrade loggging" PREVIOUS="version" NEXT="info"/>
+ <FIELD NAME="info" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="targetversion" NEXT="details"/>
<FIELD NAME="details" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="info" NEXT="backtrace"/>
<FIELD NAME="backtrace" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="details" NEXT="userid"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="backtrace" NEXT="timemodified"/>
View
@@ -74,6 +74,7 @@ function xmldb_main_upgrade($oldversion) {
$table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null);
$table->add_field('version', XMLDB_TYPE_CHAR, '100', null, null, null, null);
+ $table->add_field('targetversion', XMLDB_TYPE_CHAR, '100', null, null, null, null);
$table->add_field('info', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('details', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
$table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
@@ -6005,6 +6006,22 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2011012501);
}
+ if ($oldversion < 2011020200.01) {
+
+ // Define field targetversion to be added to upgrade_log
+ $table = new xmldb_table('upgrade_log');
+ $field = new xmldb_field('targetversion', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'version');
+
+ // Conditionally launch add field targetversion
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // Main savepoint reached
+ upgrade_main_savepoint(true, 2011020200.01);
+ }
+
+
return true;
}
View
@@ -987,11 +987,8 @@ function upgrade_handle_exception($ex, $plugin = null) {
/**
* Adds log entry into upgrade_log table
*
- * @global object
- * @global object
- * @global object
* @param int $type UPGRADE_LOG_NORMAL, UPGRADE_LOG_NOTICE or UPGRADE_LOG_ERROR
- * @param string $plugin plugin or null if main
+ * @param string $plugin frankenstyle component name
* @param string $info short description text of log entry
* @param string $details long problem description
* @param string $backtrace string used for errors only
@@ -1000,54 +997,80 @@ function upgrade_handle_exception($ex, $plugin = null) {
function upgrade_log($type, $plugin, $info, $details=null, $backtrace=null) {
global $DB, $USER, $CFG;
- $plugin = ($plugin==='moodle') ? null : $plugin;
+ if (empty($plugin)) {
+ $plugin = 'core';
+ }
+
+ list($plugintype, $pluginname) = normalize_component($plugin);
+ $component = is_null($pluginname) ? $plugintype : $plugintype . '_' . $pluginname;
$backtrace = format_backtrace($backtrace, true);
- $version = null;
+ $currentversion = null;
+ $targetversion = null;
//first try to find out current version number
- if (empty($plugin) or $plugin === 'moodle') {
+ if ($plugintype === 'core') {
//main
- $version = $CFG->version;
+ $currentversion = $CFG->version;
- } else if ($plugin === 'local') {
- //customisation
- $version = $CFG->local_version;
+ $version = null;
+ include("$CFG->dirroot/version.php");
+ $targetversion = $version;
- } else if (strpos($plugin, 'mod/') === 0) {
+ } else if ($plugintype === 'mod') {
try {
- $modname = substr($plugin, strlen('mod/'));
- $version = $DB->get_field('modules', 'version', array('name'=>$modname));
- $version = ($version === false) ? null : $version;
+ $currentversion = $DB->get_field('modules', 'version', array('name'=>$pluginname));
+ $currentversion = ($currentversion === false) ? null : $currentversion;
} catch (Exception $ignored) {
}
+ $cd = get_component_directory($component);
+ if (file_exists("$cd/version.php")) {
+ $module = new stdClass();
+ $module->version = null;
+ include("$cd/version.php");
+ $targetversion = $module->version;
+ }
- } else if (strpos($plugin, 'block/') === 0) {
+ } else if ($plugintype === 'block') {
try {
- $blockname = substr($plugin, strlen('block/'));
- if ($block = $DB->get_record('block', array('name'=>$blockname))) {
- $version = $block->version;
+ if ($block = $DB->get_record('block', array('name'=>$pluginname))) {
+ $currentversion = $block->version;
}
} catch (Exception $ignored) {
}
+ $cd = get_component_directory($component);
+ if (file_exists("$cd/version.php")) {
+ $plugin = new stdClass();
+ $plugin->version = null;
+ include("$cd/version.php");
+ $targetversion = $plugin->version;
+ }
} else {
- $pluginversion = get_config(str_replace('/', '_', $plugin), 'version');
+ $pluginversion = get_config($component, 'version');
if (!empty($pluginversion)) {
- $version = $pluginversion;
+ $currentversion = $pluginversion;
+ }
+ $cd = get_component_directory($component);
+ if (file_exists("$cd/version.php")) {
+ $plugin = new stdClass();
+ $plugin->version = null;
+ include("$cd/version.php");
+ $targetversion = $plugin->version;
}
}
$log = new stdClass();
- $log->type = $type;
- $log->plugin = $plugin;
- $log->version = $version;
- $log->info = $info;
- $log->details = $details;
- $log->backtrace = $backtrace;
- $log->userid = $USER->id;
- $log->timemodified = time();
+ $log->type = $type;
+ $log->plugin = $component;
+ $log->version = $currentversion;
+ $log->targetversion = $targetversion;
+ $log->info = $info;
+ $log->details = $details;
+ $log->backtrace = $backtrace;
+ $log->userid = $USER->id;
+ $log->timemodified = time();
try {
$DB->insert_record('upgrade_log', $log);
} catch (Exception $ignored) {
View
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2011020200; // YYYYMMDD = date of the last version bump
+$version = 2011020200.01; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0.1+ (Build: 20110204)'; // Human-friendly version name

0 comments on commit 8fc84ff

Please sign in to comment.