mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
MDL-71747 upgrade: remove functions not used anymore
This code was used only by deleted upgrade steps so it's safe to proceed with straight deletion, considering it internal. Deletion has been documented in corresponding upgrade.txt files: - upgrade_analytics_fix_contextids_defaults() - upgrade_convert_hub_config_site_param_names() - upgrade_rename_prediction_actions_useful_incorrectly_flagged()
This commit is contained in:
parent
58b56e2395
commit
012ae934be
@ -531,104 +531,6 @@ function upgrade_delete_orphaned_file_records() {
|
||||
$DB->delete_records_list('files_reference', 'id', $deletedfileids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the existing prediction actions in the database according to the new suggested actions.
|
||||
* @return null
|
||||
*/
|
||||
function upgrade_rename_prediction_actions_useful_incorrectly_flagged() {
|
||||
global $DB;
|
||||
|
||||
// The update depends on the analyser class used by each model so we need to iterate through the models in the system.
|
||||
$modelids = $DB->get_records_sql("SELECT DISTINCT am.id, am.target
|
||||
FROM {analytics_models} am
|
||||
JOIN {analytics_predictions} ap ON ap.modelid = am.id
|
||||
JOIN {analytics_prediction_actions} apa ON ap.id = apa.predictionid");
|
||||
foreach ($modelids as $model) {
|
||||
$targetname = $model->target;
|
||||
if (!class_exists($targetname)) {
|
||||
// The plugin may not be available.
|
||||
continue;
|
||||
}
|
||||
$target = new $targetname();
|
||||
|
||||
$analyserclass = $target->get_analyser_class();
|
||||
if (!class_exists($analyserclass)) {
|
||||
// The plugin may not be available.
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($analyserclass::one_sample_per_analysable()) {
|
||||
// From 'fixed' to 'useful'.
|
||||
$params = ['oldaction' => 'fixed', 'newaction' => 'useful'];
|
||||
} else {
|
||||
// From 'notuseful' to 'incorrectlyflagged'.
|
||||
$params = ['oldaction' => 'notuseful', 'newaction' => 'incorrectlyflagged'];
|
||||
}
|
||||
|
||||
$subsql = "SELECT id FROM {analytics_predictions} WHERE modelid = :modelid";
|
||||
$updatesql = "UPDATE {analytics_prediction_actions}
|
||||
SET actionname = :newaction
|
||||
WHERE predictionid IN ($subsql) AND actionname = :oldaction";
|
||||
|
||||
$DB->execute($updatesql, $params + ['modelid' => $model->id]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the site settings for the 'hub' component in the config_plugins table.
|
||||
*
|
||||
* @param stdClass $hubconfig Settings loaded for the 'hub' component.
|
||||
* @param string $huburl The URL of the hub to use as the valid one in case of conflict.
|
||||
* @return stdClass List of new settings to be applied (including null values to be unset).
|
||||
*/
|
||||
function upgrade_convert_hub_config_site_param_names(stdClass $hubconfig, string $huburl): stdClass {
|
||||
|
||||
$cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
|
||||
$converted = [];
|
||||
|
||||
foreach ($hubconfig as $oldname => $value) {
|
||||
if (preg_match('/^site_([a-z]+)([A-Za-z0-9_-]*)/', $oldname, $matches)) {
|
||||
$newname = 'site_'.$matches[1];
|
||||
|
||||
if ($oldname === $newname) {
|
||||
// There is an existing value with the new naming convention already.
|
||||
$converted[$newname] = $value;
|
||||
|
||||
} else if (!array_key_exists($newname, $converted)) {
|
||||
// Add the value under a new name and mark the original to be unset.
|
||||
$converted[$newname] = $value;
|
||||
$converted[$oldname] = null;
|
||||
|
||||
} else if ($matches[2] === '_'.$cleanhuburl) {
|
||||
// The new name already exists, overwrite only if coming from the valid hub.
|
||||
$converted[$newname] = $value;
|
||||
$converted[$oldname] = null;
|
||||
|
||||
} else {
|
||||
// Just unset the old value.
|
||||
$converted[$oldname] = null;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Not a hub-specific site setting, just keep it.
|
||||
$converted[$oldname] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return (object) $converted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix the incorrect default values inserted into analytics contextids field.
|
||||
*/
|
||||
function upgrade_analytics_fix_contextids_defaults() {
|
||||
global $DB;
|
||||
|
||||
$select = $DB->sql_compare_text('contextids') . ' = :zero OR ' . $DB->sql_compare_text('contextids') . ' = :null';
|
||||
$params = ['zero' => '0', 'null' => 'null'];
|
||||
$DB->execute("UPDATE {analytics_models} set contextids = null WHERE " . $select, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade core licenses shipped with Moodle.
|
||||
*/
|
||||
|
@ -894,214 +894,6 @@ class upgradelib_test extends advanced_testcase {
|
||||
$this->assertEquals($file, $newstoredfile[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the previous records are updated according to the reworded actions.
|
||||
* @return null
|
||||
*/
|
||||
public function test_upgrade_rename_prediction_actions_useful_incorrectly_flagged() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$models = $DB->get_records('analytics_models');
|
||||
$upcomingactivitiesdue = null;
|
||||
$noteaching = null;
|
||||
foreach ($models as $model) {
|
||||
if ($model->target === '\\core_user\\analytics\\target\\upcoming_activities_due') {
|
||||
$upcomingactivitiesdue = new \core_analytics\model($model);
|
||||
}
|
||||
if ($model->target === '\\core_course\\analytics\\target\\no_teaching') {
|
||||
$noteaching = new \core_analytics\model($model);
|
||||
}
|
||||
}
|
||||
|
||||
// Upcoming activities due generating some insights.
|
||||
$course1 = $this->getDataGenerator()->create_course();
|
||||
$attrs = ['course' => $course1, 'duedate' => time() + WEEKSECS - DAYSECS];
|
||||
$assign = $this->getDataGenerator()->get_plugin_generator('mod_assign')->create_instance($attrs);
|
||||
$student = $this->getDataGenerator()->create_user();
|
||||
$usercontext = \context_user::instance($student->id);
|
||||
$this->getDataGenerator()->enrol_user($student->id, $course1->id, 'student');
|
||||
$upcomingactivitiesdue->predict();
|
||||
list($ignored, $predictions) = $upcomingactivitiesdue->get_predictions($usercontext, true);
|
||||
$prediction = reset($predictions);
|
||||
|
||||
$predictionaction = (object)[
|
||||
'predictionid' => $prediction->get_prediction_data()->id,
|
||||
'userid' => 2,
|
||||
'actionname' => 'fixed',
|
||||
'timecreated' => time()
|
||||
];
|
||||
$DB->insert_record('analytics_prediction_actions', $predictionaction);
|
||||
$predictionaction->actionname = 'notuseful';
|
||||
$DB->insert_record('analytics_prediction_actions', $predictionaction);
|
||||
|
||||
upgrade_rename_prediction_actions_useful_incorrectly_flagged();
|
||||
|
||||
$this->assertEquals(0, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_FIXED]));
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_USEFUL]));
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_NOT_USEFUL]));
|
||||
$this->assertEquals(0, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_INCORRECTLY_FLAGGED]));
|
||||
|
||||
// No teaching generating some insights.
|
||||
$course2 = $this->getDataGenerator()->create_course(['startdate' => time() + (2 * DAYSECS)]);
|
||||
$noteaching->predict();
|
||||
list($ignored, $predictions) = $noteaching->get_predictions(\context_system::instance(), true);
|
||||
$prediction = reset($predictions);
|
||||
|
||||
$predictionaction = (object)[
|
||||
'predictionid' => $prediction->get_prediction_data()->id,
|
||||
'userid' => 2,
|
||||
'actionname' => 'notuseful',
|
||||
'timecreated' => time()
|
||||
];
|
||||
$DB->insert_record('analytics_prediction_actions', $predictionaction);
|
||||
$predictionaction->actionname = 'fixed';
|
||||
$DB->insert_record('analytics_prediction_actions', $predictionaction);
|
||||
|
||||
upgrade_rename_prediction_actions_useful_incorrectly_flagged();
|
||||
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_FIXED]));
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_USEFUL]));
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_NOT_USEFUL]));
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_INCORRECTLY_FLAGGED]));
|
||||
|
||||
// We also check that there are no records incorrectly switched in upcomingactivitiesdue.
|
||||
$upcomingactivitiesdue->clear();
|
||||
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_FIXED]));
|
||||
$this->assertEquals(0, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_USEFUL]));
|
||||
$this->assertEquals(0, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_NOT_USEFUL]));
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_INCORRECTLY_FLAGGED]));
|
||||
|
||||
$upcomingactivitiesdue->predict();
|
||||
list($ignored, $predictions) = $upcomingactivitiesdue->get_predictions($usercontext, true);
|
||||
$prediction = reset($predictions);
|
||||
|
||||
$predictionaction = (object)[
|
||||
'predictionid' => $prediction->get_prediction_data()->id,
|
||||
'userid' => 2,
|
||||
'actionname' => 'fixed',
|
||||
'timecreated' => time()
|
||||
];
|
||||
$DB->insert_record('analytics_prediction_actions', $predictionaction);
|
||||
$predictionaction->actionname = 'notuseful';
|
||||
$DB->insert_record('analytics_prediction_actions', $predictionaction);
|
||||
|
||||
upgrade_rename_prediction_actions_useful_incorrectly_flagged();
|
||||
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_FIXED]));
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_USEFUL]));
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_NOT_USEFUL]));
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions',
|
||||
['actionname' => \core_analytics\prediction::ACTION_INCORRECTLY_FLAGGED]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the functionality of the {@link upgrade_convert_hub_config_site_param_names()} function.
|
||||
*/
|
||||
public function test_upgrade_convert_hub_config_site_param_names() {
|
||||
|
||||
$config = (object) [
|
||||
// This is how site settings related to registration at https://moodle.net are stored.
|
||||
'site_name_httpsmoodlenet' => 'Foo Site',
|
||||
'site_language_httpsmoodlenet' => 'en',
|
||||
'site_emailalert_httpsmoodlenet' => 1,
|
||||
// These are unexpected relics of a value as registered at the old http://hub.moodle.org site.
|
||||
'site_name_httphubmoodleorg' => 'Bar Site',
|
||||
'site_description_httphubmoodleorg' => 'Old description',
|
||||
// This is the target value we are converting to - here it already somehow exists.
|
||||
'site_emailalert' => 0,
|
||||
// This is a setting not related to particular hub.
|
||||
'custom' => 'Do not touch this',
|
||||
// A setting defined for multiple alternative hubs.
|
||||
'site_foo_httpfirsthuborg' => 'First',
|
||||
'site_foo_httpanotherhubcom' => 'Another',
|
||||
'site_foo_httpyetanotherhubcom' => 'Yet another',
|
||||
// A setting defined for multiple alternative hubs and one referential one.
|
||||
'site_bar_httpfirsthuborg' => 'First',
|
||||
'site_bar_httpanotherhubcom' => 'Another',
|
||||
'site_bar_httpsmoodlenet' => 'One hub to rule them all!',
|
||||
'site_bar_httpyetanotherhubcom' => 'Yet another',
|
||||
];
|
||||
|
||||
$converted = upgrade_convert_hub_config_site_param_names($config, 'https://moodle.net');
|
||||
|
||||
// Values defined for the moodle.net take precedence over the ones defined for other hubs.
|
||||
$this->assertSame($converted->site_name, 'Foo Site');
|
||||
$this->assertSame($converted->site_bar, 'One hub to rule them all!');
|
||||
$this->assertNull($converted->site_name_httpsmoodlenet);
|
||||
$this->assertNull($converted->site_bar_httpfirsthuborg);
|
||||
$this->assertNull($converted->site_bar_httpanotherhubcom);
|
||||
$this->assertNull($converted->site_bar_httpyetanotherhubcom);
|
||||
// Values defined for alternative hubs only do not have any guaranteed value. Just for convenience, we use the first one.
|
||||
$this->assertSame($converted->site_foo, 'First');
|
||||
$this->assertNull($converted->site_foo_httpfirsthuborg);
|
||||
$this->assertNull($converted->site_foo_httpanotherhubcom);
|
||||
$this->assertNull($converted->site_foo_httpyetanotherhubcom);
|
||||
// Values that are already defined with the new name format are kept.
|
||||
$this->assertSame($converted->site_emailalert, 0);
|
||||
// Eventual custom values not following the expected hub-specific naming format, are kept.
|
||||
$this->assertSame($converted->custom, 'Do not touch this');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the functionality of the {@link upgrade_analytics_fix_contextids_defaults} function.
|
||||
*/
|
||||
public function test_upgrade_analytics_fix_contextids_defaults() {
|
||||
global $DB, $USER;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$model = (object)[
|
||||
'name' => 'asd',
|
||||
'target' => 'ou',
|
||||
'indicators' => '[]',
|
||||
'version' => '1',
|
||||
'timecreated' => time(),
|
||||
'timemodified' => time(),
|
||||
'usermodified' => $USER->id,
|
||||
'contextids' => ''
|
||||
];
|
||||
$DB->insert_record('analytics_models', $model);
|
||||
|
||||
$model->contextids = null;
|
||||
$DB->insert_record('analytics_models', $model);
|
||||
|
||||
unset($model->contextids);
|
||||
$DB->insert_record('analytics_models', $model);
|
||||
|
||||
$model->contextids = '0';
|
||||
$DB->insert_record('analytics_models', $model);
|
||||
|
||||
$model->contextids = 'null';
|
||||
$DB->insert_record('analytics_models', $model);
|
||||
|
||||
$select = $DB->sql_compare_text('contextids') . ' = :zero OR ' . $DB->sql_compare_text('contextids') . ' = :null';
|
||||
$params = ['zero' => '0', 'null' => 'null'];
|
||||
$this->assertEquals(2, $DB->count_records_select('analytics_models', $select, $params));
|
||||
|
||||
upgrade_analytics_fix_contextids_defaults();
|
||||
|
||||
$this->assertEquals(0, $DB->count_records_select('analytics_models', $select, $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the functionality of {@link upgrade_core_licenses} function.
|
||||
*/
|
||||
|
@ -11,6 +11,11 @@ information provided here is intended especially for developers.
|
||||
* Final deprecation and removal of cron_run_single_task(), please use \core\task\manager::run_from_cli().
|
||||
* The $USER->groupmember hack that fills the user object with the groups that the user belongs to has been removed.
|
||||
Please use the Groups API function groups_get_user_groups() to fetch the cached list of groups the user is a member of.
|
||||
* The following functions, previously used (exclusively) by upgrade steps are not available anymore
|
||||
because of the upgrade cleanup performed for this version. See MDL-71747 for more info:
|
||||
- upgrade_analytics_fix_contextids_defaults()
|
||||
- upgrade_convert_hub_config_site_param_names()
|
||||
- upgrade_rename_prediction_actions_useful_incorrectly_flagged()
|
||||
* The method ensure_adhoc_task_qos() in lib/classes/task/manager.php has been deprecated, please use get_next_adhoc_task()
|
||||
instead.
|
||||
* New setting $CFG->enrolments_sync_interval controls the minimum time in seconds between re-synchronization of enrollment via enrol_check_plugins.
|
||||
|
Loading…
x
Reference in New Issue
Block a user