Skip to content

Commit

Permalink
MDL-51580 upgradelib: Delete stuff used by removed upgrade steps
Browse files Browse the repository at this point in the history
This commits removes stuff from different upgradelib files, used
exclusively by the already deleted upgrade steps. Given such
exclusivity it was not needed to proceed with a 2-phase deprecation
as far as the functions were 100% internal to upgrade.

This is the list of deleted functions, all them docummented in their
corresponding upgrade.txt files:

- repository_picasa_admin_upgrade_notification();
- repository_googledocs_admin_upgrade_notification();
- repository_boxnet_admin_upgrade_notification();
- repository_alfresco_admin_security_key_notice();
- qtype_essay_convert_to_html();
- portfolio_picasa_admin_upgrade_notification();
- portfolio_googledocs_admin_upgrade_notification();
- portfolio_boxnet_admin_upgrade_notification();
- mod_book_migrate_moddata_dir_to_legacy();
- mod_book_migrate_all_areas();
- mod_book_migrate_area();
- mod_assignment_pending_upgrades_notification();
- upgrade_mysql_fix_unsigned_and_lob_columns();
- upgrade_course_completion_remove_duplicates();
- upgrade_save_orphaned_questions();
- upgrade_rename_old_backup_files_using_shortname();
- upgrade_mssql_nvarcharmax();
- upgrade_mssql_varbinarymax();
- upgrade_fix_missing_root_folders();
- upgrade_course_modules_sequences();
- upgrade_grade_item_fix_sortorder();
- upgrade_availability_item();
  • Loading branch information
stronk7 committed Feb 15, 2016
1 parent e8c82aa commit 1405f01
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 1,512 deletions.
381 changes: 0 additions & 381 deletions lib/db/upgradelib.php

Large diffs are not rendered by default.

247 changes: 12 additions & 235 deletions lib/tests/upgradelib_test.php
Expand Up @@ -43,80 +43,6 @@ public function test_upgrade_stale_php_files_present() {
$this->assertFalse(upgrade_stale_php_files_present());
}

/**
* Test the {@link upgrade_grade_item_fix_sortorder() function with
* faked duplicate sortorder data.
*/
public function test_upgrade_grade_item_fix_sortorder() {
global $DB;

$this->resetAfterTest(true);

// The purpose of this test is to make sure that after upgrade script
// there is no duplicates in the field grade_items.sortorder (for each course)
// and the result of query "SELECT id FROM grade_items WHERE courseid=? ORDER BY sortorder, id" does not change.
$sequencesql = 'SELECT id FROM {grade_items} WHERE courseid=? ORDER BY sortorder, id';

// Each set is used for filling the db with fake data and will be representing the result of query:
// "SELECT sortorder from {grade_items} WHERE courseid=? ORDER BY id".
$testsets = array(
// Items that need no action.
array(1,2,3),
array(5,6,7),
array(7,6,1,3,2,5),
// Items with sortorder duplicates
array(1,2,2,3,3,4,5),
// Only one sortorder duplicate.
array(1,1),
array(3,3),
// Non-sequential sortorders with one or multiple duplicates.
array(3,3,7,5,6,6,9,10,8,3),
array(7,7,3),
array(3,4,5,3,5,4,7,1)
);
$origsequences = array();

// Generate the data and remember the initial sequence or items.
foreach ($testsets as $testset) {
$course = $this->getDataGenerator()->create_course();
foreach ($testset as $sortorder) {
$this->insert_fake_grade_item_sortorder($course->id, $sortorder);
}
$DB->get_records('grade_items');
$origsequences[$course->id] = $DB->get_fieldset_sql($sequencesql, array($course->id));
}

$duplicatedetectionsql = "SELECT courseid, sortorder
FROM {grade_items}
GROUP BY courseid, sortorder
HAVING COUNT(id) > 1";

// Verify there are duplicates before we start the fix.
$dupes = $DB->record_exists_sql($duplicatedetectionsql);
$this->assertTrue($dupes);

// Do the work.
upgrade_grade_item_fix_sortorder();

// Verify that no duplicates are left in the database.
$dupes = $DB->record_exists_sql($duplicatedetectionsql);
$this->assertFalse($dupes);

// Verify that sequences are exactly the same as they were before upgrade script.
$idx = 0;
foreach ($origsequences as $courseid => $origsequence) {
if (count(($testsets[$idx])) == count(array_unique($testsets[$idx]))) {
// If there were no duplicates for this course verify that sortorders are not modified.
$newsortorders = $DB->get_fieldset_sql("SELECT sortorder from {grade_items} WHERE courseid=? ORDER BY id", array($courseid));
$this->assertEquals($testsets[$idx], $newsortorders);
}
$newsequence = $DB->get_fieldset_sql($sequencesql, array($courseid));
$this->assertEquals($origsequence, $newsequence,
"Sequences do not match for test set $idx : ".join(',', $testsets[$idx]));
$idx++;
}
}

/**
* Populate some fake grade items into the database with specified
* sortorder and course id.
Expand Down Expand Up @@ -150,57 +76,6 @@ private function insert_fake_grade_item_sortorder($courseid, $sortorder) {
return $DB->get_record('grade_items', array('id' => $item->id));
}

public function test_upgrade_fix_missing_root_folders() {
global $DB, $SITE;

$this->resetAfterTest(true);

// Setup some broken data...
// Create two resources (and associated file areas).
$this->setAdminUser();
$resource1 = $this->getDataGenerator()->get_plugin_generator('mod_resource')
->create_instance(array('course' => $SITE->id));
$resource2 = $this->getDataGenerator()->get_plugin_generator('mod_resource')
->create_instance(array('course' => $SITE->id));

// Delete the folder record of resource1 to simulate broken data.
$context = context_module::instance($resource1->cmid);
$selectargs = array('contextid' => $context->id,
'component' => 'mod_resource',
'filearea' => 'content',
'itemid' => 0);

// Verify file records exist.
$areafilecount = $DB->count_records('files', $selectargs);
$this->assertNotEmpty($areafilecount);

// Delete the folder record.
$folderrecord = $selectargs;
$folderrecord['filepath'] = '/';
$folderrecord['filename'] = '.';

// Get previous folder record.
$oldrecord = $DB->get_record('files', $folderrecord);
$DB->delete_records('files', $folderrecord);

// Verify the folder record has been removed.
$newareafilecount = $DB->count_records('files', $selectargs);
$this->assertSame($newareafilecount, $areafilecount - 1);

$this->assertFalse($DB->record_exists('files', $folderrecord));

// Run the upgrade step!
upgrade_fix_missing_root_folders();

// Verify the folder record has been restored.
$newareafilecount = $DB->count_records('files', $selectargs);
$this->assertSame($newareafilecount, $areafilecount);

$newrecord = $DB->get_record('files', $folderrecord, '*', MUST_EXIST);
// Verify the hash is correctly created.
$this->assertSame($oldrecord->pathnamehash, $newrecord->pathnamehash);
}

public function test_upgrade_fix_missing_root_folders_draft() {
global $DB, $SITE;

Expand Down Expand Up @@ -245,115 +120,6 @@ public function test_upgrade_fix_missing_root_folders_draft() {
$this->assertEquals($originalhash, $newhash);
}

/**
* Tests the upgrade of an individual course-module or section from the
* old to new availability system. (This test does not use the database
* so it can run any time.)
*/
public function test_upgrade_availability_item() {
global $CFG;
$this->resetAfterTest();

// This function is in the other upgradelib.
require_once($CFG->libdir . '/db/upgradelib.php');

// Groupmembersonly (or nothing). Show option on but ignored.
// Note: This $CFG option doesn't exist any more but we are testing the
// upgrade function so it did exist then...
$CFG->enablegroupmembersonly = 0;
$this->assertNull(
upgrade_availability_item(1, 0, 0, 0, 1, array(), array()));
$CFG->enablegroupmembersonly = 1;
$this->assertNull(
upgrade_availability_item(0, 0, 0, 0, 1, array(), array()));
$this->assertEquals(
'{"op":"&","showc":[false],"c":[{"type":"group"}]}',
upgrade_availability_item(1, 0, 0, 0, 1, array(), array()));
$this->assertEquals(
'{"op":"&","showc":[false],"c":[{"type":"grouping","id":4}]}',
upgrade_availability_item(1, 4, 0, 0, 1, array(), array()));

// Dates (with show/hide options - until date always hides).
$this->assertEquals(
'{"op":"&","showc":[true],"c":[{"type":"date","d":">=","t":996}]}',
upgrade_availability_item(0, 0, 996, 0, 1, array(), array()));
$this->assertEquals(
'{"op":"&","showc":[false],"c":[{"type":"date","d":">=","t":997}]}',
upgrade_availability_item(0, 0, 997, 0, 0, array(), array()));
$this->assertEquals(
'{"op":"&","showc":[false],"c":[{"type":"date","d":"<","t":998}]}',
upgrade_availability_item(0, 0, 0, 998, 1, array(), array()));
$this->assertEquals(
'{"op":"&","showc":[true,false],"c":[' .
'{"type":"date","d":">=","t":995},{"type":"date","d":"<","t":999}]}',
upgrade_availability_item(0, 0, 995, 999, 1, array(), array()));

// Grade (show option works as normal).
$availrec = (object)array(
'sourcecmid' => null, 'requiredcompletion' => null,
'gradeitemid' => 13, 'grademin' => null, 'grademax' => null);
$this->assertEquals(
'{"op":"&","showc":[true],"c":[{"type":"grade","id":13}]}',
upgrade_availability_item(0, 0, 0, 0, 1, array($availrec), array()));
$availrec->grademin = 4.1;
$this->assertEquals(
'{"op":"&","showc":[false],"c":[{"type":"grade","id":13,"min":4.10000}]}',
upgrade_availability_item(0, 0, 0, 0, 0, array($availrec), array()));
$availrec->grademax = 9.9;
$this->assertEquals(
'{"op":"&","showc":[true],"c":[{"type":"grade","id":13,"min":4.10000,"max":9.90000}]}',
upgrade_availability_item(0, 0, 0, 0, 1, array($availrec), array()));
$availrec->grademin = null;
$this->assertEquals(
'{"op":"&","showc":[true],"c":[{"type":"grade","id":13,"max":9.90000}]}',
upgrade_availability_item(0, 0, 0, 0, 1, array($availrec), array()));

// Completion (show option normal).
$availrec->grademax = null;
$availrec->gradeitemid = null;
$availrec->sourcecmid = 666;
$availrec->requiredcompletion = 1;
$this->assertEquals(
'{"op":"&","showc":[true],"c":[{"type":"completion","cm":666,"e":1}]}',
upgrade_availability_item(0, 0, 0, 0, 1, array($availrec), array()));
$this->assertEquals(
'{"op":"&","showc":[false],"c":[{"type":"completion","cm":666,"e":1}]}',
upgrade_availability_item(0, 0, 0, 0, 0, array($availrec), array()));

// Profile conditions (custom/standard field, values/not, show option normal).
$fieldrec = (object)array('userfield' => 'email', 'operator' => 'isempty',
'value' => '', 'shortname' => null);
$this->assertEquals(
'{"op":"&","showc":[true],"c":[{"type":"profile","op":"isempty","sf":"email"}]}',
upgrade_availability_item(0, 0, 0, 0, 1, array(), array($fieldrec)));
$fieldrec->value = '@';
$fieldrec->operator = 'contains';
$this->assertEquals(
'{"op":"&","showc":[true],"c":[{"type":"profile","op":"contains","sf":"email","v":"@"}]}',
upgrade_availability_item(0, 0, 0, 0, 1, array(), array($fieldrec)));
$fieldrec->operator = 'isnotempty';
$fieldrec->userfield = null;
$fieldrec->shortname = 'frogtype';
$this->assertEquals(
'{"op":"&","showc":[false],"c":[{"type":"profile","op":"isnotempty","cf":"frogtype"}]}',
upgrade_availability_item(0, 0, 0, 0, 0, array(), array($fieldrec)));

// Everything at once.
$this->assertEquals('{"op":"&","showc":[false,true,false,true,true,true],' .
'"c":[{"type":"grouping","id":13},' .
'{"type":"date","d":">=","t":990},' .
'{"type":"date","d":"<","t":991},' .
'{"type":"grade","id":665,"min":70.00000},' .
'{"type":"completion","cm":42,"e":2},' .
'{"type":"profile","op":"isempty","sf":"email"}]}',
upgrade_availability_item(1, 13, 990, 991, 1, array(
(object)array('sourcecmid' => null, 'gradeitemid' => 665, 'grademin' => 70),
(object)array('sourcecmid' => 42, 'gradeitemid' => null, 'requiredcompletion' => 2)
), array(
(object)array('userfield' => 'email', 'shortname' => null, 'operator' => 'isempty'),
)));
}

/**
* Test upgrade minmaxgrade step.
*/
Expand Down Expand Up @@ -488,6 +254,8 @@ public function test_upgrade_extra_credit_weightoverride() {

$this->resetAfterTest(true);

require_once($CFG->libdir . '/db/upgradelib.php');

$c = array();
$a = array();
$gi = array();
Expand Down Expand Up @@ -551,8 +319,11 @@ public function test_upgrade_extra_credit_weightoverride() {
*/
public function test_upgrade_calculated_grade_items_freeze() {
global $DB, $CFG;

$this->resetAfterTest();

require_once($CFG->libdir . '/db/upgradelib.php');

// Create a user.
$user = $this->getDataGenerator()->create_user();

Expand Down Expand Up @@ -679,8 +450,11 @@ public function test_upgrade_calculated_grade_items_freeze() {

function test_upgrade_calculated_grade_items_regrade() {
global $DB, $CFG;

$this->resetAfterTest();

require_once($CFG->libdir . '/db/upgradelib.php');

// Create a user.
$user = $this->getDataGenerator()->create_user();

Expand Down Expand Up @@ -743,9 +517,12 @@ function test_upgrade_calculated_grade_items_regrade() {
}

public function test_upgrade_course_tags() {
global $DB;
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()));
Expand Down
13 changes: 13 additions & 0 deletions lib/upgrade.txt
Expand Up @@ -3,6 +3,19 @@ information provided here is intended especially for developers.

=== 3.1 ===

* The following functions, previously used (exclusively) by upgrade steps are not available
anymore because of the upgrade cleanup performed for this version. See MDL-51580 for more info:
- upgrade_mysql_fix_unsigned_and_lob_columns()
- upgrade_course_completion_remove_duplicates()
- upgrade_save_orphaned_questions()
- upgrade_rename_old_backup_files_using_shortname()
- upgrade_mssql_nvarcharmax()
- upgrade_mssql_varbinarymax()
- upgrade_fix_missing_root_folders()
- upgrade_course_modules_sequences()
- upgrade_grade_item_fix_sortorder()
- upgrade_availability_item()

* Plugins can extend the navigation for user by declaring the following callback:
<frankenstyle>_extend_navigation_user(navigation_node $parentnode, stdClass $user,
context_user $context, stdClass $course,
Expand Down

0 comments on commit 1405f01

Please sign in to comment.