From 4bead3d0b0efabd08e08af0cdc878cf38f05ba13 Mon Sep 17 00:00:00 2001 From: Artem Andreev Date: Sat, 9 Apr 2011 12:31:19 +0400 Subject: [PATCH] db/upgrade.php and db/access.php fixes --- db/access.php | 18 +++++++++--------- db/upgrade.php | 33 ++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/db/access.php b/db/access.php index ac53edc..1ad8056 100644 --- a/db/access.php +++ b/db/access.php @@ -31,13 +31,13 @@ // For the core capabilities, the variable is $moodle_capabilities. -$mod_attforblock_capabilities = array( +$capabilities = array( 'mod/attforblock:view' => array( 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( + 'archetypes' => array( 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW @@ -50,7 +50,7 @@ $mod_attforblock_capabilities = array( 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( + 'archetypes' => array( 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW ) @@ -62,7 +62,7 @@ $mod_attforblock_capabilities = array( 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( + 'archetypes' => array( 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW ) @@ -74,7 +74,7 @@ $mod_attforblock_capabilities = array( 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( + 'archetypes' => array( 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW ) @@ -86,7 +86,7 @@ $mod_attforblock_capabilities = array( 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( + 'archetypes' => array( 'editingteacher' => CAP_ALLOW ) ), @@ -97,7 +97,7 @@ $mod_attforblock_capabilities = array( 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( + 'archetypes' => array( 'editingteacher' => CAP_ALLOW ) ), @@ -108,7 +108,7 @@ $mod_attforblock_capabilities = array( 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( + 'archetypes' => array( 'editingteacher' => CAP_ALLOW ) ), @@ -120,7 +120,7 @@ $mod_attforblock_capabilities = array( 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( + 'archetypes' => array( 'student' => CAP_ALLOW ) ) diff --git a/db/upgrade.php b/db/upgrade.php index 23d7d88..8c94604 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -228,11 +228,16 @@ function xmldb_attforblock_upgrade($oldversion=0) { $field = new xmldb_field('groupid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'courseid'); - $dbman->add_field($table, $field); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } $index = new xmldb_index('groupid'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('groupid')); - $dbman->add_index($table, $index); + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + upgrade_mod_savepoint(true, 2010070900, 'attforblock'); } @@ -242,26 +247,36 @@ function xmldb_attforblock_upgrade($oldversion=0) { $field = new xmldb_field('attendanceid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'groupid'); - $dbman->add_field($table, $field); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } - $index = new xmldb_table('attendanceid'); + $index = new xmldb_index('attendanceid'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('attendanceid')); - $dbman->add_index($table, $index); + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } $sql = "UPDATE {attendance_sessions} AS ses,{attforblock} AS att SET ses.attendanceid=att.id WHERE att.course=ses.courseid"; - $dbman->execute($sql); + $DB->execute($sql); $table = new xmldb_table('attendance_statuses'); $field = new xmldb_field('attendanceid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'courseid'); - $dbman->add_field($table, $field); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } $index = new xmldb_index('attendanceid'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('attendanceid')); - $dbman->add_index($table, $index); + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } $sql = "UPDATE {attendance_statuses} AS sta,{attforblock} AS att SET sta.attendanceid=att.id WHERE att.course=sta.courseid"; - execute($sql); + $DB->execute($sql); + + upgrade_mod_savepoint(true, 2010123003, 'attforblock'); } return $result; }