1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Upgrade code for install
|
|
|
19 |
*
|
|
|
20 |
* @package mod_assign
|
|
|
21 |
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* upgrade this assignment instance - this function could be skipped but it will be needed later
|
|
|
27 |
* @param int $oldversion The old version of the assign module
|
|
|
28 |
* @return bool
|
|
|
29 |
*/
|
|
|
30 |
function xmldb_assign_upgrade($oldversion) {
|
|
|
31 |
global $DB;
|
|
|
32 |
|
|
|
33 |
// Automatically generated Moodle v4.2.0 release upgrade line.
|
|
|
34 |
// Put any upgrade step following this.
|
|
|
35 |
|
|
|
36 |
// Automatically generated Moodle v4.3.0 release upgrade line.
|
|
|
37 |
// Put any upgrade step following this.
|
|
|
38 |
|
|
|
39 |
$dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
|
|
|
40 |
|
|
|
41 |
if ($oldversion < 2023103000) {
|
|
|
42 |
// Define field activity to be added to assign.
|
|
|
43 |
$table = new xmldb_table('assign');
|
|
|
44 |
$field = new xmldb_field(
|
|
|
45 |
'markinganonymous',
|
|
|
46 |
XMLDB_TYPE_INTEGER,
|
|
|
47 |
'2',
|
|
|
48 |
null,
|
|
|
49 |
XMLDB_NOTNULL,
|
|
|
50 |
null,
|
|
|
51 |
'0',
|
|
|
52 |
'markingallocation'
|
|
|
53 |
);
|
|
|
54 |
// Conditionally launch add field activity.
|
|
|
55 |
if (!$dbman->field_exists($table, $field)) {
|
|
|
56 |
$dbman->add_field($table, $field);
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
// Assign savepoint reached.
|
|
|
60 |
upgrade_mod_savepoint(true, 2023103000, 'assign');
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
// Automatically generated Moodle v4.4.0 release upgrade line.
|
|
|
64 |
// Put any upgrade step following this.
|
|
|
65 |
|
1441 |
ariadna |
66 |
if ($oldversion < 2024042201) {
|
|
|
67 |
// The 'Never' ('none') option for the additional attempts (attemptreopenmethod) setting is no longer supported
|
|
|
68 |
// and needs to be updated in all relevant instances.
|
|
|
69 |
|
|
|
70 |
// The default value for the 'attemptreopenmethod' field in the 'assign' database table is currently set to 'none',
|
|
|
71 |
// This needs to be updated to 'untilpass' to ensure the system functions correctly. Additionally, the default
|
|
|
72 |
// value for the 'maxattempts' field needs to be changed to '1' to prevent multiple attempts and maintain the
|
|
|
73 |
// original behavior.
|
|
|
74 |
$table = new xmldb_table('assign');
|
|
|
75 |
$attemptreopenmethodfield = new xmldb_field('attemptreopenmethod', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL,
|
|
|
76 |
null, 'untilpass');
|
|
|
77 |
$maxattemptsfield = new xmldb_field('maxattempts', XMLDB_TYPE_INTEGER, '6', null, XMLDB_NOTNULL,
|
|
|
78 |
null, '1');
|
|
|
79 |
$dbman->change_field_default($table, $attemptreopenmethodfield);
|
|
|
80 |
$dbman->change_field_default($table, $maxattemptsfield);
|
|
|
81 |
|
|
|
82 |
// If the current value for the 'attemptreopenmethod' global configuration in the assignment is set to 'none'.
|
|
|
83 |
if (get_config('assign', 'attemptreopenmethod') == 'none') {
|
|
|
84 |
// Reset the value to 'untilpass'.
|
|
|
85 |
set_config('attemptreopenmethod', 'untilpass', 'assign');
|
|
|
86 |
// Also, setting the value for the 'maxattempts' global config in the assignment to '1' ensures that the
|
|
|
87 |
// original behaviour is preserved by disallowing any additional attempts by default.
|
|
|
88 |
set_config('maxattempts', 1, 'assign');
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
// Update all the current assignment instances that have their 'attemptreopenmethod' set to 'none'.
|
|
|
92 |
// By setting 'maxattempts' to 1, additional attempts are disallowed, preserving the original behavior.
|
|
|
93 |
$DB->execute(
|
|
|
94 |
'UPDATE {assign}
|
|
|
95 |
SET attemptreopenmethod = :newattemptreopenmethod,
|
|
|
96 |
maxattempts = :maxattempts
|
|
|
97 |
WHERE attemptreopenmethod = :oldattemptreopenmethod',
|
|
|
98 |
[
|
|
|
99 |
'newattemptreopenmethod' => 'untilpass',
|
|
|
100 |
'maxattempts' => 1,
|
|
|
101 |
'oldattemptreopenmethod' => 'none',
|
|
|
102 |
]
|
|
|
103 |
);
|
|
|
104 |
|
|
|
105 |
// Assign savepoint reached.
|
|
|
106 |
upgrade_mod_savepoint(true, 2024042201, 'assign');
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
// Automatically generated Moodle v4.5.0 release upgrade line.
|
|
|
110 |
// Put any upgrade step following this.
|
|
|
111 |
|
|
|
112 |
if ($oldversion < 2024121801) {
|
|
|
113 |
|
|
|
114 |
// Define field gradepenalty to be added to assign.
|
|
|
115 |
$table = new xmldb_table('assign');
|
|
|
116 |
$field = new xmldb_field('gradepenalty', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'submissionattachments');
|
|
|
117 |
|
|
|
118 |
// Conditionally launch add field gradepenalty.
|
|
|
119 |
if (!$dbman->field_exists($table, $field)) {
|
|
|
120 |
$dbman->add_field($table, $field);
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
// Define index gradepenalty (not unique) to be added to assign.
|
|
|
124 |
$index = new xmldb_index('gradepenalty', XMLDB_INDEX_NOTUNIQUE, ['gradepenalty']);
|
|
|
125 |
|
|
|
126 |
// Conditionally launch add index gradepenalty.
|
|
|
127 |
if (!$dbman->index_exists($table, $index)) {
|
|
|
128 |
$dbman->add_index($table, $index);
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
// Define field penalty to be added to assign_grades.
|
|
|
132 |
$table = new xmldb_table('assign_grades');
|
|
|
133 |
$field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'grade');
|
|
|
134 |
|
|
|
135 |
// Conditionally launch add field penalty.
|
|
|
136 |
if (!$dbman->field_exists($table, $field)) {
|
|
|
137 |
$dbman->add_field($table, $field);
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
// Assign savepoint reached.
|
|
|
141 |
upgrade_mod_savepoint(true, 2024121801, 'assign');
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
// Automatically generated Moodle v5.0.0 release upgrade line.
|
|
|
145 |
// Put any upgrade step following this.
|
|
|
146 |
|
1 |
efrain |
147 |
return true;
|
|
|
148 |
}
|