diff --git a/classes/task/adhoc_task.php b/classes/task/adhoc_task.php new file mode 100644 index 0000000..9411ddf --- /dev/null +++ b/classes/task/adhoc_task.php @@ -0,0 +1,43 @@ +. + +namespace mod_oublog\task; + +defined('MOODLE_INTERNAL') || die(); +/** + * Class adhoc_task + * + * @package mod_oublog + * @copyright 2024 YOUR NAME + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class adhoc_task extends \core\task\adhoc_task { + /** + * Execute the task. + */ + public function execute() { + global $CFG, $DB; + if (!isset($CFG->oublogsetup)) { + if ($pbcm = get_coursemodule_from_instance('oublog', 1 , SITEID, 1)) { + $mod = new \stdClass(); + $mod->id= $pbcm->id; + $mod->section = course_add_cm_to_section((int) $pbcm->course, (int) $pbcm->id, 1); + $DB->update_record('course_modules', $mod); + } + set_config('oublogsetup', true); + } + } +} diff --git a/db/install.php b/db/install.php index 7b39f04..3490fd5 100644 --- a/db/install.php +++ b/db/install.php @@ -56,6 +56,10 @@ function xmldb_oublog_install() { if (!$cm = add_course_module($mod)) { return true; } + + $task = new \mod_oublog\task\adhoc_task(); + \core\task\manager::queue_adhoc_task($task, true); + set_config('oublogsetup', null); // For unit tests to work, it's necessary to create context now. diff --git a/settings.php b/settings.php index 426f774..4a458f5 100644 --- a/settings.php +++ b/settings.php @@ -14,17 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -// Dodgy hack to setup the global blog instance (section not created yet on install). -if (!isset($CFG->oublogsetup)) { - if ($pbcm = get_coursemodule_from_instance('oublog', 1 , SITEID, 1)) { - $mod = new stdClass(); - $mod->id= $pbcm->id; - $mod->section = course_add_cm_to_section($pbcm->course, $pbcm->id, 1); - $DB->update_record('course_modules', $mod); - } - set_config('oublogsetup', true); -} - $plugin = new stdClass(); require($CFG->dirroot . '/mod/oublog/version.php'); $settings->add(new admin_setting_heading('oublog_version', '',