MDL-57432 upgrade: remove unused functions/settings from upgradelib
All these functions were used only by deleted upgrade steps so it's safe to proceed with straight deletion, considering them internal. Deletion has been documented in corresponding upgrade.txt files: - upgrade_mimetypes() - upgrade_fix_missing_root_folders_draft() - upgrade_minmaxgrade() and upgrade_minmaxgradestepignored setting - upgrade_course_tags() - atto_equation_update_librarygroup4_setting() - mod_lti_upgrade_custom_separator() These have been kept because continue being used by restore: - upgrade_group_members_only() - upgrade_extra_credit_weightoverride() - upgrade_calculated_grade_items()
This commit is contained in:
committed by
Dan Poltawski
parent
29af7b0b4c
commit
f83d212bcf
@@ -132,7 +132,6 @@ function xmldb_main_install() {
|
||||
'texteditors' => 'atto,tinymce,textarea',
|
||||
'antiviruses' => '',
|
||||
'media_plugins_sortorder' => 'videojs,youtube,swf',
|
||||
'upgrade_minmaxgradestepignored' => 1, // New installs should not run this upgrade step.
|
||||
'upgrade_extracreditweightsstepignored' => 1, // New installs should not run this upgrade step.
|
||||
'upgrade_calculatedgradeitemsignored' => 1, // New installs should not run this upgrade step.
|
||||
'upgrade_letterboundarycourses' => 1, // New installs should not run this upgrade step.
|
||||
|
||||
@@ -1914,5 +1914,11 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2017061301.00);
|
||||
}
|
||||
|
||||
if ($oldversion < 2017071000.00 ) {
|
||||
// Clean old upgrade setting not used anymore.
|
||||
unset_config('upgrade_minmaxgradestepignored');
|
||||
upgrade_main_savepoint(true, 2017071000.00);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -130,26 +130,6 @@ function upgrade_group_members_only($groupingid, $availability) {
|
||||
return json_encode($tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the mime-types for files that exist in the database, based on their
|
||||
* file extension.
|
||||
*
|
||||
* @param array $filetypes Array with file extension as the key, and mimetype as the value
|
||||
*/
|
||||
function upgrade_mimetypes($filetypes) {
|
||||
global $DB;
|
||||
$select = $DB->sql_like('filename', '?', false);
|
||||
foreach ($filetypes as $extension=>$mimetype) {
|
||||
$DB->set_field_select(
|
||||
'files',
|
||||
'mimetype',
|
||||
$mimetype,
|
||||
$select,
|
||||
array($extension)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks all courses with changes in extra credit weight calculation
|
||||
*
|
||||
@@ -288,26 +268,6 @@ function upgrade_calculated_grade_items($courseid = null) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This upgrade script merges all tag instances pointing to the same course tag
|
||||
*
|
||||
* User id is no longer used for those tag instances
|
||||
*/
|
||||
function upgrade_course_tags() {
|
||||
global $DB;
|
||||
$sql = "SELECT min(ti.id)
|
||||
FROM {tag_instance} ti
|
||||
LEFT JOIN {tag_instance} tii on tii.itemtype = ? and tii.itemid = ti.itemid and tii.tiuserid = 0 and tii.tagid = ti.tagid
|
||||
where ti.itemtype = ? and ti.tiuserid <> 0 AND tii.id is null
|
||||
group by ti.tagid, ti.itemid";
|
||||
$ids = $DB->get_fieldset_sql($sql, array('course', 'course'));
|
||||
if ($ids) {
|
||||
list($idsql, $idparams) = $DB->get_in_or_equal($ids);
|
||||
$DB->execute('UPDATE {tag_instance} SET tiuserid = 0 WHERE id ' . $idsql, $idparams);
|
||||
}
|
||||
$DB->execute("DELETE FROM {tag_instance} WHERE itemtype = ? AND tiuserid <> 0", array('course'));
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates a default separated/connected scale
|
||||
* so there's something in the database. The locations of
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Atto equation upgrade helper functions.
|
||||
*
|
||||
* @package atto_equation
|
||||
* @copyright 2015 Sam Chaffee <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Updates the librarygroup4 setting if has not been changed from the default.
|
||||
*/
|
||||
function atto_equation_update_librarygroup4_setting() {
|
||||
// Original default setting for librarygroup4.
|
||||
$settingdefault = '
|
||||
\sum{a,b}
|
||||
\int_{a}^{b}{c}
|
||||
\iint_{a}^{b}{c}
|
||||
\iiint_{a}^{b}{c}
|
||||
\oint{a}
|
||||
(a)
|
||||
[a]
|
||||
\lbrace{a}\rbrace
|
||||
\left| \begin{matrix} a_1 & a_2 \\ a_3 & a_4 \end{matrix} \right|
|
||||
';
|
||||
// Make a comparison string.
|
||||
$settingdefaultcmpr = trim(str_replace(array("\r", "\n"), '', $settingdefault));
|
||||
|
||||
// Make the current librarygroup4 setting into a comparison string.
|
||||
$currentsetting = get_config('atto_equation', 'librarygroup4');
|
||||
$currentsettingcmpr = trim(str_replace(array("\r", "\n"), '', $currentsetting));
|
||||
|
||||
if ($settingdefaultcmpr === $currentsettingcmpr) {
|
||||
// Only if the original defaults match the current setting do we set the new config.
|
||||
$newconfig = '
|
||||
\sum{a,b}
|
||||
\sqrt[a]{b+c}
|
||||
\int_{a}^{b}{c}
|
||||
\iint_{a}^{b}{c}
|
||||
\iiint_{a}^{b}{c}
|
||||
\oint{a}
|
||||
(a)
|
||||
[a]
|
||||
\lbrace{a}\rbrace
|
||||
\left| \begin{matrix} a_1 & a_2 \\ a_3 & a_4 \end{matrix} \right|
|
||||
\frac{a}{b+c}
|
||||
\vec{a}
|
||||
\binom {a} {b}
|
||||
{a \brack b}
|
||||
{a \brace b}
|
||||
';
|
||||
set_config('librarygroup4', $newconfig, 'atto_equation');
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* PHPUnit testcase class for atto equation upgrade lib.
|
||||
*
|
||||
* @package atto_equation
|
||||
* @copyright 2015 Sam Chaffee <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* PHPUnit testcase class for atto equation upgrade lib.
|
||||
*
|
||||
* @package atto_equation
|
||||
* @copyright 2015 Sam Chaffee <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class atto_equation_upgradelib_testcase extends advanced_testcase {
|
||||
/**
|
||||
* The name of the plugin in config_plugins.
|
||||
*/
|
||||
const SETTING_PLUGIN = 'atto_equation';
|
||||
|
||||
/**
|
||||
* The name of the setting in config_plugins.
|
||||
*/
|
||||
const SETTING_NAME = 'librarygroup4';
|
||||
|
||||
/**
|
||||
* Does testsuite set up.
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the upgradelib atto_equation_update_librarygroup4_setting function.
|
||||
*/
|
||||
public function test_update_librarygroup4_update() {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/editor/atto/plugins/equation/db/upgradelib.php');
|
||||
|
||||
$originaldefaults = [
|
||||
'\sum{a,b}',
|
||||
'\int_{a}^{b}{c}',
|
||||
'\iint_{a}^{b}{c}',
|
||||
'\iiint_{a}^{b}{c}',
|
||||
'\oint{a}',
|
||||
'(a)',
|
||||
'[a]',
|
||||
'\lbrace{a}\rbrace',
|
||||
'\left| \begin{matrix} a_1 & a_2 \\ a_3 & a_4 \end{matrix} \right|',
|
||||
];
|
||||
|
||||
$newconfig = '
|
||||
\sum{a,b}
|
||||
\sqrt[a]{b+c}
|
||||
\int_{a}^{b}{c}
|
||||
\iint_{a}^{b}{c}
|
||||
\iiint_{a}^{b}{c}
|
||||
\oint{a}
|
||||
(a)
|
||||
[a]
|
||||
\lbrace{a}\rbrace
|
||||
\left| \begin{matrix} a_1 & a_2 \\ a_3 & a_4 \end{matrix} \right|
|
||||
\frac{a}{b+c}
|
||||
\vec{a}
|
||||
\binom {a} {b}
|
||||
{a \brack b}
|
||||
{a \brace b}
|
||||
';
|
||||
|
||||
// Test successful update using windows line endings.
|
||||
$originaldefaultswindows = "\r\n" . implode("\r\n", $originaldefaults) . "\r\n";
|
||||
set_config(self::SETTING_NAME, $originaldefaultswindows, self::SETTING_PLUGIN);
|
||||
atto_equation_update_librarygroup4_setting();
|
||||
|
||||
$this->assertEquals($newconfig, get_config(self::SETTING_PLUGIN, self::SETTING_NAME));
|
||||
|
||||
// Test successful update using linux line .
|
||||
$originaldefaultslinux = "\n" . implode("\n", $originaldefaults) . "\n";
|
||||
set_config(self::SETTING_NAME, $originaldefaultslinux, self::SETTING_PLUGIN);
|
||||
atto_equation_update_librarygroup4_setting();
|
||||
|
||||
$this->assertEquals($newconfig, get_config(self::SETTING_PLUGIN, self::SETTING_NAME));
|
||||
|
||||
// Alter the original configuration by removing one of the equations.
|
||||
$alteredconfig = array_slice($originaldefaults, 0, -1);
|
||||
|
||||
// Test no update using windows line endings.
|
||||
$alteredconfigwindows = "\r\n" . implode("\r\n", $alteredconfig) . "\r\n";
|
||||
set_config(self::SETTING_NAME, $alteredconfigwindows, self::SETTING_PLUGIN);
|
||||
atto_equation_update_librarygroup4_setting();
|
||||
|
||||
$this->assertEquals($alteredconfigwindows, get_config(self::SETTING_PLUGIN, self::SETTING_NAME));
|
||||
|
||||
// Test no update using linux line endings.
|
||||
$alteredconfiglinux = "\n" . implode("\n", $alteredconfig) . "\n";
|
||||
set_config(self::SETTING_NAME, $alteredconfiglinux, self::SETTING_PLUGIN);
|
||||
atto_equation_update_librarygroup4_setting();
|
||||
|
||||
$this->assertEquals($alteredconfiglinux, get_config(self::SETTING_PLUGIN, self::SETTING_NAME));
|
||||
|
||||
// Test no configuration.
|
||||
unset_config(self::SETTING_NAME, self::SETTING_PLUGIN);
|
||||
atto_equation_update_librarygroup4_setting();
|
||||
|
||||
$this->assertFalse(get_config(self::SETTING_PLUGIN, self::SETTING_NAME));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,13 @@
|
||||
This files describes API changes in the editor_atto code.
|
||||
|
||||
=== 3.4 ===
|
||||
|
||||
* The following functions, previously used (exclusively) by upgrade steps are not available
|
||||
anymore because of the upgrade cleanup performed for this version. See MDL-57432 for more info:
|
||||
- atto_equation_update_librarygroup4_setting()
|
||||
|
||||
=== 3.0 ===
|
||||
|
||||
* Rangy updated to 1.3.0.
|
||||
Rangy has deprecated the createCssClassApplier function in this version (it is now createClassApplier).
|
||||
|
||||
|
||||
@@ -75,179 +75,6 @@ class core_upgradelib_testcase extends advanced_testcase {
|
||||
return $DB->get_record('grade_items', array('id' => $item->id));
|
||||
}
|
||||
|
||||
public function test_upgrade_fix_missing_root_folders_draft() {
|
||||
global $DB, $SITE;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$usercontext = context_user::instance($user->id);
|
||||
$this->setUser($user);
|
||||
$resource1 = $this->getDataGenerator()->get_plugin_generator('mod_resource')
|
||||
->create_instance(array('course' => $SITE->id));
|
||||
$context = context_module::instance($resource1->cmid);
|
||||
$draftitemid = 0;
|
||||
file_prepare_draft_area($draftitemid, $context->id, 'mod_resource', 'content', 0);
|
||||
|
||||
$queryparams = array(
|
||||
'component' => 'user',
|
||||
'contextid' => $usercontext->id,
|
||||
'filearea' => 'draft',
|
||||
'itemid' => $draftitemid,
|
||||
);
|
||||
|
||||
// Make sure there are two records in files for the draft file area and one of them has filename '.'.
|
||||
$records = $DB->get_records_menu('files', $queryparams, '', 'id, filename');
|
||||
$this->assertEquals(2, count($records));
|
||||
$this->assertTrue(in_array('.', $records));
|
||||
$originalhash = $DB->get_field('files', 'pathnamehash', $queryparams + array('filename' => '.'));
|
||||
|
||||
// Delete record with filename '.' and make sure it does not exist any more.
|
||||
$DB->delete_records('files', $queryparams + array('filename' => '.'));
|
||||
|
||||
$records = $DB->get_records_menu('files', $queryparams, '', 'id, filename');
|
||||
$this->assertEquals(1, count($records));
|
||||
$this->assertFalse(in_array('.', $records));
|
||||
|
||||
// Run upgrade script and make sure the record is restored.
|
||||
upgrade_fix_missing_root_folders_draft();
|
||||
|
||||
$records = $DB->get_records_menu('files', $queryparams, '', 'id, filename');
|
||||
$this->assertEquals(2, count($records));
|
||||
$this->assertTrue(in_array('.', $records));
|
||||
$newhash = $DB->get_field('files', 'pathnamehash', $queryparams + array('filename' => '.'));
|
||||
$this->assertEquals($originalhash, $newhash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test upgrade minmaxgrade step.
|
||||
*/
|
||||
public function test_upgrade_minmaxgrade() {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->libdir . '/gradelib.php');
|
||||
$initialminmax = $CFG->grade_minmaxtouse;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$c1 = $this->getDataGenerator()->create_course();
|
||||
$c2 = $this->getDataGenerator()->create_course();
|
||||
$c3 = $this->getDataGenerator()->create_course();
|
||||
$u1 = $this->getDataGenerator()->create_user();
|
||||
$a1 = $this->getDataGenerator()->create_module('assign', array('course' => $c1, 'grade' => 100));
|
||||
$a2 = $this->getDataGenerator()->create_module('assign', array('course' => $c2, 'grade' => 100));
|
||||
$a3 = $this->getDataGenerator()->create_module('assign', array('course' => $c3, 'grade' => 100));
|
||||
|
||||
$cm1 = get_coursemodule_from_instance('assign', $a1->id);
|
||||
$ctx1 = context_module::instance($cm1->id);
|
||||
$assign1 = new assign($ctx1, $cm1, $c1);
|
||||
|
||||
$cm2 = get_coursemodule_from_instance('assign', $a2->id);
|
||||
$ctx2 = context_module::instance($cm2->id);
|
||||
$assign2 = new assign($ctx2, $cm2, $c2);
|
||||
|
||||
$cm3 = get_coursemodule_from_instance('assign', $a3->id);
|
||||
$ctx3 = context_module::instance($cm3->id);
|
||||
$assign3 = new assign($ctx3, $cm3, $c3);
|
||||
|
||||
// Give a grade to the student.
|
||||
$ug = $assign1->get_user_grade($u1->id, true);
|
||||
$ug->grade = 10;
|
||||
$assign1->update_grade($ug);
|
||||
|
||||
$ug = $assign2->get_user_grade($u1->id, true);
|
||||
$ug->grade = 20;
|
||||
$assign2->update_grade($ug);
|
||||
|
||||
$ug = $assign3->get_user_grade($u1->id, true);
|
||||
$ug->grade = 30;
|
||||
$assign3->update_grade($ug);
|
||||
|
||||
|
||||
// Run the upgrade.
|
||||
upgrade_minmaxgrade();
|
||||
|
||||
// Nothing has happened.
|
||||
$this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c1->id)));
|
||||
$this->assertSame(false, grade_get_setting($c1->id, 'minmaxtouse', false, true));
|
||||
$this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c1->id)));
|
||||
$this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c2->id)));
|
||||
$this->assertSame(false, grade_get_setting($c2->id, 'minmaxtouse', false, true));
|
||||
$this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c2->id)));
|
||||
$this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c3->id)));
|
||||
$this->assertSame(false, grade_get_setting($c3->id, 'minmaxtouse', false, true));
|
||||
$this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c3->id)));
|
||||
|
||||
// Create inconsistency in c1 and c2.
|
||||
$giparams = array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $a1->id,
|
||||
'courseid' => $c1->id, 'itemnumber' => 0);
|
||||
$gi = grade_item::fetch($giparams);
|
||||
$gi->grademin = 5;
|
||||
$gi->update();
|
||||
|
||||
$giparams = array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $a2->id,
|
||||
'courseid' => $c2->id, 'itemnumber' => 0);
|
||||
$gi = grade_item::fetch($giparams);
|
||||
$gi->grademax = 50;
|
||||
$gi->update();
|
||||
|
||||
|
||||
// C1 and C2 should be updated, but the course setting should not be set.
|
||||
$CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_GRADE;
|
||||
|
||||
// Run the upgrade.
|
||||
upgrade_minmaxgrade();
|
||||
|
||||
// C1 and C2 were partially updated.
|
||||
$this->assertTrue($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c1->id)));
|
||||
$this->assertSame(false, grade_get_setting($c1->id, 'minmaxtouse', false, true));
|
||||
$this->assertTrue($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c1->id)));
|
||||
$this->assertTrue($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c2->id)));
|
||||
$this->assertSame(false, grade_get_setting($c2->id, 'minmaxtouse', false, true));
|
||||
$this->assertTrue($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c2->id)));
|
||||
|
||||
// Nothing has happened for C3.
|
||||
$this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c3->id)));
|
||||
$this->assertSame(false, grade_get_setting($c3->id, 'minmaxtouse', false, true));
|
||||
$this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c3->id)));
|
||||
|
||||
|
||||
// Course setting should not be set on a course that has the setting already.
|
||||
$CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_ITEM;
|
||||
grade_set_setting($c1->id, 'minmaxtouse', -1); // Sets different value than constant to check that it remained the same.
|
||||
|
||||
// Run the upgrade.
|
||||
upgrade_minmaxgrade();
|
||||
|
||||
// C2 was updated.
|
||||
$this->assertSame((string) GRADE_MIN_MAX_FROM_GRADE_GRADE, grade_get_setting($c2->id, 'minmaxtouse', false, true));
|
||||
|
||||
// Nothing has happened for C1.
|
||||
$this->assertSame('-1', grade_get_setting($c1->id, 'minmaxtouse', false, true));
|
||||
|
||||
// Nothing has happened for C3.
|
||||
$this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c3->id)));
|
||||
$this->assertSame(false, grade_get_setting($c3->id, 'minmaxtouse', false, true));
|
||||
$this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c3->id)));
|
||||
|
||||
|
||||
// Final check, this time we'll unset the default config.
|
||||
unset($CFG->grade_minmaxtouse);
|
||||
grade_set_setting($c1->id, 'minmaxtouse', null);
|
||||
|
||||
// Run the upgrade.
|
||||
upgrade_minmaxgrade();
|
||||
|
||||
// C1 was updated.
|
||||
$this->assertSame((string) GRADE_MIN_MAX_FROM_GRADE_GRADE, grade_get_setting($c1->id, 'minmaxtouse', false, true));
|
||||
|
||||
// Nothing has happened for C3.
|
||||
$this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c3->id)));
|
||||
$this->assertSame(false, grade_get_setting($c3->id, 'minmaxtouse', false, true));
|
||||
$this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c3->id)));
|
||||
|
||||
// Restore value.
|
||||
$CFG->grade_minmaxtouse = $initialminmax;
|
||||
}
|
||||
|
||||
public function test_upgrade_extra_credit_weightoverride() {
|
||||
global $DB, $CFG;
|
||||
|
||||
@@ -515,67 +342,6 @@ class core_upgradelib_testcase extends advanced_testcase {
|
||||
$this->assertEquals($gradecategoryitem->grademin, $grade->rawgrademin);
|
||||
}
|
||||
|
||||
public function test_upgrade_course_tags() {
|
||||
global $DB, $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
require_once($CFG->libdir . '/db/upgradelib.php');
|
||||
|
||||
// Running upgrade script when there are no tags.
|
||||
upgrade_course_tags();
|
||||
$this->assertFalse($DB->record_exists('tag_instance', array()));
|
||||
|
||||
// No course entries.
|
||||
$DB->insert_record('tag_instance', array('itemid' => 123, 'tagid' => 101, 'tiuserid' => 0,
|
||||
'itemtype' => 'post', 'component' => 'core', 'contextid' => 1));
|
||||
$DB->insert_record('tag_instance', array('itemid' => 333, 'tagid' => 103, 'tiuserid' => 1002,
|
||||
'itemtype' => 'post', 'component' => 'core', 'contextid' => 1));
|
||||
|
||||
upgrade_course_tags();
|
||||
$records = array_values($DB->get_records('tag_instance', array(), 'id', '*'));
|
||||
$this->assertEquals(2, count($records));
|
||||
$this->assertEquals(123, $records[0]->itemid);
|
||||
$this->assertEquals(333, $records[1]->itemid);
|
||||
|
||||
// Imagine we have tags 101, 102, 103, ... and courses 1, 2, 3, ... and users 1001, 1002, ... .
|
||||
$keys = array('itemid', 'tagid', 'tiuserid');
|
||||
$valuesets = array(
|
||||
array(1, 101, 0),
|
||||
array(1, 102, 0),
|
||||
|
||||
array(2, 102, 0),
|
||||
array(2, 103, 1001),
|
||||
|
||||
array(3, 103, 0),
|
||||
array(3, 103, 1001),
|
||||
|
||||
array(3, 104, 1006),
|
||||
array(3, 104, 1001),
|
||||
array(3, 104, 1002),
|
||||
);
|
||||
|
||||
foreach ($valuesets as $values) {
|
||||
$DB->insert_record('tag_instance', array_combine($keys, $values) +
|
||||
array('itemtype' => 'course', 'component' => 'core', 'contextid' => 1));
|
||||
}
|
||||
|
||||
upgrade_course_tags();
|
||||
// There are 8 records in 'tag_instance' table and 7 of them do not have tiuserid (except for one 'post').
|
||||
$records = array_values($DB->get_records('tag_instance', array(), 'id', '*'));
|
||||
$this->assertEquals(8, count($records));
|
||||
$this->assertEquals(7, $DB->count_records('tag_instance', array('tiuserid' => 0)));
|
||||
// Course 1 is mapped to tags 101 and 102.
|
||||
$this->assertEquals(array(101, 102), array_values($DB->get_fieldset_select('tag_instance', 'tagid',
|
||||
'itemtype = ? AND itemid = ? ORDER BY tagid', array('course', 1))));
|
||||
// Course 2 is mapped to tags 102 and 103.
|
||||
$this->assertEquals(array(102, 103), array_values($DB->get_fieldset_select('tag_instance', 'tagid',
|
||||
'itemtype = ? AND itemid = ? ORDER BY tagid', array('course', 2))));
|
||||
// Course 1 is mapped to tags 101 and 102.
|
||||
$this->assertEquals(array(103, 104), array_values($DB->get_fieldset_select('tag_instance', 'tagid',
|
||||
'itemtype = ? AND itemid = ? ORDER BY tagid', array('course', 3))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the upgrade script correctly flags courses to be frozen due to letter boundary problems.
|
||||
*/
|
||||
|
||||
@@ -3,6 +3,13 @@ information provided here is intended especially for developers.
|
||||
|
||||
=== 3.4 ===
|
||||
|
||||
* The following functions, previously used (exclusively) by upgrade steps are not available
|
||||
anymore because of the upgrade cleanup performed for this version. See MDL-57432 for more info:
|
||||
- upgrade_mimetypes()
|
||||
- upgrade_fix_missing_root_folders_draft()
|
||||
- upgrade_minmaxgrade()
|
||||
- upgrade_course_tags()
|
||||
|
||||
* Added new moodleform element 'filetypes' and new admin setting widget 'admin_setting_filetypes'. These new widgets
|
||||
allow users to define a list of file types; either by typing them manually or selecting them from a list. The widgets
|
||||
directly support the syntax used to feed the 'accepted_types' option of the filemanager and filepicker elements. File
|
||||
|
||||
@@ -2116,39 +2116,6 @@ function admin_mnet_method_get_help(ReflectionFunctionAbstract $function) {
|
||||
return implode("\n", $helplines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect draft file areas with missing root directory records and add them.
|
||||
*/
|
||||
function upgrade_fix_missing_root_folders_draft() {
|
||||
global $DB;
|
||||
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
$sql = "SELECT contextid, itemid, MAX(timecreated) AS timecreated, MAX(timemodified) AS timemodified
|
||||
FROM {files}
|
||||
WHERE (component = 'user' AND filearea = 'draft')
|
||||
GROUP BY contextid, itemid
|
||||
HAVING MAX(CASE WHEN filename = '.' AND filepath = '/' THEN 1 ELSE 0 END) = 0";
|
||||
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
$defaults = array('component' => 'user',
|
||||
'filearea' => 'draft',
|
||||
'filepath' => '/',
|
||||
'filename' => '.',
|
||||
'userid' => 0, // Don't rely on any particular user for these system records.
|
||||
'filesize' => 0,
|
||||
// Note: This does not use the file_storage API's hash calculator
|
||||
// because access to core APIs is not allowed during upgrade.
|
||||
'contenthash' => sha1(''),
|
||||
);
|
||||
foreach ($rs as $r) {
|
||||
$r->pathnamehash = sha1("/$r->contextid/user/draft/$r->itemid/.");
|
||||
$DB->insert_record('files', (array)$r + $defaults);
|
||||
}
|
||||
$rs->close();
|
||||
$transaction->allow_commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function verifies that the database is not using an unsupported storage engine.
|
||||
*
|
||||
@@ -2342,57 +2309,6 @@ function check_is_https(environment_results $result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade the minmaxgrade setting.
|
||||
*
|
||||
* This step should only be run for sites running 2.8 or later. Sites using 2.7 will be fine
|
||||
* using the new default system setting $CFG->grade_minmaxtouse.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function upgrade_minmaxgrade() {
|
||||
global $CFG, $DB;
|
||||
|
||||
// 2 is a copy of GRADE_MIN_MAX_FROM_GRADE_GRADE.
|
||||
$settingvalue = 2;
|
||||
|
||||
// Set the course setting when:
|
||||
// - The system setting does not exist yet.
|
||||
// - The system seeting is not set to what we'd set the course setting.
|
||||
$setcoursesetting = !isset($CFG->grade_minmaxtouse) || $CFG->grade_minmaxtouse != $settingvalue;
|
||||
|
||||
// Identify the courses that have inconsistencies grade_item vs grade_grade.
|
||||
$sql = "SELECT DISTINCT(gi.courseid)
|
||||
FROM {grade_grades} gg
|
||||
JOIN {grade_items} gi
|
||||
ON gg.itemid = gi.id
|
||||
WHERE gi.itemtype NOT IN (?, ?)
|
||||
AND (gg.rawgrademax != gi.grademax OR gg.rawgrademin != gi.grademin)";
|
||||
|
||||
$rs = $DB->get_recordset_sql($sql, array('course', 'category'));
|
||||
foreach ($rs as $record) {
|
||||
// Flag the course to show a notice in the gradebook.
|
||||
set_config('show_min_max_grades_changed_' . $record->courseid, 1);
|
||||
|
||||
// Set the appropriate course setting so that grades displayed are not changed.
|
||||
$configname = 'minmaxtouse';
|
||||
if ($setcoursesetting &&
|
||||
!$DB->record_exists('grade_settings', array('courseid' => $record->courseid, 'name' => $configname))) {
|
||||
// Do not set the setting when the course already defines it.
|
||||
$data = new stdClass();
|
||||
$data->courseid = $record->courseid;
|
||||
$data->name = $configname;
|
||||
$data->value = $settingvalue;
|
||||
$DB->insert_record('grade_settings', $data);
|
||||
}
|
||||
|
||||
// Mark the grades to be regraded.
|
||||
$DB->set_field('grade_items', 'needsupdate', 1, array('courseid' => $record->courseid));
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Assert the upgrade key is provided, if it is defined.
|
||||
*
|
||||
|
||||
@@ -61,8 +61,6 @@
|
||||
function xmldb_lti_upgrade($oldversion) {
|
||||
global $CFG, $DB;
|
||||
|
||||
require_once(__DIR__ . '/upgradelib.php');
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
if ($oldversion < 2016041800) {
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* LTI upgrade script.
|
||||
*
|
||||
* @package mod_lti
|
||||
* @copyright 2014 Vital Source Technologies http://vitalsource.com
|
||||
* @author Stephen Vickers
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Update any custom parameter settings separated by semicolons.
|
||||
*/
|
||||
function mod_lti_upgrade_custom_separator() {
|
||||
global $DB;
|
||||
|
||||
// Initialise parameter array.
|
||||
$params = array('semicolon' => ';', 'likecr' => "%\r%", 'likelf' => "%\n%", 'lf' => "\n");
|
||||
|
||||
// Initialise NOT LIKE clauses to check for CR and LF characters.
|
||||
$notlikecr = $DB->sql_like('value', ':likecr', true, true, true);
|
||||
$notlikelf = $DB->sql_like('value', ':likelf', true, true, true);
|
||||
|
||||
// Update any instances in the lti_types_config table.
|
||||
$sql = 'UPDATE {lti_types_config} ' .
|
||||
'SET value = REPLACE(value, :semicolon, :lf) ' .
|
||||
'WHERE (name = \'customparameters\') AND (' . $notlikecr . ') AND (' . $notlikelf . ')';
|
||||
$DB->execute($sql, $params);
|
||||
|
||||
// Initialise NOT LIKE clauses to check for CR and LF characters.
|
||||
$notlikecr = $DB->sql_like('instructorcustomparameters', ':likecr', true, true, true);
|
||||
$notlikelf = $DB->sql_like('instructorcustomparameters', ':likelf', true, true, true);
|
||||
|
||||
// Update any instances in the lti table.
|
||||
$sql = 'UPDATE {lti} ' .
|
||||
'SET instructorcustomparameters = REPLACE(instructorcustomparameters, :semicolon, :lf) ' .
|
||||
'WHERE (instructorcustomparameters IS NOT NULL) AND (' . $notlikecr . ') AND (' . $notlikelf . ')';
|
||||
$DB->execute($sql, $params);
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* LTI upgrade script.
|
||||
*
|
||||
* @package mod_lti
|
||||
* @copyright 2014 Vital Source Technologies http://vitalsource.com
|
||||
* @author Stephen Vickers
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/mod/lti/locallib.php');
|
||||
require_once($CFG->dirroot . '/mod/lti/db/upgradelib.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for mod_lti upgrades.
|
||||
*
|
||||
* @package mod_lti
|
||||
* @since Moodle 2.8
|
||||
* @copyright 2014 Vital Source Technologies http://vitalsource.com
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class mod_lti_upgradelib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test conversion of semicolon separated custom parameters.
|
||||
*/
|
||||
public function test_custom_parameter() {
|
||||
global $DB, $SITE, $USER;
|
||||
|
||||
$custom1 = 'a=one;b=two;three=3';
|
||||
$custom2 = "a=one\nb=two\nthree=3";
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$ltigenerator = $this->getDataGenerator()->get_plugin_generator('mod_lti');
|
||||
|
||||
// Create 2 tools with custom parameters.
|
||||
$toolid1 = $DB->insert_record('lti_types', array('course' => $SITE->id, 'baseurl' => '', 'createdby' => $USER->id,
|
||||
'timecreated' => time(), 'timemodified' => time()));
|
||||
$configid1 = $DB->insert_record('lti_types_config', array('typeid' => $toolid1, 'name' => 'customparameters',
|
||||
'value' => $custom1));
|
||||
$toolid2 = $DB->insert_record('lti_types', array('course' => $SITE->id, 'baseurl' => '', 'createdby' => $USER->id,
|
||||
'timecreated' => time(), 'timemodified' => time()));
|
||||
$configid2 = $DB->insert_record('lti_types_config', array('typeid' => $toolid2, 'name' => 'customparameters',
|
||||
'value' => $custom2));
|
||||
|
||||
// Create 2 instances with custom parameters.
|
||||
$activity1 = $ltigenerator->create_instance(array('course' => $SITE->id, 'name' => 'LTI activity 1',
|
||||
'typeid' => $toolid1, 'toolurl' => '', 'instructorcustomparameters' => $custom1));
|
||||
$activity2 = $ltigenerator->create_instance(array('course' => $SITE->id, 'name' => 'LTI activity 2',
|
||||
'typeid' => $toolid2, 'toolurl' => '', 'instructorcustomparameters' => $custom2));
|
||||
|
||||
// Run upgrade script.
|
||||
mod_lti_upgrade_custom_separator();
|
||||
|
||||
// Check semicolon-separated custom parameters have been updated but others have not.
|
||||
$config = $DB->get_record('lti_types_config', array('id' => $configid1));
|
||||
$this->assertEquals($config->value, $custom2);
|
||||
|
||||
$config = $DB->get_record('lti_types_config', array('id' => $configid2));
|
||||
$this->assertEquals($config->value, $custom2);
|
||||
|
||||
$config = $DB->get_record('lti', array('id' => $activity1->id));
|
||||
$this->assertEquals($config->instructorcustomparameters, $custom2);
|
||||
|
||||
$config = $DB->get_record('lti', array('id' => $activity2->id));
|
||||
$this->assertEquals($config->instructorcustomparameters, $custom2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
This files describes API changes in the lti code.
|
||||
|
||||
=== 3.4 ===
|
||||
|
||||
* The following functions, previously used (exclusively) by upgrade steps are not available
|
||||
anymore because of the upgrade cleanup performed for this version. See MDL-57432 for more info:
|
||||
- mod_lti_upgrade_custom_separator()
|
||||
|
||||
=== 3.2 ===
|
||||
|
||||
* Support for LTI ContentItem message type.
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2017070700.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2017071000.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user