mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 10:26:40 +02:00
Merge branch 'MDL-67187_master' of git://github.com/dmonllao/moodle
This commit is contained in:
commit
5f1307ef9a
3 changed files with 53 additions and 2 deletions
|
@ -3756,8 +3756,7 @@ function xmldb_main_upgrade($oldversion) {
|
||||||
|
|
||||||
if ($oldversion < 2019103000.13) {
|
if ($oldversion < 2019103000.13) {
|
||||||
|
|
||||||
$DB->execute("UPDATE {analytics_models} set contextids = null
|
upgrade_analytics_fix_contextids_defaults();
|
||||||
WHERE contextids = :zero or contextids = :null", ['zero' => '0', 'null' => 'null']);
|
|
||||||
|
|
||||||
// Main savepoint reached.
|
// Main savepoint reached.
|
||||||
upgrade_main_savepoint(true, 2019103000.13);
|
upgrade_main_savepoint(true, 2019103000.13);
|
||||||
|
|
|
@ -653,3 +653,14 @@ function upgrade_convert_hub_config_site_param_names(stdClass $hubconfig, string
|
||||||
|
|
||||||
return (object) $converted;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -1172,4 +1172,45 @@ class core_upgradelib_testcase extends advanced_testcase {
|
||||||
// Eventual custom values not following the expected hub-specific naming format, are kept.
|
// Eventual custom values not following the expected hub-specific naming format, are kept.
|
||||||
$this->assertSame($converted->custom, 'Do not touch this');
|
$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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue