-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade existing courses to new completionlib settings on plugin upgrade
- Loading branch information
1 parent
9a03ad8
commit ab09fdd
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use local_adler\local\exceptions\not_an_adler_course_exception; | ||
use local_adler\local\upgrade\upgrade_3_2_0_to_4_0_0_completionlib; | ||
|
||
/** | ||
* @throws moodle_exception | ||
* @throws not_an_adler_course_exception | ||
*/ | ||
function xmldb_local_adler_upgrade($oldversion): bool { | ||
// global $CFG, $DB; | ||
// $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes. | ||
|
||
if ($oldversion < 2024090900) { | ||
$courses = get_courses('all'); | ||
foreach ($courses as $course) { | ||
if ($course->id == 1) { | ||
// moodle special course for startpage | ||
continue; | ||
} | ||
try { | ||
$upgrader = new upgrade_3_2_0_to_4_0_0_completionlib($course->id); | ||
$upgrader->execute(); | ||
} catch (not_an_adler_course_exception $e) { | ||
// Do nothing | ||
} | ||
} | ||
} | ||
|
||
// Everything has succeeded to here. Return true. | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php /** @noinspection PhpIllegalPsrClassPathInspection */ | ||
|
||
global $CFG; | ||
|
||
use local_adler\lib\adler_testcase; | ||
|
||
require_once($CFG->dirroot . '/local/adler/tests/lib/adler_testcase.php'); | ||
require_once($CFG->dirroot . '/local/adler/db/upgrade.php'); | ||
|
||
class upgrade_test extends adler_testcase { | ||
|
||
private function create_legacy_module(int $course_id): stdClass { | ||
return $this->getDataGenerator()->get_plugin_generator('mod_url')->create_instance([ | ||
'course' => $course_id, | ||
'completion' => COMPLETION_TRACKING_MANUAL, | ||
'completeionview' => 0, | ||
'completionpassgrade' => 0 | ||
]); | ||
} | ||
public function test_upgrade_2024090900_completion_changes() { | ||
// Create 3 courses | ||
$course1 = $this->getDataGenerator()->create_course(['enablecompletion' => 1]); | ||
$course2 = $this->getDataGenerator()->create_course(['enablecompletion' => 1]); | ||
$course3 = $this->getDataGenerator()->create_course(['enablecompletion' => 1]); | ||
|
||
$this->getDataGenerator()->get_plugin_generator('local_adler')->create_adler_course_object($course1->id); | ||
$this->getDataGenerator()->get_plugin_generator('local_adler')->create_adler_course_object($course3->id); | ||
|
||
$course1_mod1 = $this->create_legacy_module($course1->id); | ||
$course2_mod1 = $this->create_legacy_module($course2->id); | ||
$course_3_mod1 = $this->create_legacy_module($course3->id); | ||
|
||
// call cud | ||
xmldb_local_adler_upgrade(2024090800); | ||
|
||
// verify | ||
$cm1 = get_fast_modinfo($course1->id)->get_cm($course1_mod1->cmid); | ||
$this->assertEquals(COMPLETION_TRACKING_AUTOMATIC, $cm1->completion); | ||
$cm2 = get_fast_modinfo($course2->id)->get_cm($course2_mod1->cmid); | ||
$this->assertEquals(COMPLETION_TRACKING_MANUAL, $cm2->completion); | ||
$cm3 = get_fast_modinfo($course3->id)->get_cm($course_3_mod1->cmid); | ||
$this->assertEquals(COMPLETION_TRACKING_AUTOMATIC, $cm3->completion); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters