From 6346dda358f409c9dda062010c518e7aba4faa53 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Thu, 24 Jul 2008 05:28:56 +0000 Subject: [PATCH] MDL-14650, fix the problem of upgrade script --- mod/chat/db/upgrade.php | 68 +++++++++++++++-------------------------- mod/chat/version.php | 2 +- 2 files changed, 26 insertions(+), 44 deletions(-) diff --git a/mod/chat/db/upgrade.php b/mod/chat/db/upgrade.php index 6f63201b40..284e69c84a 100644 --- a/mod/chat/db/upgrade.php +++ b/mod/chat/db/upgrade.php @@ -25,54 +25,36 @@ function xmldb_chat_upgrade($oldversion=0) { $result = true; - if ($result && $oldversion < 2007101510) { + if ($result && $oldversion < 2008072400) { - /// Define field id to be added to chat_messages_current + /// Define table chat_messages_current to be created $table = new xmldb_table('chat_messages_current'); - $field = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null); - $table->addField($field); - - $field = new xmldb_field('chatid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0', 'id'); - $table->addField($field); - - $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0', 'chatid'); - $table->addField($field); - - $field = new xmldb_field('groupid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0', 'userid'); - $table->addField($field); - - $field = new xmldb_field('system', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'groupid'); - $table->addField($field); - - $field = new xmldb_field('message', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null, 'system'); - $table->addField($field); - - $field = new xmldb_field('timestamp', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'message'); - $table->addField($field); - - $key = new xmldb_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->addKey($key); - - $key = new xmldb_key('chatid', XMLDB_KEY_FOREIGN, array('chatid'), 'chat', array('id')); - $table->addKey($key); - - $result = $result && $dbman->create_table($table); - - $index = new xmldb_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); - if (!$dbman->index_exists($table, $index)) { - $result = $result && $dbman->add_index($table, $index); + /// Adding fields to table chat_messages_current + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->add_field('chatid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->add_field('system', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->add_field('message', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('timestamp', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + + /// Adding keys to table chat_messages_current + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('chatid', XMLDB_KEY_FOREIGN, array('chatid'), 'chat', array('id')); + + /// Adding indexes to table chat_messages_current + $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); + $table->add_index('groupid', XMLDB_INDEX_NOTUNIQUE, array('groupid')); + $table->add_index('timestamp-chatid', XMLDB_INDEX_NOTUNIQUE, array('timestamp', 'chatid')); + + /// Conditionally launch create table for chat_messages_current + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); } - $index = new xmldb_index('groupid', XMLDB_INDEX_NOTUNIQUE, array('groupid')); - if (!$dbman->index_exists($table, $index)) { - $result = $result && $dbman->add_index($table, $index); - } - - $index = new xmldb_index('timestamp-chatid', XMLDB_INDEX_NOTUNIQUE, array('timestamp', 'chatid')); - if (!$dbman->index_exists($table, $index)) { - $result = $result && $dbman->add_index($table, $index); - } + /// chat savepoint reached + upgrade_mod_savepoint($result, 2008072400, 'chat'); } return $result; diff --git a/mod/chat/version.php b/mod/chat/version.php index 632b37beaf..c933033c04 100644 --- a/mod/chat/version.php +++ b/mod/chat/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2007101510; // The (date) version of this module +$module->version = 2008072400; // The (date) version of this module $module->requires = 2007101509; // Requires this Moodle version $module->cron = 300; // How often should cron check this module (seconds)? -- 2.39.5