Ejemplo n.º 1
0
 /**
  * Update the database to contain a list of handlers for a component,
  * adding any handlers which do not exist in the database.
  *
  * @param string $componentname - The frankenstyle component name.
  */
 public static function create_missing_messageinbound_handlers_for_component($componentname)
 {
     global $DB;
     $componentname = \core_component::normalize_componentname($componentname);
     $expectedhandlers = self::load_default_handlers_for_component($componentname);
     foreach ($expectedhandlers as $handler) {
         $recordexists = $DB->record_exists('messageinbound_handlers', array('component' => $componentname, 'classname' => $handler->classname));
         if (!$recordexists) {
             $record = self::record_from_handler($handler);
             $record->component = $componentname;
             $DB->insert_record('messageinbound_handlers', $record);
         }
     }
 }
Ejemplo n.º 2
0
 public function test_normalize_componentname()
 {
     // Moodle core.
     $this->assertSame('core', core_component::normalize_componentname('core'));
     $this->assertSame('core', core_component::normalize_componentname('moodle'));
     $this->assertSame('core', core_component::normalize_componentname(''));
     // Moodle core subsystems.
     $this->assertSame('core_admin', core_component::normalize_componentname('admin'));
     $this->assertSame('core_admin', core_component::normalize_componentname('core_admin'));
     $this->assertSame('core_admin', core_component::normalize_componentname('moodle_admin'));
     // Activity modules and their subplugins.
     $this->assertSame('mod_workshop', core_component::normalize_componentname('workshop'));
     $this->assertSame('mod_workshop', core_component::normalize_componentname('mod_workshop'));
     $this->assertSame('workshopform_accumulative', core_component::normalize_componentname('workshopform_accumulative'));
     $this->assertSame('mod_quiz', core_component::normalize_componentname('quiz'));
     $this->assertSame('quiz_grading', core_component::normalize_componentname('quiz_grading'));
     $this->assertSame('mod_data', core_component::normalize_componentname('data'));
     $this->assertSame('datafield_checkbox', core_component::normalize_componentname('datafield_checkbox'));
     // Other plugin types.
     $this->assertSame('auth_mnet', core_component::normalize_componentname('auth_mnet'));
     $this->assertSame('enrol_self', core_component::normalize_componentname('enrol_self'));
     $this->assertSame('block_html', core_component::normalize_componentname('block_html'));
     $this->assertSame('block_mnet_hosts', core_component::normalize_componentname('block_mnet_hosts'));
     $this->assertSame('local_amos', core_component::normalize_componentname('local_amos'));
     $this->assertSame('local_admin', core_component::normalize_componentname('local_admin'));
     // Unknown words without underscore are supposed to be activity modules.
     $this->assertSame('mod_whoonearthwouldcomewithsuchastupidnameofcomponent', core_component::normalize_componentname('whoonearthwouldcomewithsuchastupidnameofcomponent'));
     // Module names can not contain underscores, this must be a subplugin.
     $this->assertSame('whoonearth_wouldcomewithsuchastupidnameofcomponent', core_component::normalize_componentname('whoonearth_wouldcomewithsuchastupidnameofcomponent'));
     $this->assertSame('whoonearth_would_come_withsuchastupidnameofcomponent', core_component::normalize_componentname('whoonearth_would_come_withsuchastupidnameofcomponent'));
 }
Ejemplo n.º 3
0
 public static function getPluginMetadata($courseformat = 'weeks')
 {
     global $CFG;
     $pluginmanager = \core_plugin_manager::instance();
     $meta = [];
     $plugintypes = \core_component::get_plugin_types();
     foreach ($plugintypes as $plugintype => $plugintypedir) {
         $plugins = \core_component::get_plugin_list($plugintype);
         foreach ($plugins as $pluginname => $plugindir) {
             $component = \core_component::normalize_componentname("{$plugintype}_{$pluginname}");
             $pluginfo = $pluginmanager->get_plugin_info($component);
             // format uses get_config() which we don't want to fake
             if ($plugintype == 'format') {
                 $can_uninstall = $pluginname != $courseformat;
             } else {
                 $can_uninstall = $pluginfo->is_uninstall_allowed();
             }
             $meta[$component] = ['type' => $plugintype, 'dir' => str_replace($CFG->dirroot, '', $plugindir), 'can_uninstall' => $can_uninstall, 'versioninfo' => (array) self::getVersionInfo($plugindir)];
         }
     }
     return $meta;
 }