MDL-61667 analytics: Fix checking that a given model does not exist
The original implementation did not work well for checking that the given model does NOT exist. If no record was found in the analytics_models table, the code execution continued and it reached the moment when indicators were checked. If no indicators were provided, the call ended up with error 'array_keys() expects parameter 1 to be array, boolean given' (because indicators were set to false).
This commit is contained in:
@@ -407,6 +407,10 @@ class model {
|
||||
|
||||
$existingmodels = $DB->get_records('analytics_models', array('target' => $target->get_id()));
|
||||
|
||||
if (!$existingmodels) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$indicators && $existingmodels) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -281,6 +281,7 @@ class analytics_manager_testcase extends advanced_testcase {
|
||||
// Check that no such model exists yet.
|
||||
$target = \core_analytics\manager::get_target('test_target_course_level_shortname');
|
||||
$this->assertEquals(0, $DB->count_records('analytics_models', ['target' => $target->get_id()]));
|
||||
$this->assertFalse(\core_analytics\model::exists($target));
|
||||
|
||||
// Check that the model is created.
|
||||
$created = \core_analytics\manager::create_declared_model($declaration);
|
||||
|
||||
@@ -274,6 +274,12 @@ class analytics_model_testcase extends advanced_testcase {
|
||||
|
||||
$target = \core_analytics\manager::get_target('\core\analytics\target\no_teaching');
|
||||
$this->assertTrue(\core_analytics\model::exists($target));
|
||||
|
||||
foreach (\core_analytics\manager::get_all_models() as $model) {
|
||||
$model->delete();
|
||||
}
|
||||
|
||||
$this->assertFalse(\core_analytics\model::exists($target));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user