Ignore:
Timestamp:
May 2, 2016, 12:09:23 PM (3 years ago)
Author:
jrpelegrina
Message:

Updated to moodle 3.0.3

Location:
moodle/trunk/fuentes/lib/classes/plugininfo
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • moodle/trunk/fuentes/lib/classes/plugininfo/availability.php

    r136 r1331  
    2323 */
    2424namespace core\plugininfo;
     25
     26use admin_settingpage;
    2527
    2628defined('MOODLE_INTERNAL') || die();
     
    6365        return true;
    6466    }
     67
     68    /**
     69     * Get the name for the settings section.
     70     *
     71     * @return string
     72     */
     73    public function get_settings_section_name() {
     74        return 'availabilitysetting' . $this->name;
     75    }
     76
     77    /**
     78     * Load the global settings for a particular availability plugin (if there are any)
     79     *
     80     * @param \part_of_admin_tree $adminroot
     81     * @param string $parentnodename
     82     * @param bool $hassiteconfig
     83     */
     84    public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
     85        global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them.
     86        $ADMIN = $adminroot; // May be used in settings.php.
     87        $plugininfo = $this; // Also can be used inside settings.php
     88        $availability = $this; // Also to be used inside settings.php.
     89
     90        if (!$this->is_installed_and_upgraded()) {
     91            return;
     92        }
     93
     94        if (!$hassiteconfig) {
     95            return;
     96        }
     97
     98        $section = $this->get_settings_section_name();
     99
     100        $settings = null;
     101        if (file_exists($this->full_path('settings.php'))) {
     102            $settings = new admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false);
     103            include($this->full_path('settings.php')); // This may also set $settings to null.
     104        }
     105        if ($settings) {
     106            $ADMIN->add($parentnodename, $settings);
     107        }
     108    }
    65109}
  • moodle/trunk/fuentes/lib/classes/plugininfo/base.php

    r136 r1331  
    6262    /** @var int order of the plugin among other plugins of the same type - not supported yet */
    6363    public $sortorder;
     64    /** @var core_plugin_manager the plugin manager this plugin info is part of */
     65    public $pluginman;
     66
    6467    /** @var array|null array of {@link \core\update\info} for this plugin */
    65     public $availableupdates;
     68    protected $availableupdates;
    6669
    6770    /**
     
    7679     * Gathers and returns the information about all plugins of the given type,
    7780     * either on disk or previously installed.
     81     *
     82     * This is supposed to be used exclusively by the plugin manager when it is
     83     * populating its tree of plugins.
    7884     *
    7985     * @param string $type the name of the plugintype, eg. mod, auth or workshopform
    8086     * @param string $typerootdir full path to the location of the plugin dir
    8187     * @param string $typeclass the name of the actually called class
     88     * @param core_plugin_manager $pluginman the plugin manager calling this method
    8289     * @return array of plugintype classes, indexed by the plugin name
    8390     */
    84     public static function get_plugins($type, $typerootdir, $typeclass) {
     91    public static function get_plugins($type, $typerootdir, $typeclass, $pluginman) {
    8592        // Get the information about plugins at the disk.
    8693        $plugins = core_component::get_plugin_list($type);
     
    8895        foreach ($plugins as $pluginname => $pluginrootdir) {
    8996            $return[$pluginname] = self::make_plugin_instance($type, $typerootdir,
    90                 $pluginname, $pluginrootdir, $typeclass);
     97                $pluginname, $pluginrootdir, $typeclass, $pluginman);
    9198        }
    9299
    93100        // Fetch missing incorrectly uninstalled plugins.
    94         $manager = core_plugin_manager::instance();
    95         $plugins = $manager->get_installed_plugins($type);
     101        $plugins = $pluginman->get_installed_plugins($type);
    96102
    97103        foreach ($plugins as $name => $version) {
     
    106112            $plugin->displayname = $name;
    107113            $plugin->versiondb   = $version;
     114            $plugin->pluginman   = $pluginman;
    108115            $plugin->init_is_standard();
    109116
     
    122129     * @param string $namerootdir full path to the location of the plugin
    123130     * @param string $typeclass the name of class that holds the info about the plugin
     131     * @param core_plugin_manager $pluginman the plugin manager of the new instance
    124132     * @return base the instance of $typeclass
    125133     */
    126     protected static function make_plugin_instance($type, $typerootdir, $name, $namerootdir, $typeclass) {
     134    protected static function make_plugin_instance($type, $typerootdir, $name, $namerootdir, $typeclass, $pluginman) {
    127135        $plugin              = new $typeclass();
    128136        $plugin->type        = $type;
     
    130138        $plugin->name        = $name;
    131139        $plugin->rootdir     = $namerootdir;
     140        $plugin->pluginman   = $pluginman;
    132141
    133142        $plugin->init_display_name();
     
    148157        }
    149158        if ($this->versiondb === null and $this->versiondisk === null) {
    150             // There is no version.php or version info inside,
    151             // for now let's pretend it is ok.
    152             // TODO: return false once we require version in each plugin.
    153             return true;
     159            // There is no version.php or version info inside it.
     160            return false;
    154161        }
    155162
     
    208215     */
    209216    public function load_disk_version() {
    210         $versions = core_plugin_manager::instance()->get_present_plugins($this->type);
     217        $versions = $this->pluginman->get_present_plugins($this->type);
    211218
    212219        $this->versiondisk = null;
     
    262269     */
    263270    public function get_parent_plugin() {
    264         return $this->get_plugin_manager()->get_parent_of_subplugin($this->type);
     271        return $this->pluginman->get_parent_of_subplugin($this->type);
    265272    }
    266273
     
    274281     */
    275282    public function load_db_version() {
    276         $versions = core_plugin_manager::instance()->get_installed_plugins($this->type);
     283        $versions = $this->pluginman->get_installed_plugins($this->type);
    277284
    278285        if (isset($versions[$this->name])) {
     
    293300    public function init_is_standard() {
    294301
    295         $standard = core_plugin_manager::standard_plugins_list($this->type);
     302        $pluginman = $this->pluginman;
     303        $standard = $pluginman::standard_plugins_list($this->type);
    296304
    297305        if ($standard !== false) {
     
    300308                $this->source = core_plugin_manager::PLUGIN_SOURCE_STANDARD;
    301309            } else if (!is_null($this->versiondb) and is_null($this->versiondisk)
    302                 and core_plugin_manager::is_deleted_standard_plugin($this->type, $this->name)) {
     310                and $pluginman::is_deleted_standard_plugin($this->type, $this->name)) {
    303311                $this->source = core_plugin_manager::PLUGIN_SOURCE_STANDARD; // To be deleted.
    304312            } else {
     
    341349    public function get_status() {
    342350
     351        $pluginman = $this->pluginman;
     352
    343353        if (is_null($this->versiondb) and is_null($this->versiondisk)) {
    344354            return core_plugin_manager::PLUGIN_STATUS_NODB;
     
    348358
    349359        } else if (!is_null($this->versiondb) and is_null($this->versiondisk)) {
    350             if (core_plugin_manager::is_deleted_standard_plugin($this->type, $this->name)) {
     360            if ($pluginman::is_deleted_standard_plugin($this->type, $this->name)) {
    351361                return core_plugin_manager::PLUGIN_STATUS_DELETE;
    352362            } else {
     
    387397        }
    388398
    389         $enabled = core_plugin_manager::instance()->get_enabled_plugins($this->type);
     399        $enabled = $this->pluginman->get_enabled_plugins($this->type);
    390400
    391401        if (!is_array($enabled)) {
     
    394404
    395405        return isset($enabled[$this->name]);
    396     }
    397 
    398     /**
    399      * Populates the property {@link $availableupdates} with the information provided by
    400      * available update checker
    401      *
    402      * @param \core\update\checker $provider the class providing the available update info
    403      */
    404     public function check_available_updates(\core\update\checker $provider) {
    405         global $CFG;
    406 
    407         if (isset($CFG->updateminmaturity)) {
    408             $minmaturity = $CFG->updateminmaturity;
    409         } else {
    410             // This can happen during the very first upgrade to 2.3 .
    411             $minmaturity = MATURITY_STABLE;
    412         }
    413 
    414         $this->availableupdates = $provider->get_update_info($this->component,
    415             array('minmaturity' => $minmaturity));
    416406    }
    417407
     
    423413     * availability is unknown.
    424414     *
     415     * Populates the property {@link $availableupdates} on first call (lazy
     416     * loading).
     417     *
    425418     * @return array|null
    426419     */
    427420    public function available_updates() {
    428421
     422        if ($this->availableupdates === null) {
     423            // Lazy load the information about available updates.
     424            $this->availableupdates = $this->pluginman->load_available_updates_for_plugin($this->component);
     425        }
     426
    429427        if (empty($this->availableupdates) or !is_array($this->availableupdates)) {
     428            $this->availableupdates = array();
    430429            return null;
    431430        }
     
    587586        ));
    588587    }
    589 
    590     /**
    591      * Provides access to the core_plugin_manager singleton.
    592      *
    593      * @return core_plugin_manager
    594      */
    595     protected function get_plugin_manager() {
    596         return core_plugin_manager::instance();
    597     }
    598588}
  • moodle/trunk/fuentes/lib/classes/plugininfo/cachestore.php

    r136 r1331  
    2727
    2828/**
    29  * Class for admin tool plugins
     29 * Class for cache store plugins
    3030 */
    3131class cachestore extends base {
    3232
    3333    public function is_uninstall_allowed() {
    34         return false;
     34        $instance = \cache_config::instance();
     35        foreach ($instance->get_all_stores() as $store) {
     36            if ($store['plugin'] == $this->name) {
     37                return false;
     38            }
     39        }
     40        return true;
    3541    }
    3642}
  • moodle/trunk/fuentes/lib/classes/plugininfo/calendartype.php

    r136 r1331  
    2323 */
    2424namespace core\plugininfo;
     25
     26use part_of_admin_tree, admin_settingpage;
    2527
    2628defined('MOODLE_INTERNAL') || die();
  • moodle/trunk/fuentes/lib/classes/plugininfo/format.php

    r136 r1331  
    7272     * @param string $typerootdir full path to the location of the plugin dir
    7373     * @param string $typeclass the name of the actually called class
     74     * @param core_plugin_manager $pluginman the plugin manager calling this method
    7475     * @return array of plugintype classes, indexed by the plugin name
    7576     */
    76     public static function get_plugins($type, $typerootdir, $typeclass) {
     77    public static function get_plugins($type, $typerootdir, $typeclass, $pluginman) {
    7778        global $CFG;
    78         $formats = parent::get_plugins($type, $typerootdir, $typeclass);
    7979        require_once($CFG->dirroot.'/course/lib.php');
     80
     81        $formats = parent::get_plugins($type, $typerootdir, $typeclass, $pluginman);
    8082        $order = get_sorted_course_formats();
    8183        $sortedformats = array();
     
    138140        }
    139141
    140         $defaultformat = $this->get_plugin_manager()->plugin_name('format_'.get_config('moodlecourse', 'format'));
     142        $defaultformat = $this->pluginman->plugin_name('format_'.get_config('moodlecourse', 'format'));
    141143        $message = get_string(
    142144            'formatuninstallwithcourses', 'core_admin',
  • moodle/trunk/fuentes/lib/classes/plugininfo/orphaned.php

    r136 r1331  
    6565     * @param string $typerootdir full path to the location of the plugin dir
    6666     * @param string $typeclass the name of the actually called class
     67     * @param core_plugin_manager $pluginman the plugin manager calling this method
    6768     * @return array of plugintype classes, indexed by the plugin name
    6869     */
    69     public static function get_plugins($type, $typerootdir, $typeclass) {
     70    public static function get_plugins($type, $typerootdir, $typeclass, $pluginman) {
    7071        $return = array();
    71         $manager = \core_plugin_manager::instance();
    72         $plugins = $manager->get_installed_plugins($type);
     72        $plugins = $pluginman->get_installed_plugins($type);
    7373
    7474        foreach ($plugins as $name => $version) {
     
    8080            $plugin->displayname = $name;
    8181            $plugin->versiondb   = $version;
     82            $plugin->pluginman   = $pluginman;
    8283            $plugin->init_is_standard();
    8384
  • moodle/trunk/fuentes/lib/classes/plugininfo/portfolio.php

    r136 r1331  
    5555        return new moodle_url('/admin/portfolio.php');
    5656    }
     57
     58    /**
     59     * Defines if there should be a way to uninstall the plugin via the administration UI.
     60     * @return boolean
     61     */
     62    public function is_uninstall_allowed() {
     63        return true;
     64    }
     65
     66    /**
     67     * Pre-uninstall hook.
     68     * This is intended for disabling of plugin, some DB table purging, etc.
     69     */
     70    public function uninstall_cleanup() {
     71        global $DB;
     72
     73        // Get all instances of this portfolio.
     74        $count = $DB->count_records('portfolio_instance', array('plugin' => $this->name));
     75        if ($count > 0) {
     76            // This portfolio is in use, get the it's ID.
     77            $rec = $DB->get_record('portfolio_instance', array('plugin' => $this->name));
     78
     79            // Remove all records from portfolio_instance_config.
     80            $DB->delete_records('portfolio_instance_config', array('instance' => $rec->id));
     81            // Remove all records from portfolio_instance_user.
     82            $DB->delete_records('portfolio_instance_user', array('instance' => $rec->id));
     83            // Remove all records from portfolio_log.
     84            $DB->delete_records('portfolio_log', array('portfolio' => $rec->id));
     85            // Remove all records from portfolio_tempdata.
     86            $DB->delete_records('portfolio_tempdata', array('instance' => $rec->id));
     87
     88            // Remove the record from the portfolio_instance table.
     89            $DB->delete_records('portfolio_instance', array('id' => $rec->id));
     90        }
     91
     92        parent::uninstall_cleanup();
     93    }
    5794}
  • moodle/trunk/fuentes/lib/classes/plugininfo/repository.php

    r136 r1331  
    6868        return new moodle_url('/admin/repository.php');
    6969    }
     70
     71    /**
     72     * Defines if there should be a way to uninstall the plugin via the administration UI.
     73     * @return boolean
     74     */
     75    public function is_uninstall_allowed() {
     76        if ($this->name === 'upload' || $this->name === 'coursefiles' || $this->name === 'user' || $this->name === 'recent') {
     77            return false;
     78        } else {
     79            return true;
     80        }
     81    }
     82
     83    /**
     84     * Pre-uninstall hook.
     85     * This is intended for disabling of plugin, some DB table purging, etc.
     86     * Converts all linked files to standard files when repository is removed
     87     * and cleans up all records in the DB for that repository.
     88     */
     89    public function uninstall_cleanup() {
     90        global $CFG;
     91        require_once($CFG->dirroot.'/repository/lib.php');
     92
     93        $repo = \repository::get_type_by_typename($this->name);
     94        if ($repo) {
     95            $repo->delete(true);
     96        }
     97
     98        parent::uninstall_cleanup();
     99    }
    70100}
  • moodle/trunk/fuentes/lib/classes/plugininfo/theme.php

    r136 r1331  
    3535        global $CFG;
    3636
    37         if ($this->name === 'standard' or $this->name === 'base' or $this->name === 'bootstrapbase') {
     37        if ($this->name === 'base' or $this->name === 'bootstrapbase') {
    3838            // All of these are protected for now.
    3939            return false;
Note: See TracChangeset for help on using the changeset viewer.