Skip to content

Commit

Permalink
Merge pull request moodlehq#185 from andrewnicols/default_cfg
Browse files Browse the repository at this point in the history
Apply sensible default values for $CFG if not specified
  • Loading branch information
stronk7 authored Feb 16, 2022
2 parents a556e9b + 827f447 commit c3350d2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions moodle/Util/MoodleUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,19 @@ protected static function loadCoreComponent(string $moodleRoot): bool {
defined('IGNORE_COMPONENT_CACHE') ?: define('IGNORE_COMPONENT_CACHE', 1);
defined('MOODLE_INTERNAL') ?: define('MOODLE_INTERNAL', 1);

if (!isset($CFG->dirroot)) { // No defined, let's start from scratch.
$CFG = (object) [
'dirroot' => $moodleRoot,
'libdir' => "${moodleRoot}/lib",
'admin' => 'admin',
];
}

// Save current CFG values.
$olddirroot = $CFG->dirroot ?? null;
$oldlibdir = $CFG->libdir ?? null;
$oldadmin = $CFG->admin ?? null;

if (!isset($CFG->dirroot)) { // No defined, let's start from scratch.
$CFG = new \stdClass();
}

if ($CFG->dirroot !== $moodleRoot) { // Different, set the minimum required.
$CFG->dirroot = $moodleRoot;
$CFG->libdir = $CFG->dirroot . '/lib';
Expand Down

0 comments on commit c3350d2

Please sign in to comment.