bdecentgmbh / moodle-format_kickstart

Kickstart adds a powerful course template engine to moodle – create courses easily and produce high quality courses, consistently.
http://bdecent.de/kickstart
5 stars 3 forks source link

Call to a member function get_setting() on null #22

Closed rschrenk closed 3 years ago

rschrenk commented 3 years ago

When importing a course I get the Error "Call to a member function get_setting() on null". This occurs in File classes/course_importer.php on line 105 with the call $setting = $rc->get_plan()->get_setting($settingname);

Our installed plugin version is: format_kickstart 2020061300 local_kickstart_pro 2020061700

This suddenly occured and we have no clue why. Can you help us?

rschrenk commented 3 years ago

Hallo,

we figure out, that this problem is due to the fact, that we have the temp-directory on several machines locally. The "temp"-Directory should only be used for temporary files. In case of your plugin, you store the backups persistently.

Therefore I would suggest, that you implement the following:

Kind regards

moodledev commented 3 years ago

The Kickstart templates are associated with an mbz backup file stored in the Moodle file system: https://github.com/stefanscholz/moodle-format_kickstart/blob/master/template.php#L64

The import process uses the standard Moodle API. During import, the mbz is extracted to temp storage: https://github.com/stefanscholz/moodle-format_kickstart/blob/a43c0a8e34ff075b5da673d8b7b28a477debe31c/classes/course_importer.php#L69

I don't see anything being persistently stored in temp. Can you clarify what is stored in temp that shouldn't be?

rschrenk commented 3 years ago

Thank you for your answer. That is weird. In our temp/backup-Directory there is one subfolder for each of our kickstart-templates, that contains the extracted course archive. If this folder is missing, we get the above mentioned error.

Is the mbz always extraced to the same subfolder?

rschrenk commented 3 years ago

I suffered from the same error on our test system too. There is only one webnode, so this cannot be the cause of the issue.

After this error appeared, I removed all contents of the moodledata/temp/backup folder. I started the import.php again, and the mbz actually gets extracted to moodledata/temp/backup/template1. All contents are there.

Nevertheless, the error appears. Fehler: Call to a member function get_setting() on null

Here is the stack trace.


Stack trace: 

    line 106 of /course/format/kickstart/classes/course_importer.php: Error thrown
    line 71 of /course/format/kickstart/classes/course_importer.php: call to format_kickstart\course_importer::import()
    line 40 of /course/format/kickstart/import.php: call to format_kickstart\course_importer::import_from_template()
rschrenk commented 3 years ago

We moved our $CFG->tempdir to an alternative location, maybe the problem is, because you have hardcoded it to a subdir in the moodle data dir?

https://github.com/stefanscholz/moodle-format_kickstart/blob/02d258756f257650ec714a1766b16a38fa1be213/classes/course_importer.php#L68

$filepath = $CFG->dataroot . '/temp/backup/template' . $templateid;

If you export it to the dir in the moodle dataroot, but Moodle wants to restore from the alternative location, this will not work.

dasistwas commented 3 years ago

Hi, yes please use that instead: make_backup_temp_directory

Usage see https://github.com/moodle/moodle/blob/2444c9d9be59a84f376d7109bd5b4ec87a96c95b/lib/setuplib.php#L1704