mirror of
https://github.com/moodle/moodle.git
synced 2025-01-30 03:58:34 +01:00
MDL-77829 core: Added environment check for mod_assignment
Decided to add an environment check before uninstalling the mod_assignment plugin to prevent data lost.
This commit is contained in:
parent
f8e2445513
commit
b796cbd03c
@ -4109,6 +4109,11 @@
|
||||
</CUSTOM_CHECK>
|
||||
<CUSTOM_CHECK file="lib/upgradelib.php" function="check_xmlrpc_usage" level="optional">
|
||||
</CUSTOM_CHECK>
|
||||
<CUSTOM_CHECK file="lib/upgradelib.php" function="check_mod_assignment" level="required">
|
||||
<FEEDBACK>
|
||||
<ON_ERROR message="modassignmentinuse" />
|
||||
</FEEDBACK>
|
||||
</CUSTOM_CHECK>
|
||||
</CUSTOM_CHECKS>
|
||||
</MOODLE>
|
||||
</COMPATIBILITY_MATRIX>
|
||||
|
@ -1549,6 +1549,7 @@ $string['xmlrpcwebserviceenabled'] = 'It has been detected that the XML-RPC Web
|
||||
$string['yuicomboloading'] = 'YUI combo loading';
|
||||
$string['ziprequired'] = 'The Zip PHP extension is now required by Moodle, info-ZIP binaries or PclZip library are not used anymore.';
|
||||
$string['manageqbanks'] = 'Manage question bank plugins';
|
||||
$string['modassignmentinuse'] = 'It has been detected that your site is still using the Assignment 2.2 plugin. You may resolve this before upgrading by 1) Backing up your Assignment 2.2 activities and restoring them as new Assignment activities; or 2) Deleting the data from the assignment tables in the database.';
|
||||
|
||||
|
||||
$string['caching'] = 'Caching';
|
||||
|
@ -1354,6 +1354,29 @@ class upgradelib_test extends advanced_testcase {
|
||||
$this->assertFalse($result->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the check_mod_assignment check if mod_assignment is still used.
|
||||
*
|
||||
* @covers ::check_mod_assignment
|
||||
* @return void
|
||||
*/
|
||||
public function test_check_mod_assignment_is_used(): void {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$result = new environment_results('custom_checks');
|
||||
|
||||
if ($DB->get_manager()->table_exists('assignment')) {
|
||||
$DB->insert_record('assignment', (object)['name' => 'test_assign', 'intro' => 'test_assign_intro']);
|
||||
|
||||
$this->assertNotNull(check_mod_assignment($result));
|
||||
$this->assertEquals('Assignment 2.2 is in use', $result->getInfo());
|
||||
$this->assertFalse($result->getStatus());
|
||||
} else {
|
||||
$this->assertTrue($result->getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider of usermenu items.
|
||||
*
|
||||
|
@ -2789,3 +2789,22 @@ function check_xmlrpc_usage(environment_results $result): ?environment_results {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the mod_assignment is currently being used.
|
||||
*
|
||||
* @param environment_results $result
|
||||
* @return environment_results|null
|
||||
*/
|
||||
function check_mod_assignment(environment_results $result): ?environment_results {
|
||||
global $DB;
|
||||
|
||||
// Check the number of records.
|
||||
if ($DB->get_manager()->table_exists('assignment') && $DB->count_records('assignment') > 0) {
|
||||
$result->setInfo('Assignment 2.2 is in use');
|
||||
$result->setFeedbackStr('modassignmentinuse');
|
||||
return $result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user