From 7648d762234469f9dcf8f152be16ddce08b38b2f Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Tue, 14 Nov 2023 20:47:06 +1300 Subject: [PATCH] Move extra requires into locallib.php to make it easier to extend. --- classes/task/check_recompletion.php | 5 ----- editcompletion.php | 7 ------- locallib.php | 10 ++++++++++ resetcompletion.php | 5 ----- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/classes/task/check_recompletion.php b/classes/task/check_recompletion.php index 50986a8..8bd5028 100644 --- a/classes/task/check_recompletion.php +++ b/classes/task/check_recompletion.php @@ -91,12 +91,7 @@ public function get_user_courses_to_reset() { */ public function execute() { global $CFG, $DB; - require_once($CFG->dirroot . '/course/lib.php'); require_once($CFG->dirroot . '/local/recompletion/locallib.php'); - require_once($CFG->libdir . '/completionlib.php'); - require_once($CFG->libdir.'/gradelib.php'); - require_once($CFG->dirroot . '/mod/assign/locallib.php'); - require_once($CFG->dirroot . '/mod/quiz/lib.php'); if (!\completion_info::is_enabled_for_site()) { return; diff --git a/editcompletion.php b/editcompletion.php index d3f550d..52b099d 100644 --- a/editcompletion.php +++ b/editcompletion.php @@ -23,14 +23,7 @@ */ require_once('../../config.php'); -require_once($CFG->dirroot.'/user/lib.php'); -require_once($CFG->libdir.'/formslib.php'); require_once($CFG->dirroot.'/local/recompletion/locallib.php'); -require_once($CFG->dirroot.'/course/lib.php'); -require_once($CFG->libdir.'/completionlib.php'); -require_once($CFG->libdir.'/gradelib.php'); -require_once($CFG->dirroot . '/mod/assign/locallib.php'); -require_once($CFG->dirroot . '/mod/quiz/lib.php'); $courseid = required_param('id', PARAM_INT); $userid = optional_param('user', 0, PARAM_INT); diff --git a/locallib.php b/locallib.php index 7366952..ac04de7 100644 --- a/locallib.php +++ b/locallib.php @@ -23,11 +23,21 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + // Used by settings to decide if attempts should be deleted or an extra attempt allowed. define('LOCAL_RECOMPLETION_NOTHING', 0); define('LOCAL_RECOMPLETION_DELETE', 1); define('LOCAL_RECOMPLETION_EXTRAATTEMPT', 2); +require_once($CFG->dirroot.'/user/lib.php'); +require_once($CFG->libdir.'/formslib.php'); +require_once($CFG->dirroot.'/course/lib.php'); +require_once($CFG->libdir.'/completionlib.php'); +require_once($CFG->libdir.'/gradelib.php'); +require_once($CFG->dirroot . '/mod/assign/locallib.php'); +require_once($CFG->dirroot . '/mod/quiz/lib.php'); + /** * Get list of supported plugin classes. * @return array diff --git a/resetcompletion.php b/resetcompletion.php index 6cd7919..b21f73f 100644 --- a/resetcompletion.php +++ b/resetcompletion.php @@ -24,11 +24,6 @@ require_once(__DIR__.'/../../config.php'); require_once($CFG->dirroot.'/local/recompletion/locallib.php'); -require_once($CFG->dirroot.'/course/lib.php'); -require_once($CFG->libdir.'/completionlib.php'); -require_once($CFG->libdir.'/gradelib.php'); -require_once($CFG->dirroot . '/mod/assign/locallib.php'); -require_once($CFG->dirroot . '/mod/quiz/lib.php'); $id = required_param('id', PARAM_INT); // Course id. $confirm = optional_param('confirm', '', PARAM_INT);