mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch '43365-28' of git://github.com/samhemelryk/moodle
This commit is contained in:
commit
eaa504cd67
@ -2988,7 +2988,7 @@ function get_component_string($component, $contextlevel) {
|
||||
|
||||
if ($component === 'moodle' or $component === 'core') {
|
||||
switch ($contextlevel) {
|
||||
// TODO: this should probably use context level names instead
|
||||
// TODO MDL-46123: this should probably use context level names instead
|
||||
case CONTEXT_SYSTEM: return get_string('coresystem');
|
||||
case CONTEXT_USER: return get_string('users');
|
||||
case CONTEXT_COURSECAT: return get_string('categories');
|
||||
@ -3007,7 +3007,7 @@ function get_component_string($component, $contextlevel) {
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
// TODO: this is really hacky, anyway it should be probably moved to lib/pluginlib.php
|
||||
// TODO MDL-46123: this is really hacky and should be improved.
|
||||
case 'quiz': return get_string($name.':componentname', $component);// insane hack!!!
|
||||
case 'repository': return get_string('repository', 'repository').': '.get_string('pluginname', $component);
|
||||
case 'gradeimport': return get_string('gradeimport', 'grades').': '.get_string('pluginname', $component);
|
||||
|
@ -307,10 +307,3 @@ class core_collator {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy collatorlib.
|
||||
* @deprecated since 2.6, use core_collator:: instead.
|
||||
*/
|
||||
class collatorlib extends core_collator {
|
||||
}
|
||||
|
@ -47,19 +47,21 @@ class core_component {
|
||||
/** @var array list plugin types that support subplugins, do not add more here unless absolutely necessary */
|
||||
protected static $supportsubplugins = array('mod', 'editor', 'tool', 'local');
|
||||
|
||||
/** @var null cache of plugin types */
|
||||
/** @var array cache of plugin types */
|
||||
protected static $plugintypes = null;
|
||||
/** @var null cache of plugin locations */
|
||||
/** @var array cache of plugin locations */
|
||||
protected static $plugins = null;
|
||||
/** @var null cache of core subsystems */
|
||||
/** @var array cache of core subsystems */
|
||||
protected static $subsystems = null;
|
||||
/** @var null subplugin type parents */
|
||||
/** @var array subplugin type parents */
|
||||
protected static $parents = null;
|
||||
/** @var null subplugins */
|
||||
/** @var array subplugins */
|
||||
protected static $subplugins = null;
|
||||
/** @var null list of all known classes that can be autoloaded */
|
||||
/** @var array list of all known classes that can be autoloaded */
|
||||
protected static $classmap = null;
|
||||
/** @var null list of some known files that can be included. */
|
||||
/** @var array list of all classes that have been renamed to be autoloaded */
|
||||
protected static $classmaprenames = null;
|
||||
/** @var array list of some known files that can be included. */
|
||||
protected static $filemap = null;
|
||||
/** @var int|float core version. */
|
||||
protected static $version = null;
|
||||
@ -92,6 +94,13 @@ class core_component {
|
||||
include_once(self::$classmap[$classname]);
|
||||
return;
|
||||
}
|
||||
if (isset(self::$classmaprenames[$classname]) && isset(self::$classmap[self::$classmaprenames[$classname]])) {
|
||||
$newclassname = self::$classmaprenames[$classname];
|
||||
$debugging = "Class '%s' has been renamed for the autoloader and is now deprecated. Please use '%s' instead.";
|
||||
debugging(sprintf($debugging, $classname, $newclassname), DEBUG_DEVELOPER);
|
||||
class_alias($newclassname, $classname);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,13 +134,14 @@ class core_component {
|
||||
}
|
||||
$cache = array();
|
||||
include($cachefile);
|
||||
self::$plugintypes = $cache['plugintypes'];
|
||||
self::$plugins = $cache['plugins'];
|
||||
self::$subsystems = $cache['subsystems'];
|
||||
self::$parents = $cache['parents'];
|
||||
self::$subplugins = $cache['subplugins'];
|
||||
self::$classmap = $cache['classmap'];
|
||||
self::$filemap = $cache['filemap'];
|
||||
self::$plugintypes = $cache['plugintypes'];
|
||||
self::$plugins = $cache['plugins'];
|
||||
self::$subsystems = $cache['subsystems'];
|
||||
self::$parents = $cache['parents'];
|
||||
self::$subplugins = $cache['subplugins'];
|
||||
self::$classmap = $cache['classmap'];
|
||||
self::$classmaprenames = $cache['classmaprenames'];
|
||||
self::$filemap = $cache['filemap'];
|
||||
return;
|
||||
}
|
||||
|
||||
@ -164,13 +174,14 @@ class core_component {
|
||||
// $CFG->dirroot was changed.
|
||||
} else {
|
||||
// The cache looks ok, let's use it.
|
||||
self::$plugintypes = $cache['plugintypes'];
|
||||
self::$plugins = $cache['plugins'];
|
||||
self::$subsystems = $cache['subsystems'];
|
||||
self::$parents = $cache['parents'];
|
||||
self::$subplugins = $cache['subplugins'];
|
||||
self::$classmap = $cache['classmap'];
|
||||
self::$filemap = $cache['filemap'];
|
||||
self::$plugintypes = $cache['plugintypes'];
|
||||
self::$plugins = $cache['plugins'];
|
||||
self::$subsystems = $cache['subsystems'];
|
||||
self::$parents = $cache['parents'];
|
||||
self::$subplugins = $cache['subplugins'];
|
||||
self::$classmap = $cache['classmap'];
|
||||
self::$classmaprenames = $cache['classmaprenames'];
|
||||
self::$filemap = $cache['filemap'];
|
||||
return;
|
||||
}
|
||||
// Note: we do not verify $CFG->admin here intentionally,
|
||||
@ -249,14 +260,15 @@ class core_component {
|
||||
}
|
||||
|
||||
$cache = array(
|
||||
'subsystems' => self::$subsystems,
|
||||
'plugintypes' => self::$plugintypes,
|
||||
'plugins' => self::$plugins,
|
||||
'parents' => self::$parents,
|
||||
'subplugins' => self::$subplugins,
|
||||
'classmap' => self::$classmap,
|
||||
'filemap' => self::$filemap,
|
||||
'version' => self::$version,
|
||||
'subsystems' => self::$subsystems,
|
||||
'plugintypes' => self::$plugintypes,
|
||||
'plugins' => self::$plugins,
|
||||
'parents' => self::$parents,
|
||||
'subplugins' => self::$subplugins,
|
||||
'classmap' => self::$classmap,
|
||||
'classmaprenames' => self::$classmaprenames,
|
||||
'filemap' => self::$filemap,
|
||||
'version' => self::$version,
|
||||
);
|
||||
|
||||
return '<?php
|
||||
@ -278,6 +290,7 @@ $cache = '.var_export($cache, true).';
|
||||
}
|
||||
|
||||
self::fill_classmap_cache();
|
||||
self::fill_classmap_renames_cache();
|
||||
self::fill_filemap_cache();
|
||||
self::fetch_core_version();
|
||||
}
|
||||
@ -578,13 +591,8 @@ $cache = '.var_export($cache, true).';
|
||||
self::load_classes($plugintype.'_'.$pluginname, "$fulldir/classes");
|
||||
}
|
||||
}
|
||||
|
||||
// Note: Add extra deprecated legacy classes here as necessary.
|
||||
self::$classmap['textlib'] = "$CFG->dirroot/lib/classes/text.php";
|
||||
self::$classmap['collatorlib'] = "$CFG->dirroot/lib/classes/collator.php";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fills up the cache defining what plugins have certain files.
|
||||
*
|
||||
@ -1024,4 +1032,47 @@ $cache = '.var_export($cache, true).';
|
||||
public static function is_core_subsystem($subsystemname) {
|
||||
return isset(self::$subsystems[$subsystemname]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Records all class renames that have been made to facilitate autoloading.
|
||||
*/
|
||||
protected static function fill_classmap_renames_cache() {
|
||||
global $CFG;
|
||||
|
||||
self::$classmaprenames = array();
|
||||
|
||||
self::load_renamed_classes("$CFG->dirroot/lib/");
|
||||
|
||||
foreach (self::$subsystems as $subsystem => $fulldir) {
|
||||
self::load_renamed_classes($fulldir);
|
||||
}
|
||||
|
||||
foreach (self::$plugins as $plugintype => $plugins) {
|
||||
foreach ($plugins as $pluginname => $fulldir) {
|
||||
self::load_renamed_classes($fulldir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the db/renamedclasses.php file from the given directory.
|
||||
*
|
||||
* The renamedclasses.php should contain a key => value array ($renamedclasses) where the key is old class name,
|
||||
* and the value is the new class name.
|
||||
* It is only included when we are populating the component cache. After that is not needed.
|
||||
*
|
||||
* @param string $fulldir
|
||||
*/
|
||||
protected static function load_renamed_classes($fulldir) {
|
||||
$file = $fulldir . '/db/renamedclasses.php';
|
||||
if (is_readable($file)) {
|
||||
$renamedclasses = null;
|
||||
require($file);
|
||||
if (is_array($renamedclasses)) {
|
||||
foreach ($renamedclasses as $oldclass => $newclass) {
|
||||
self::$classmaprenames[(string)$oldclass] = (string)$newclass;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -695,22 +695,4 @@ class core_text {
|
||||
}
|
||||
return implode(' ', $words);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy tectlib.
|
||||
* @deprecated since 2.6, use core_text:: instead.
|
||||
*/
|
||||
class textlib extends core_text {
|
||||
/**
|
||||
* Locale aware sorting, the key associations are kept, values are sorted alphabetically.
|
||||
*
|
||||
* @param array $arr array to be sorted (reference)
|
||||
* @param int $sortflag One of Collator::SORT_REGULAR, Collator::SORT_NUMERIC, Collator::SORT_STRING
|
||||
* @return void modifies parameter
|
||||
*/
|
||||
public static function asort(array &$arr, $sortflag = null) {
|
||||
debugging('textlib::asort has been superseeded by collatorlib::asort please upgrade your code to use that', DEBUG_DEVELOPER);
|
||||
collatorlib::asort($arr, $sortflag);
|
||||
}
|
||||
}
|
47
lib/db/renamedclasses.php
Normal file
47
lib/db/renamedclasses.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* This file contains mappings for classes that have been renamed so that they meet the requirements of the autoloader.
|
||||
*
|
||||
* Renaming isn't always the recommended approach, but can provide benefit in situations where we've already got a
|
||||
* close structure, OR where lots of classes get included and not necessarily used, or checked for often.
|
||||
*
|
||||
* When renaming a class delete the original class and add an entry to the db/renamedclasses.php directory for that
|
||||
* component.
|
||||
* This way we don't need to keep around old classes, instead creating aliases only when required.
|
||||
* One big advantage to this method is that we provide consistent debugging for renamed classes when they are used.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2014 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Like other files in the db directory this file uses an array.
|
||||
// The old class name is the key, the new class name is the value.
|
||||
// The array must be called $renamedclasses.
|
||||
$renamedclasses = array(
|
||||
|
||||
// Deprecated in 2.6.
|
||||
// TODO MDL-46124: Remove textlib. collatorlib, plugin_manager, and plugininfo base in 2.9.
|
||||
'textlib' => 'core_text',
|
||||
'collatorlib' => 'core_collator',
|
||||
'plugin_manager' => 'core_plugin_manager',
|
||||
'plugininfo_base' => 'core\plugininfo\base'
|
||||
|
||||
);
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@ -22,6 +21,7 @@
|
||||
* Moodle. It is mainly used by the plugins management admin page and the
|
||||
* plugins check page during the upgrade.
|
||||
*
|
||||
* @todo MDL-46122 This file will be removed in 2.9
|
||||
* @package core
|
||||
* @copyright 2011 David Mudrak <david@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
@ -29,21 +29,5 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated since 2.6 - use core_plugin_manager instead.
|
||||
*/
|
||||
class plugin_manager extends core_plugin_manager {
|
||||
// BC only.
|
||||
public static function instance() {
|
||||
return core_plugin_manager::instance();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 2.6 - use \core\plugininfo\base instead.
|
||||
*/
|
||||
class plugininfo_base extends \core\plugininfo\base {
|
||||
// BC only.
|
||||
}
|
||||
|
||||
debugging('lib/pluginlib.php has been deprecated, the classes that used to exist are now autoloaded. Please removed ' .
|
||||
'any calls to include or require this file.', DEBUG_DEVELOPER);
|
@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2011 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_collator_testcase extends basic_testcase {
|
||||
class core_collator_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* @var string The initial lang, stored because we change it during testing
|
||||
@ -244,6 +244,7 @@ class core_collator_testcase extends basic_testcase {
|
||||
public function test_legacy_collatorlib() {
|
||||
$arr = array('b' => 'ab', 1 => 'aa', 0 => 'cc');
|
||||
$result = collatorlib::asort($arr);
|
||||
$this->assertDebuggingCalled(null, null, 'This fails if any other test uses the deprecated collatorlib class.');
|
||||
$this->assertSame(array('aa', 'ab', 'cc'), array_values($arr));
|
||||
$this->assertSame(array(1, 'b', 0), array_keys($arr));
|
||||
$this->assertTrue($result);
|
||||
|
@ -350,6 +350,7 @@ class core_text_testcase extends advanced_testcase {
|
||||
|
||||
public function test_deprecated_textlib() {
|
||||
$this->assertSame(textlib::strtolower('HUH'), core_text::strtolower('HUH'));
|
||||
$this->assertDebuggingCalled(null, null, 'This fails if any other test uses the deprecated textlib class.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -351,7 +351,7 @@ class qformat_webct extends qformat_default {
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$nlinecounter++;
|
||||
$line = textlib::convert($line, 'windows-1252', 'utf-8');
|
||||
$line = core_text::convert($line, 'windows-1252', 'utf-8');
|
||||
// Processing multiples lines strings.
|
||||
|
||||
if (isset($questiontext) and is_string($questiontext)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user