Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#135: Fix mod_oublog hackedcode for install.xml #146

Open
wants to merge 1 commit into
base: MOODLE_401_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions classes/task/adhoc_task.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace mod_oublog\task;

defined('MOODLE_INTERNAL') || die();
/**
* Class adhoc_task
*
* @package mod_oublog
* @copyright 2024 YOUR NAME <[email protected]>
* @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);
}
}
}
4 changes: 4 additions & 0 deletions db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 0 additions & 11 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

// 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', '',
Expand Down