Skip to content

Commit

Permalink
Merge branch 'MDL-72350-master' of https://github.com/stevandoMoodle/…
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Mar 30, 2023
2 parents 4858a62 + 1147a9f commit 11c2667
Show file tree
Hide file tree
Showing 64 changed files with 97 additions and 4,085 deletions.
5 changes: 5 additions & 0 deletions admin/environment.xml
Expand Up @@ -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>
1 change: 0 additions & 1 deletion admin/tool/behat/tests/behat/data_generators.feature
Expand Up @@ -160,7 +160,6 @@ Feature: Set up contextual data for tests
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| assign | Test assignment name | Test assignment description | C1 | assign1 |
| assignment | Test assignment22 name | Test assignment22 description | C1 | assignment1 |
| book | Test book name | Test book description | C1 | book1 |
| chat | Test chat name | Test chat description | C1 | chat1 |
| choice | Test choice name | Test choice description | C1 | choice1 |
Expand Down
Expand Up @@ -114,7 +114,7 @@ public function find_favourites_by_type(string $component, string $itemtype, int
* Find a list of favourites, by multiple types within a component.
*
* E.g. "Find all favourites in the activity chooser" might result in:
* $favcourses = find_all_favourites('core_course', ['contentitem_mod_assign','contentitem_mod_assignment');
* $favcourses = find_all_favourites('core_course', ['contentitem_mod_assign');
*
* @param string $component the frankenstyle component name.
* @param array $itemtypes optional the type of the favourited item.
Expand Down
2 changes: 1 addition & 1 deletion grade/grading/form/lib.php
Expand Up @@ -695,7 +695,7 @@ public function render_grade($page, $itemid, $gradinginfo, $defaultcontent, $can
* to the nearest int. Positive $gradingtype means that range 0..$gradingtype
* is used for the grades and in this case grade does not have to be rounded.
*
* Sometimes modules always expect grade to be rounded (like mod_assignment does).
* Sometimes modules always expect grade to be rounded (like mod_assign does).
*
* @param array $graderange array where first _key_ is the minimum grade and the
* last key is the maximum grade.
Expand Down
2 changes: 1 addition & 1 deletion grade/grading/lib.php
Expand Up @@ -38,7 +38,7 @@
* @category grading
* @example $manager = get_grading_manager($areaid);
* @example $manager = get_grading_manager(context_system::instance());
* @example $manager = get_grading_manager($context, 'mod_assignment', 'submission');
* @example $manager = get_grading_manager($context, 'mod_assign', 'submission');
* @param stdClass|int|null $context_or_areaid if $areaid is passed, no other parameter is needed
* @param string|null $component the frankenstyle name of the component
* @param string|null $area the name of the gradable area
Expand Down
1 change: 1 addition & 0 deletions lang/en/admin.php
Expand Up @@ -1570,6 +1570,7 @@
$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';
Expand Down
8 changes: 3 additions & 5 deletions lib/classes/plugin_manager.php
Expand Up @@ -1721,6 +1721,7 @@ public static function is_deleted_standard_plugin($type, $name) {
// Moodle 2.3 supports upgrades from 2.2.x only.
$plugins = array(
'qformat' => array('blackboard', 'learnwise', 'examview'),
'assignment' => array('offline', 'online', 'upload', 'uploadsingle'),
'auth' => array('radius', 'fc', 'nntp', 'pam', 'pop3', 'imap'),
'block' => array('course_overview', 'messages', 'community', 'participants', 'quiz_results'),
'cachestore' => array('memcache', 'memcached', 'mongodb'),
Expand All @@ -1731,6 +1732,7 @@ public static function is_deleted_standard_plugin($type, $name) {
'portfolio' => array('picasa', 'boxnet'),
'qformat' => array('webct'),
'message' => array('jabber'),
'mod' => array('assignment'),
'quizaccess' => array('safebrowser'),
'report' => array('search'),
'repository' => array('alfresco', 'picasa', 'skydrive', 'boxnet'),
Expand Down Expand Up @@ -1776,10 +1778,6 @@ public static function standard_plugins_list($type) {
'title', 'underline', 'undo', 'unorderedlist', 'h5p', 'emojipicker',
),

'assignment' => array(
'offline', 'online', 'upload', 'uploadsingle'
),

'assignsubmission' => array(
'comments', 'file', 'onlinetext'
),
Expand Down Expand Up @@ -1931,7 +1929,7 @@ public static function standard_plugins_list($type) {
),

'mod' => array(
'assign', 'assignment', 'bigbluebuttonbn', 'book', 'chat', 'choice', 'data', 'feedback', 'folder',
'assign', 'bigbluebuttonbn', 'book', 'chat', 'choice', 'data', 'feedback', 'folder',
'forum', 'glossary', 'h5pactivity', 'imscp', 'label', 'lesson', 'lti', 'page',
'quiz', 'resource', 'scorm', 'survey', 'url', 'wiki', 'workshop'
),
Expand Down
14 changes: 14 additions & 0 deletions lib/db/upgrade.php
Expand Up @@ -3201,5 +3201,19 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2023031400.02);
}

if ($oldversion < 2023032800.01) {
// If mod_assignment is no longer present, remove it.
if (!file_exists($CFG->dirroot . '/mod/assignment/version.php')) {
uninstall_plugin('assignment', 'offline');
uninstall_plugin('assignment', 'online');
uninstall_plugin('assignment', 'upload');
uninstall_plugin('assignment', 'uploadsingle');
uninstall_plugin('mod', 'assignment');
}

// Main savepoint reached.
upgrade_main_savepoint(true, 2023032800.01);
}

return true;
}
2 changes: 1 addition & 1 deletion lib/externallib.php
Expand Up @@ -103,7 +103,7 @@ function external_create_service_token($servicename, $contextid) {
/**
* Delete all pre-built services (+ related tokens) and external functions information defined in the specified component.
*
* @param string $component name of component (moodle, mod_assignment, etc.)
* @param string $component name of component (moodle, etc.)
*/
function external_delete_descriptions($component) {
util::delete_service_descriptions($component);
Expand Down
2 changes: 1 addition & 1 deletion lib/grade/tests/grade_item_test.php
Expand Up @@ -602,7 +602,7 @@ protected function scales_outcomes_test_grade_item_depends_on() {
}

protected function sub_test_refresh_grades() {
// Testing with the grade item for a mod_assignment instance.
// Testing with the grade item for a mod_assign instance.
$grade_item = new \grade_item($this->grade_items[0], false);
$this->assertTrue(method_exists($grade_item, 'refresh_grades'));
$this->assertTrue($grade_item->refresh_grades());
Expand Down
2 changes: 1 addition & 1 deletion lib/portfoliolib.php
Expand Up @@ -1200,7 +1200,7 @@ function portfolio_format_text_options() {
* looks through preg_replace matches and replaces content with whatever the active portfolio export format says
*
* @param int $contextid module context id
* @param string $component module name (eg:mod_assignment)
* @param string $component module name (eg:mod_assign)
* @param string $filearea normal file_area arguments
* @param int $itemid component item id
* @param portfolio_format $format exporter format type
Expand Down
36 changes: 36 additions & 0 deletions lib/tests/upgradelib_test.php
Expand Up @@ -1354,6 +1354,42 @@ public function test_check_xmlrpc_webservice_is_set(): void {
$this->assertFalse($result->getStatus());
}

/**
* Test the check_mod_assignment check if mod_assignment is still used.
*
* @return void
*/
public function test_check_mod_assignment_is_used(): void {
global $CFG, $DB;

$this->resetAfterTest();
$result = new environment_results('custom_checks');

if (file_exists("{$CFG->dirroot}/mod/assignment/version.php")) {
// This is for when the test is run on sites where mod_assignment is most likely reinstalled.
$this->assertNull(check_mod_assignment($result));
$this->assertTrue($result->getStatus());
} else {
// This is for when the test is run on sites with mod_assignment now gone.
$this->assertFalse($DB->get_manager()->table_exists('assignment'));
$this->assertNull(check_mod_assignment($result));

// Then we can simulate a scenario here where the assignment records are still present during the upgrade
// by recreating the assignment table and adding a record to it.
$dbman = $DB->get_manager();
$table = new xmldb_table('assignment');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->add_field('name', XMLDB_TYPE_CHAR, '255');
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
$dbman->create_table($table);
$DB->insert_record('assignment', (object)['name' => 'test_assign']);

$this->assertNotNull(check_mod_assignment($result));
$this->assertEquals('Assignment 2.2 is in use', $result->getInfo());
$this->assertFalse($result->getStatus());
}
}

/**
* Data provider of usermenu items.
*
Expand Down
24 changes: 22 additions & 2 deletions lib/upgradelib.php
Expand Up @@ -1161,7 +1161,7 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) {
/**
* Log_display description function used during install and upgrade.
*
* @param string $component name of component (moodle, mod_assignment, etc.)
* @param string $component name of component (moodle, etc.)
* @return void
*/
function log_update_descriptions($component) {
Expand Down Expand Up @@ -1218,7 +1218,7 @@ function log_update_descriptions($component) {

/**
* Web service discovery function used during install and upgrade.
* @param string $component name of component (moodle, mod_assignment, etc.)
* @param string $component name of component (moodle, etc.)
* @return void
*/
function external_update_descriptions($component) {
Expand Down Expand Up @@ -2796,3 +2796,23 @@ 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 $CFG, $DB;

// Check the number of records.
if (!file_exists("{$CFG->dirroot}/mod/assignment/version.php") && $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;
}
1 change: 0 additions & 1 deletion mod/assign/tests/base_test.php
Expand Up @@ -22,7 +22,6 @@

global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
require_once($CFG->dirroot . '/mod/assign/upgradelib.php');
require_once(__DIR__ . '/fixtures/testable_assign.php');

/**
Expand Down
1 change: 0 additions & 1 deletion mod/assign/tests/locallib_test.php
Expand Up @@ -32,7 +32,6 @@

global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
require_once($CFG->dirroot . '/mod/assign/upgradelib.php');
require_once($CFG->dirroot . '/mod/assign/tests/generator.php');

/**
Expand Down
145 changes: 0 additions & 145 deletions mod/assign/tests/upgradelib_test.php

This file was deleted.

4 changes: 4 additions & 0 deletions mod/assign/upgrade.txt
@@ -1,4 +1,8 @@
This files describes API changes in the assign code.

=== 4.2 ===
* The upgradelib.php file has been removed from mod_assign as it was only being used by mod_assignment and mod_assignment has been removed from core.

=== 4.1 ===
* New method \assign::is_userid_filtered() has been implemented. It returns false if user id is filtered out by either
user preferences for grading table or submission status filter. Otherwise, returns true.
Expand Down

0 comments on commit 11c2667

Please sign in to comment.