I got the following error:
Value of type null is not callable
When trying to delete an activity,the function is called by:
$assignment->delete_instance();
The $assignment is not null i double checked, but a valid assignment object, i don't know how to solve this issue, please help in this question, thank you in advance
Edit1:
"It sounds like you reused a method name as a variable" - this is true because its definied like:
function remove_course_contents($courseid, $showfeedback = true, array $options = null) {
$modname = 'assign';
$moddelete = $modname .'_delete_instance';
if (function_exists($moddelete)) {
// This purges all module data in related tables, extra user prefs, settings, etc.
$moddelete($cm->modinstance);
} else {
// NOTE: we should not allow installation of modules with missing delete support!
debugging("Defective module '$modname' detected when deleting course contents: missing function $moddelete()!");
$DB->delete_records($modname, array('id' => $cm->modinstance));
}
so it's called like:
$moddelete($cm->modinstance);
this will call finally:
function assign_delete_instance($id) {
$assignment->delete_instance();//this is where the execution stopped
}
public function delete_instance() {
global $DB;
$result = true;
foreach ($this->submissionplugins as $plugin) {
if (!$plugin->delete_instance()) {
throw new \moodle_exception($plugin->get_error());
$result = false;
}
}
foreach ($this->feedbackplugins as $plugin) {
if (!$plugin->delete_instance()) {
throw new \moodle_exception($plugin->get_error());
$result = false;
}
}
// Delete files associated with this assignment.
$fs = get_file_storage();
if (! $fs->delete_area_files($this->context->id) ) {
$result = false;
}
$this->delete_all_overrides();
// Delete_records will throw an exception if it fails - so no need for error checking here.
$DB->delete_records('assign_submission', array('assignment' => $this->get_instance()->id));
$DB->delete_records('assign_grades', array('assignment' => $this->get_instance()->id));
$DB->delete_records('assign_plugin_config', array('assignment' => $this->get_instance()->id));
$DB->delete_records('assign_user_flags', array('assignment' => $this->get_instance()->id));
$DB->delete_records('assign_user_mapping', array('assignment' => $this->get_instance()->id));
// Delete items from the gradebook.
if (! $this->delete_grades()) {
$result = false;
}
// Delete the instance.
// We must delete the module record after we delete the grade item.
$DB->delete_records('assign', array('id'=>$this->get_instance()->id));
return $result;
}