General developer forum

crash in add category

Picture of Eli C
crash in add category

Hi, can some one uelp me?
I'm trying to import a school with courses and users into moodle version 3.1.3.
The heirarchy of the school, is school-name -> year -> courses.
I used the following code to add a category for the school and then for adding the school year as a sub category:
        global $DB;
        //Create Category
        $category = new stdClass();
        $category->parent = $parent;
        $category->name = $name;
        $category->description = $description;
        $category->descriptionformat = FORMAT_PLAIN;
        $category->idnumber = $idnumber;
        $category->sortorder = 999;
        $category->id = $DB->insert_record('course_categories', $category);
        $category->context = get_context_instance(CONTEXT_COURSECAT, $category->id);

        $DB->update_record('course_categories', $category);


I saw that it worked.
Then I added the users
Then I added the course.
Everything seemed to be correct when I looked at the Moodle GUI. I saw the school -> year -> course and also the users.
I deleted the whole school, in the "Manage courses and categories" option of the admin, in order to check if the import will work again correctly,

Now the add_category code crashes in the last line -> fix_course_sortorder();
It crashed in the following code:
    public static function purge_by_event($event) {
        $instance = cache_config::instance();
        $invalidationeventset = false;
        $factory = cache_factory::instance();
        $inuse = $factory->get_caches_in_use();
        foreach ($instance->get_definitions() as $name => $definitionarr) {
            $definition = cache_definition::load($name, $definitionarr);
            if ($definition->invalidates_on_event($event)) {
The crash was:
Inline image 1
Can someone please help me understand what went wrong?

Average of ratings: -