MDL-49329 admin: Improve loading of available updates info
The actual loading of available updates info objects is moved back to the plugin manager class. As we can now mockup the manager in unit tests, this allows us to bypass the real \core\update\checker and have unit tests for \core\plugininfo\base::available_updates().
This commit is contained in:
@@ -405,33 +405,6 @@ abstract class base {
|
||||
return isset($enabled[$this->name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the property {@link $availableupdates}
|
||||
*
|
||||
* This is supposed to be called by {@link self::available_updates()} only
|
||||
* to lazy load the data once they are first requested.
|
||||
*/
|
||||
protected function load_available_updates() {
|
||||
global $CFG;
|
||||
|
||||
$provider = \core\update\checker::instance();
|
||||
|
||||
if (!$provider->enabled() or during_initial_install()) {
|
||||
$this->availableupdates = array();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($CFG->updateminmaturity)) {
|
||||
$minmaturity = $CFG->updateminmaturity;
|
||||
} else {
|
||||
// This can happen during the very first upgrade to 2.3.
|
||||
$minmaturity = MATURITY_STABLE;
|
||||
}
|
||||
|
||||
$this->availableupdates = $provider->get_update_info($this->component,
|
||||
array('minmaturity' => $minmaturity));
|
||||
}
|
||||
|
||||
/**
|
||||
* If there are updates for this plugin available, returns them.
|
||||
*
|
||||
@@ -439,16 +412,20 @@ abstract class base {
|
||||
* is available. Returns null if there is no update available or if the update
|
||||
* availability is unknown.
|
||||
*
|
||||
* Populates the property {@link $availableupdates} on first call (lazy
|
||||
* loading).
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function available_updates() {
|
||||
|
||||
if ($this->availableupdates === null) {
|
||||
// Lazy load the information about available updates.
|
||||
$this->load_available_updates();
|
||||
$this->availableupdates = $this->pluginman->load_available_updates_for_plugin($this->component);
|
||||
}
|
||||
|
||||
if (empty($this->availableupdates) or !is_array($this->availableupdates)) {
|
||||
$this->availableupdates = array();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user