MDL-82183 core: Do not load subsystem db/legacyclasses.php
Subsystems do not support the notion of a `db` folder. Instead we must conflate the lib/db/legacyclasses.php syntax to allow it to support paths as either a string, or an array with [subsystem, path].
This commit is contained in:
@@ -727,14 +727,13 @@ $cache = ' . var_export($cache, true) . ';
|
||||
self::$classmap = [];
|
||||
|
||||
self::load_classes('core', "$CFG->dirroot/lib/classes");
|
||||
self::load_legacy_classes($CFG->libdir);
|
||||
self::load_legacy_classes($CFG->libdir, true);
|
||||
|
||||
foreach (self::$subsystems as $subsystem => $fulldir) {
|
||||
if (!$fulldir) {
|
||||
continue;
|
||||
}
|
||||
self::load_classes('core_' . $subsystem, "$fulldir/classes");
|
||||
self::load_legacy_classes($fulldir);
|
||||
}
|
||||
|
||||
foreach (self::$plugins as $plugintype => $plugins) {
|
||||
@@ -1448,8 +1447,12 @@ $cache = ' . var_export($cache, true) . ';
|
||||
* and the value is the path to the class file within the relative ../classes/ directory.
|
||||
*
|
||||
* @param string|null $fulldir The directory to the legacy classes.
|
||||
* @param bool $allowsubsystems Whether to allow the specification of alternative subsystems for this path.
|
||||
*/
|
||||
protected static function load_legacy_classes(?string $fulldir): void {
|
||||
protected static function load_legacy_classes(
|
||||
?string $fulldir,
|
||||
bool $allowsubsystems = false,
|
||||
): void {
|
||||
if (is_null($fulldir)) {
|
||||
return;
|
||||
}
|
||||
@@ -1460,7 +1463,32 @@ $cache = ' . var_export($cache, true) . ';
|
||||
require($file);
|
||||
if (is_array($legacyclasses)) {
|
||||
foreach ($legacyclasses as $classname => $path) {
|
||||
self::$classmap[$classname] = "{$fulldir}/classes/{$path}";
|
||||
if (is_array($path)) {
|
||||
if (!$allowsubsystems) {
|
||||
throw new \Exception(
|
||||
"Invalid legacy classes path entry for {$classname}. " .
|
||||
"Only files within the component can be specified.",
|
||||
);
|
||||
}
|
||||
if (count($path) !== 2) {
|
||||
throw new \Exception(
|
||||
"Invalid legacy classes path entry for {$classname}. " .
|
||||
"Entries must be in the format [subsystem, path].",
|
||||
);
|
||||
}
|
||||
[$subsystem, $path] = $path;
|
||||
$subsystem = substr($subsystem, 5);
|
||||
if (!array_key_exists($subsystem, self::$subsystems)) {
|
||||
throw new \Exception(
|
||||
"Unknown subsystem '{$subsystem}' for legacy classes entry of '{$classname}'",
|
||||
);
|
||||
}
|
||||
|
||||
$subsystemfulldir = self::$subsystems[$subsystem];
|
||||
self::$classmap[$classname] = "{$subsystemfulldir}/classes/{$path}";
|
||||
} else {
|
||||
self::$classmap[$classname] = "{$fulldir}/classes/{$path}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user