3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Various upgrade/install related functions and classes.
23 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die();
29 /** UPGRADE_LOG_NORMAL = 0 */
30 define('UPGRADE_LOG_NORMAL', 0);
31 /** UPGRADE_LOG_NOTICE = 1 */
32 define('UPGRADE_LOG_NOTICE', 1);
33 /** UPGRADE_LOG_ERROR = 2 */
34 define('UPGRADE_LOG_ERROR', 2);
37 * Exception indicating unknown error during upgrade.
41 * @copyright 2009 Petr Skoda {@link http://skodak.org}
42 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44 class upgrade_exception extends moodle_exception {
45 function __construct($plugin, $version, $debuginfo=NULL) {
47 $a = (object)array('plugin'=>$plugin, 'version'=>$version);
48 parent::__construct('upgradeerror', 'admin', "$CFG->wwwroot/$CFG->admin/index.php", $a, $debuginfo);
53 * Exception indicating downgrade error during upgrade.
57 * @copyright 2009 Petr Skoda {@link http://skodak.org}
58 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
60 class downgrade_exception extends moodle_exception {
61 function __construct($plugin, $oldversion, $newversion) {
63 $plugin = is_null($plugin) ? 'moodle' : $plugin;
64 $a = (object)array('plugin'=>$plugin, 'oldversion'=>$oldversion, 'newversion'=>$newversion);
65 parent::__construct('cannotdowngrade', 'debug', "$CFG->wwwroot/$CFG->admin/index.php", $a);
72 * @copyright 2009 Petr Skoda {@link http://skodak.org}
73 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
75 class upgrade_requires_exception extends moodle_exception {
76 function __construct($plugin, $pluginversion, $currentmoodle, $requiremoodle) {
79 $a->pluginname = $plugin;
80 $a->pluginversion = $pluginversion;
81 $a->currentmoodle = $currentmoodle;
82 $a->requiremoodle = $requiremoodle;
83 parent::__construct('pluginrequirementsnotmet', 'error', "$CFG->wwwroot/$CFG->admin/index.php", $a);
90 * @copyright 2009 Petr Skoda {@link http://skodak.org}
91 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
93 class plugin_defective_exception extends moodle_exception {
94 function __construct($plugin, $details) {
96 parent::__construct('detectedbrokenplugin', 'error', "$CFG->wwwroot/$CFG->admin/index.php", $plugin, $details);
101 * Upgrade savepoint, marks end of each upgrade block.
102 * It stores new main version, resets upgrade timeout
103 * and abort upgrade if user cancels page loading.
105 * Please do not make large upgrade blocks with lots of operations,
106 * for example when adding tables keep only one table operation per block.
109 * @param bool $result false if upgrade step failed, true if completed
110 * @param string or float $version main version
111 * @param bool $allowabort allow user to abort script execution here
114 function upgrade_main_savepoint($result, $version, $allowabort=true) {
118 throw new upgrade_exception(null, $version);
121 if ($CFG->version >= $version) {
122 // something really wrong is going on in main upgrade script
123 throw new downgrade_exception(null, $CFG->version, $version);
126 set_config('version', $version);
127 upgrade_log(UPGRADE_LOG_NORMAL, null, 'Upgrade savepoint reached');
129 // reset upgrade timeout to default
130 upgrade_set_timeout();
132 // this is a safe place to stop upgrades if user aborts page loading
133 if ($allowabort and connection_aborted()) {
139 * Module upgrade savepoint, marks end of module upgrade blocks
140 * It stores module version, resets upgrade timeout
141 * and abort upgrade if user cancels page loading.
144 * @param bool $result false if upgrade step failed, true if completed
145 * @param string or float $version main version
146 * @param string $modname name of module
147 * @param bool $allowabort allow user to abort script execution here
150 function upgrade_mod_savepoint($result, $version, $modname, $allowabort=true) {
154 throw new upgrade_exception("mod_$modname", $version);
157 if (!$module = $DB->get_record('modules', array('name'=>$modname))) {
158 print_error('modulenotexist', 'debug', '', $modname);
161 if ($module->version >= $version) {
162 // something really wrong is going on in upgrade script
163 throw new downgrade_exception("mod_$modname", $module->version, $version);
165 $module->version = $version;
166 $DB->update_record('modules', $module);
167 upgrade_log(UPGRADE_LOG_NORMAL, "mod_$modname", 'Upgrade savepoint reached');
169 // reset upgrade timeout to default
170 upgrade_set_timeout();
172 // this is a safe place to stop upgrades if user aborts page loading
173 if ($allowabort and connection_aborted()) {
179 * Blocks upgrade savepoint, marks end of blocks upgrade blocks
180 * It stores block version, resets upgrade timeout
181 * and abort upgrade if user cancels page loading.
184 * @param bool $result false if upgrade step failed, true if completed
185 * @param string or float $version main version
186 * @param string $blockname name of block
187 * @param bool $allowabort allow user to abort script execution here
190 function upgrade_block_savepoint($result, $version, $blockname, $allowabort=true) {
194 throw new upgrade_exception("block_$blockname", $version);
197 if (!$block = $DB->get_record('block', array('name'=>$blockname))) {
198 print_error('blocknotexist', 'debug', '', $blockname);
201 if ($block->version >= $version) {
202 // something really wrong is going on in upgrade script
203 throw new downgrade_exception("block_$blockname", $block->version, $version);
205 $block->version = $version;
206 $DB->update_record('block', $block);
207 upgrade_log(UPGRADE_LOG_NORMAL, "block_$blockname", 'Upgrade savepoint reached');
209 // reset upgrade timeout to default
210 upgrade_set_timeout();
212 // this is a safe place to stop upgrades if user aborts page loading
213 if ($allowabort and connection_aborted()) {
219 * Plugins upgrade savepoint, marks end of blocks upgrade blocks
220 * It stores plugin version, resets upgrade timeout
221 * and abort upgrade if user cancels page loading.
223 * @param bool $result false if upgrade step failed, true if completed
224 * @param string or float $version main version
225 * @param string $type name of plugin
226 * @param string $dir location of plugin
227 * @param bool $allowabort allow user to abort script execution here
230 function upgrade_plugin_savepoint($result, $version, $type, $plugin, $allowabort=true) {
231 $component = $type.'_'.$plugin;
234 throw new upgrade_exception($component, $version);
237 $installedversion = get_config($component, 'version');
238 if ($installedversion >= $version) {
239 // Something really wrong is going on in the upgrade script
240 throw new downgrade_exception($component, $installedversion, $version);
242 set_config('version', $version, $component);
243 upgrade_log(UPGRADE_LOG_NORMAL, $component, 'Upgrade savepoint reached');
245 // Reset upgrade timeout to default
246 upgrade_set_timeout();
248 // This is a safe place to stop upgrades if user aborts page loading
249 if ($allowabort and connection_aborted()) {
257 * @param string $type The type of plugins that should be updated (e.g. 'enrol', 'qtype')
260 function upgrade_plugins($type, $startcallback, $endcallback, $verbose) {
264 if ($type === 'mod') {
265 return upgrade_plugins_modules($startcallback, $endcallback, $verbose);
266 } else if ($type === 'block') {
267 return upgrade_plugins_blocks($startcallback, $endcallback, $verbose);
270 $plugs = get_plugin_list($type);
272 foreach ($plugs as $plug=>$fullplug) {
273 $component = $type.'_'.$plug; // standardised plugin name
275 if (!is_readable($fullplug.'/version.php')) {
279 $plugin = new stdClass();
280 require($fullplug.'/version.php'); // defines $plugin with version etc
282 if (empty($plugin->version)) {
283 throw new plugin_defective_exception($component, 'Missing version value in version.php');
286 $plugin->name = $plug;
287 $plugin->fullname = $component;
290 if (!empty($plugin->requires)) {
291 if ($plugin->requires > $CFG->version) {
292 throw new upgrade_requires_exception($component, $plugin->version, $CFG->version, $plugin->requires);
293 } else if ($plugin->requires < 2010000000) {
294 throw new plugin_defective_exception($component, 'Plugin is not compatible with Moodle 2.x or later.');
298 // try to recover from interrupted install.php if needed
299 if (file_exists($fullplug.'/db/install.php')) {
300 if (get_config($plugin->fullname, 'installrunning')) {
301 require_once($fullplug.'/db/install.php');
302 $recover_install_function = 'xmldb_'.$plugin->fullname.'_install_recovery';
303 if (function_exists($recover_install_function)) {
304 $startcallback($component, true, $verbose);
305 $recover_install_function();
306 unset_config('installrunning', $plugin->fullname);
307 update_capabilities($component);
308 log_update_descriptions($component);
309 external_update_descriptions($component);
310 events_update_definition($component);
311 message_update_providers($component);
312 upgrade_plugin_mnet_functions($component);
313 $endcallback($component, true, $verbose);
318 $installedversion = get_config($plugin->fullname, 'version');
319 if (empty($installedversion)) { // new installation
320 $startcallback($component, true, $verbose);
322 /// Install tables if defined
323 if (file_exists($fullplug.'/db/install.xml')) {
324 $DB->get_manager()->install_from_xmldb_file($fullplug.'/db/install.xml');
328 upgrade_plugin_savepoint(true, $plugin->version, $type, $plug, false);
330 /// execute post install file
331 if (file_exists($fullplug.'/db/install.php')) {
332 require_once($fullplug.'/db/install.php');
333 set_config('installrunning', 1, $plugin->fullname);
334 $post_install_function = 'xmldb_'.$plugin->fullname.'_install';
335 $post_install_function();
336 unset_config('installrunning', $plugin->fullname);
339 /// Install various components
340 update_capabilities($component);
341 log_update_descriptions($component);
342 external_update_descriptions($component);
343 events_update_definition($component);
344 message_update_providers($component);
345 upgrade_plugin_mnet_functions($component);
348 $endcallback($component, true, $verbose);
350 } else if ($installedversion < $plugin->version) { // upgrade
351 /// Run the upgrade function for the plugin.
352 $startcallback($component, false, $verbose);
354 if (is_readable($fullplug.'/db/upgrade.php')) {
355 require_once($fullplug.'/db/upgrade.php'); // defines upgrading function
357 $newupgrade_function = 'xmldb_'.$plugin->fullname.'_upgrade';
358 $result = $newupgrade_function($installedversion);
363 $installedversion = get_config($plugin->fullname, 'version');
364 if ($installedversion < $plugin->version) {
365 // store version if not already there
366 upgrade_plugin_savepoint($result, $plugin->version, $type, $plug, false);
369 /// Upgrade various components
370 update_capabilities($component);
371 log_update_descriptions($component);
372 external_update_descriptions($component);
373 events_update_definition($component);
374 message_update_providers($component);
375 upgrade_plugin_mnet_functions($component);
378 $endcallback($component, false, $verbose);
380 } else if ($installedversion > $plugin->version) {
381 throw new downgrade_exception($component, $installedversion, $plugin->version);
387 * Find and check all modules and load them up or upgrade them if necessary
392 function upgrade_plugins_modules($startcallback, $endcallback, $verbose) {
395 $mods = get_plugin_list('mod');
397 foreach ($mods as $mod=>$fullmod) {
399 if ($mod == 'NEWMODULE') { // Someone has unzipped the template, ignore it
403 $component = 'mod_'.$mod;
405 if (!is_readable($fullmod.'/version.php')) {
406 throw new plugin_defective_exception($component, 'Missing version.php');
409 $module = new stdClass();
410 require($fullmod .'/version.php'); // defines $module with version etc
412 if (empty($module->version)) {
413 if (isset($module->version)) {
414 // Version is empty but is set - it means its value is 0 or ''. Let us skip such module.
415 // This is intended for developers so they can work on the early stages of the module.
418 throw new plugin_defective_exception($component, 'Missing version value in version.php');
421 if (!empty($module->requires)) {
422 if ($module->requires > $CFG->version) {
423 throw new upgrade_requires_exception($component, $module->version, $CFG->version, $module->requires);
424 } else if ($module->requires < 2010000000) {
425 throw new plugin_defective_exception($component, 'Plugin is not compatible with Moodle 2.x or later.');
429 $module->name = $mod; // The name MUST match the directory
431 $currmodule = $DB->get_record('modules', array('name'=>$module->name));
433 if (file_exists($fullmod.'/db/install.php')) {
434 if (get_config($module->name, 'installrunning')) {
435 require_once($fullmod.'/db/install.php');
436 $recover_install_function = 'xmldb_'.$module->name.'_install_recovery';
437 if (function_exists($recover_install_function)) {
438 $startcallback($component, true, $verbose);
439 $recover_install_function();
440 unset_config('installrunning', $module->name);
441 // Install various components too
442 update_capabilities($component);
443 log_update_descriptions($component);
444 external_update_descriptions($component);
445 events_update_definition($component);
446 message_update_providers($component);
447 upgrade_plugin_mnet_functions($component);
448 $endcallback($component, true, $verbose);
453 if (empty($currmodule->version)) {
454 $startcallback($component, true, $verbose);
456 /// Execute install.xml (XMLDB) - must be present in all modules
457 $DB->get_manager()->install_from_xmldb_file($fullmod.'/db/install.xml');
459 /// Add record into modules table - may be needed in install.php already
460 $module->id = $DB->insert_record('modules', $module);
462 /// Post installation hook - optional
463 if (file_exists("$fullmod/db/install.php")) {
464 require_once("$fullmod/db/install.php");
465 // Set installation running flag, we need to recover after exception or error
466 set_config('installrunning', 1, $module->name);
467 $post_install_function = 'xmldb_'.$module->name.'_install';;
468 $post_install_function();
469 unset_config('installrunning', $module->name);
472 /// Install various components
473 update_capabilities($component);
474 log_update_descriptions($component);
475 external_update_descriptions($component);
476 events_update_definition($component);
477 message_update_providers($component);
478 upgrade_plugin_mnet_functions($component);
481 $endcallback($component, true, $verbose);
483 } else if ($currmodule->version < $module->version) {
484 /// If versions say that we need to upgrade but no upgrade files are available, notify and continue
485 $startcallback($component, false, $verbose);
487 if (is_readable($fullmod.'/db/upgrade.php')) {
488 require_once($fullmod.'/db/upgrade.php'); // defines new upgrading function
489 $newupgrade_function = 'xmldb_'.$module->name.'_upgrade';
490 $result = $newupgrade_function($currmodule->version, $module);
495 $currmodule = $DB->get_record('modules', array('name'=>$module->name));
496 if ($currmodule->version < $module->version) {
497 // store version if not already there
498 upgrade_mod_savepoint($result, $module->version, $mod, false);
501 /// Upgrade various components
502 update_capabilities($component);
503 log_update_descriptions($component);
504 external_update_descriptions($component);
505 events_update_definition($component);
506 message_update_providers($component);
507 upgrade_plugin_mnet_functions($component);
511 $endcallback($component, false, $verbose);
513 } else if ($currmodule->version > $module->version) {
514 throw new downgrade_exception($component, $currmodule->version, $module->version);
521 * This function finds all available blocks and install them
522 * into blocks table or do all the upgrade process if newer.
527 function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) {
530 require_once($CFG->dirroot.'/blocks/moodleblock.class.php');
532 $blocktitles = array(); // we do not want duplicate titles
534 //Is this a first install
535 $first_install = null;
537 $blocks = get_plugin_list('block');
539 foreach ($blocks as $blockname=>$fullblock) {
541 if (is_null($first_install)) {
542 $first_install = ($DB->count_records('block_instances') == 0);
545 if ($blockname == 'NEWBLOCK') { // Someone has unzipped the template, ignore it
549 $component = 'block_'.$blockname;
551 if (!is_readable($fullblock.'/version.php')) {
552 throw new plugin_defective_exception('block/'.$blockname, 'Missing version.php file.');
554 $plugin = new stdClass();
555 $plugin->version = NULL;
557 include($fullblock.'/version.php');
560 if (!empty($plugin->requires)) {
561 if ($plugin->requires > $CFG->version) {
562 throw new upgrade_requires_exception($component, $plugin->version, $CFG->version, $plugin->requires);
563 } else if ($plugin->requires < 2010000000) {
564 throw new plugin_defective_exception($component, 'Plugin is not compatible with Moodle 2.x or later.');
568 if (!is_readable($fullblock.'/block_'.$blockname.'.php')) {
569 throw new plugin_defective_exception('block/'.$blockname, 'Missing main block class file.');
571 include_once($fullblock.'/block_'.$blockname.'.php');
573 $classname = 'block_'.$blockname;
575 if (!class_exists($classname)) {
576 throw new plugin_defective_exception($component, 'Can not load main class.');
579 $blockobj = new $classname; // This is what we'll be testing
580 $blocktitle = $blockobj->get_title();
582 // OK, it's as we all hoped. For further tests, the object will do them itself.
583 if (!$blockobj->_self_test()) {
584 throw new plugin_defective_exception($component, 'Self test failed.');
587 $block->name = $blockname; // The name MUST match the directory
589 if (empty($block->version)) {
590 throw new plugin_defective_exception($component, 'Missing block version.');
593 $currblock = $DB->get_record('block', array('name'=>$block->name));
595 if (file_exists($fullblock.'/db/install.php')) {
596 if (get_config('block_'.$blockname, 'installrunning')) {
597 require_once($fullblock.'/db/install.php');
598 $recover_install_function = 'xmldb_block_'.$blockname.'_install_recovery';
599 if (function_exists($recover_install_function)) {
600 $startcallback($component, true, $verbose);
601 $recover_install_function();
602 unset_config('installrunning', 'block_'.$blockname);
603 // Install various components
604 update_capabilities($component);
605 log_update_descriptions($component);
606 external_update_descriptions($component);
607 events_update_definition($component);
608 message_update_providers($component);
609 upgrade_plugin_mnet_functions($component);
610 $endcallback($component, true, $verbose);
615 if (empty($currblock->version)) { // block not installed yet, so install it
616 $conflictblock = array_search($blocktitle, $blocktitles);
617 if ($conflictblock !== false) {
618 // Duplicate block titles are not allowed, they confuse people
619 // AND PHP's associative arrays ;)
620 throw new plugin_defective_exception($component, get_string('blocknameconflict', '', (object)array('name'=>$block->name, 'conflict'=>$conflictblock)));
622 $startcallback($component, true, $verbose);
624 if (file_exists($fullblock.'/db/install.xml')) {
625 $DB->get_manager()->install_from_xmldb_file($fullblock.'/db/install.xml');
627 $block->id = $DB->insert_record('block', $block);
629 if (file_exists($fullblock.'/db/install.php')) {
630 require_once($fullblock.'/db/install.php');
631 // Set installation running flag, we need to recover after exception or error
632 set_config('installrunning', 1, 'block_'.$blockname);
633 $post_install_function = 'xmldb_block_'.$blockname.'_install';;
634 $post_install_function();
635 unset_config('installrunning', 'block_'.$blockname);
638 $blocktitles[$block->name] = $blocktitle;
640 // Install various components
641 update_capabilities($component);
642 log_update_descriptions($component);
643 external_update_descriptions($component);
644 events_update_definition($component);
645 message_update_providers($component);
646 upgrade_plugin_mnet_functions($component);
649 $endcallback($component, true, $verbose);
651 } else if ($currblock->version < $block->version) {
652 $startcallback($component, false, $verbose);
654 if (is_readable($fullblock.'/db/upgrade.php')) {
655 require_once($fullblock.'/db/upgrade.php'); // defines new upgrading function
656 $newupgrade_function = 'xmldb_block_'.$blockname.'_upgrade';
657 $result = $newupgrade_function($currblock->version, $block);
662 $currblock = $DB->get_record('block', array('name'=>$block->name));
663 if ($currblock->version < $block->version) {
664 // store version if not already there
665 upgrade_block_savepoint($result, $block->version, $block->name, false);
668 if ($currblock->cron != $block->cron) {
669 // update cron flag if needed
670 $currblock->cron = $block->cron;
671 $DB->update_record('block', $currblock);
674 // Upgrade various components
675 update_capabilities($component);
676 log_update_descriptions($component);
677 external_update_descriptions($component);
678 events_update_definition($component);
679 message_update_providers($component);
680 upgrade_plugin_mnet_functions($component);
683 $endcallback($component, false, $verbose);
685 } else if ($currblock->version > $block->version) {
686 throw new downgrade_exception($component, $currblock->version, $block->version);
691 // Finally, if we are in the first_install of BLOCKS setup frontpage and admin page blocks
692 if ($first_install) {
693 //Iterate over each course - there should be only site course here now
694 if ($courses = $DB->get_records('course')) {
695 foreach ($courses as $course) {
696 blocks_add_default_course_blocks($course);
700 blocks_add_default_system_blocks();
706 * Log_display description function used during install and upgrade.
708 * @param string $component name of component (moodle, mod_assignment, etc.)
711 function log_update_descriptions($component) {
714 $defpath = get_component_directory($component).'/db/log.php';
716 if (!file_exists($defpath)) {
717 $DB->delete_records('log_display', array('component'=>$component));
725 foreach ($logs as $log) {
726 $newlogs[$log['module'].'-'.$log['action']] = $log; // kind of unique name
731 $fields = array('module', 'action', 'mtable', 'field');
732 // update all log fist
733 $dblogs = $DB->get_records('log_display', array('component'=>$component));
734 foreach ($dblogs as $dblog) {
735 $name = $dblog->module.'-'.$dblog->action;
737 if (empty($logs[$name])) {
738 $DB->delete_records('log_display', array('id'=>$dblog->id));
746 foreach ($fields as $field) {
747 if ($dblog->$field != $log[$field]) {
748 $dblog->$field = $log[$field];
753 $DB->update_record('log_display', $dblog);
756 foreach ($logs as $log) {
757 $dblog = (object)$log;
758 $dblog->component = $component;
759 $DB->insert_record('log_display', $dblog);
764 * Web service discovery function used during install and upgrade.
765 * @param string $component name of component (moodle, mod_assignment, etc.)
768 function external_update_descriptions($component) {
771 $defpath = get_component_directory($component).'/db/services.php';
773 if (!file_exists($defpath)) {
774 external_delete_descriptions($component);
779 $functions = array();
783 // update all function fist
784 $dbfunctions = $DB->get_records('external_functions', array('component'=>$component));
785 foreach ($dbfunctions as $dbfunction) {
786 if (empty($functions[$dbfunction->name])) {
787 $DB->delete_records('external_functions', array('id'=>$dbfunction->id));
788 // do not delete functions from external_services_functions, beacuse
789 // we want to notify admins when functions used in custom services disappear
791 //TODO: this looks wrong, we have to delete it eventually (skodak)
795 $function = $functions[$dbfunction->name];
796 unset($functions[$dbfunction->name]);
797 $function['classpath'] = empty($function['classpath']) ? null : $function['classpath'];
800 if ($dbfunction->classname != $function['classname']) {
801 $dbfunction->classname = $function['classname'];
804 if ($dbfunction->methodname != $function['methodname']) {
805 $dbfunction->methodname = $function['methodname'];
808 if ($dbfunction->classpath != $function['classpath']) {
809 $dbfunction->classpath = $function['classpath'];
812 $functioncapabilities = key_exists('capabilities', $function)?$function['capabilities']:'';
813 if ($dbfunction->capabilities != $functioncapabilities) {
814 $dbfunction->capabilities = $functioncapabilities;
818 $DB->update_record('external_functions', $dbfunction);
821 foreach ($functions as $fname => $function) {
822 $dbfunction = new stdClass();
823 $dbfunction->name = $fname;
824 $dbfunction->classname = $function['classname'];
825 $dbfunction->methodname = $function['methodname'];
826 $dbfunction->classpath = empty($function['classpath']) ? null : $function['classpath'];
827 $dbfunction->component = $component;
828 $dbfunction->capabilities = key_exists('capabilities', $function)?$function['capabilities']:'';
829 $dbfunction->id = $DB->insert_record('external_functions', $dbfunction);
833 // now deal with services
834 $dbservices = $DB->get_records('external_services', array('component'=>$component));
835 foreach ($dbservices as $dbservice) {
836 if (empty($services[$dbservice->name])) {
837 $DB->delete_records('external_services_functions', array('externalserviceid'=>$dbservice->id));
838 $DB->delete_records('external_services_users', array('externalserviceid'=>$dbservice->id));
839 $DB->delete_records('external_services', array('id'=>$dbservice->id));
842 $service = $services[$dbservice->name];
843 unset($services[$dbservice->name]);
844 $service['enabled'] = empty($service['enabled']) ? 0 : $service['enabled'];
845 $service['requiredcapability'] = empty($service['requiredcapability']) ? null : $service['requiredcapability'];
846 $service['restrictedusers'] = !isset($service['restrictedusers']) ? 1 : $service['restrictedusers'];
849 if ($dbservice->enabled != $service['enabled']) {
850 $dbservice->enabled = $service['enabled'];
853 if ($dbservice->requiredcapability != $service['requiredcapability']) {
854 $dbservice->requiredcapability = $service['requiredcapability'];
857 if ($dbservice->restrictedusers != $service['restrictedusers']) {
858 $dbservice->restrictedusers = $service['restrictedusers'];
862 $DB->update_record('external_services', $dbservice);
865 $functions = $DB->get_records('external_services_functions', array('externalserviceid'=>$dbservice->id));
866 foreach ($functions as $function) {
867 $key = array_search($function->functionname, $service['functions']);
868 if ($key === false) {
869 $DB->delete_records('external_services_functions', array('id'=>$function->id));
871 unset($service['functions'][$key]);
874 foreach ($service['functions'] as $fname) {
875 $newf = new stdClass();
876 $newf->externalserviceid = $dbservice->id;
877 $newf->functionname = $fname;
878 $DB->insert_record('external_services_functions', $newf);
882 foreach ($services as $name => $service) {
883 $dbservice = new stdClass();
884 $dbservice->name = $name;
885 $dbservice->enabled = empty($service['enabled']) ? 0 : $service['enabled'];
886 $dbservice->requiredcapability = empty($service['requiredcapability']) ? null : $service['requiredcapability'];
887 $dbservice->restrictedusers = !isset($service['restrictedusers']) ? 1 : $service['restrictedusers'];
888 $dbservice->component = $component;
889 $dbservice->timecreated = time();
890 $dbservice->id = $DB->insert_record('external_services', $dbservice);
891 foreach ($service['functions'] as $fname) {
892 $newf = new stdClass();
893 $newf->externalserviceid = $dbservice->id;
894 $newf->functionname = $fname;
895 $DB->insert_record('external_services_functions', $newf);
901 * Delete all service and external functions information defined in the specified component.
902 * @param string $component name of component (moodle, mod_assignment, etc.)
905 function external_delete_descriptions($component) {
908 $params = array($component);
910 $DB->delete_records_select('external_services_users', "externalserviceid IN (SELECT id FROM {external_services} WHERE component = ?)", $params);
911 $DB->delete_records_select('external_services_functions', "externalserviceid IN (SELECT id FROM {external_services} WHERE component = ?)", $params);
912 $DB->delete_records('external_services', array('component'=>$component));
913 $DB->delete_records('external_functions', array('component'=>$component));
917 * upgrade logging functions
919 function upgrade_handle_exception($ex, $plugin = null) {
922 // rollback everything, we need to log all upgrade problems
923 abort_all_db_transactions();
925 $info = get_exception_info($ex);
927 // First log upgrade error
928 upgrade_log(UPGRADE_LOG_ERROR, $plugin, 'Exception: ' . get_class($ex), $info->message, $info->backtrace);
930 // Always turn on debugging - admins need to know what is going on
931 $CFG->debug = DEBUG_DEVELOPER;
933 default_exception_handler($ex, true, $plugin);
937 * Adds log entry into upgrade_log table
942 * @param int $type UPGRADE_LOG_NORMAL, UPGRADE_LOG_NOTICE or UPGRADE_LOG_ERROR
943 * @param string $plugin plugin or null if main
944 * @param string $info short description text of log entry
945 * @param string $details long problem description
946 * @param string $backtrace string used for errors only
949 function upgrade_log($type, $plugin, $info, $details=null, $backtrace=null) {
950 global $DB, $USER, $CFG;
952 $plugin = ($plugin==='moodle') ? null : $plugin;
954 $backtrace = format_backtrace($backtrace, true);
958 //first try to find out current version number
959 if (empty($plugin) or $plugin === 'moodle') {
961 $version = $CFG->version;
963 } else if ($plugin === 'local') {
965 $version = $CFG->local_version;
967 } else if (strpos($plugin, 'mod/') === 0) {
969 $modname = substr($plugin, strlen('mod/'));
970 $version = $DB->get_field('modules', 'version', array('name'=>$modname));
971 $version = ($version === false) ? null : $version;
972 } catch (Exception $ignored) {
975 } else if (strpos($plugin, 'block/') === 0) {
977 $blockname = substr($plugin, strlen('block/'));
978 if ($block = $DB->get_record('block', array('name'=>$blockname))) {
979 $version = $block->version;
981 } catch (Exception $ignored) {
985 $pluginversion = get_config(str_replace('/', '_', $plugin), 'version');
986 if (!empty($pluginversion)) {
987 $version = $pluginversion;
991 $log = new stdClass();
993 $log->plugin = $plugin;
994 $log->version = $version;
996 $log->details = $details;
997 $log->backtrace = $backtrace;
998 $log->userid = $USER->id;
999 $log->timemodified = time();
1001 $DB->insert_record('upgrade_log', $log);
1002 } catch (Exception $ignored) {
1003 // possible during install or 2.0 upgrade
1008 * Marks start of upgrade, blocks any other access to site.
1009 * The upgrade is finished at the end of script or after timeout.
1015 function upgrade_started($preinstall=false) {
1016 global $CFG, $DB, $PAGE, $OUTPUT;
1018 static $started = false;
1021 ignore_user_abort(true);
1022 upgrade_setup_debug(true);
1024 } else if ($started) {
1025 upgrade_set_timeout(120);
1028 if (!CLI_SCRIPT and !$PAGE->headerprinted) {
1029 $strupgrade = get_string('upgradingversion', 'admin');
1030 $PAGE->set_pagelayout('maintenance');
1031 upgrade_init_javascript();
1032 $PAGE->set_title($strupgrade.' - Moodle '.$CFG->target_release);
1033 $PAGE->set_heading($strupgrade);
1034 $PAGE->navbar->add($strupgrade);
1035 $PAGE->set_cacheable(false);
1036 echo $OUTPUT->header();
1039 ignore_user_abort(true);
1040 register_shutdown_function('upgrade_finished_handler');
1041 upgrade_setup_debug(true);
1042 set_config('upgraderunning', time()+300);
1048 * Internal function - executed if upgrade interrupted.
1050 function upgrade_finished_handler() {
1055 * Indicates upgrade is finished.
1057 * This function may be called repeatedly.
1062 function upgrade_finished($continueurl=null) {
1063 global $CFG, $DB, $OUTPUT;
1065 if (!empty($CFG->upgraderunning)) {
1066 unset_config('upgraderunning');
1067 upgrade_setup_debug(false);
1068 ignore_user_abort(false);
1070 echo $OUTPUT->continue_button($continueurl);
1071 echo $OUTPUT->footer();
1081 function upgrade_setup_debug($starting) {
1084 static $originaldebug = null;
1087 if ($originaldebug === null) {
1088 $originaldebug = $DB->get_debug();
1090 if (!empty($CFG->upgradeshowsql)) {
1091 $DB->set_debug(true);
1094 $DB->set_debug($originaldebug);
1101 function print_upgrade_reload($url) {
1105 echo '<div class="continuebutton">';
1106 echo '<a href="'.$url.'" title="'.get_string('reload').'" ><img src="'.$OUTPUT->pix_url('i/reload') . '" alt="" /> '.get_string('reload').'</a>';
1107 echo '</div><br />';
1110 function print_upgrade_separator() {
1117 * Default start upgrade callback
1118 * @param string $plugin
1119 * @param bool $installation true if installation, false means upgrade
1121 function print_upgrade_part_start($plugin, $installation, $verbose) {
1123 if (empty($plugin) or $plugin == 'moodle') {
1124 upgrade_started($installation); // does not store upgrade running flag yet
1126 echo $OUTPUT->heading(get_string('coresystem'));
1131 echo $OUTPUT->heading($plugin);
1134 if ($installation) {
1135 if (empty($plugin) or $plugin == 'moodle') {
1136 // no need to log - log table not yet there ;-)
1138 upgrade_log(UPGRADE_LOG_NORMAL, $plugin, 'Starting plugin installation');
1141 if (empty($plugin) or $plugin == 'moodle') {
1142 upgrade_log(UPGRADE_LOG_NORMAL, $plugin, 'Starting core upgrade');
1144 upgrade_log(UPGRADE_LOG_NORMAL, $plugin, 'Starting plugin upgrade');
1150 * Default end upgrade callback
1151 * @param string $plugin
1152 * @param bool $installation true if installation, false means upgrade
1154 function print_upgrade_part_end($plugin, $installation, $verbose) {
1157 if ($installation) {
1158 if (empty($plugin) or $plugin == 'moodle') {
1159 upgrade_log(UPGRADE_LOG_NORMAL, $plugin, 'Core installed');
1161 upgrade_log(UPGRADE_LOG_NORMAL, $plugin, 'Plugin installed');
1164 if (empty($plugin) or $plugin == 'moodle') {
1165 upgrade_log(UPGRADE_LOG_NORMAL, $plugin, 'Core upgraded');
1167 upgrade_log(UPGRADE_LOG_NORMAL, $plugin, 'Plugin upgraded');
1171 echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
1172 print_upgrade_separator();
1177 * Sets up JS code required for all upgrade scripts.
1180 function upgrade_init_javascript() {
1182 // scroll to the end of each upgrade page so that ppl see either error or continue button,
1183 // no need to scroll continuously any more, it is enough to jump to end once the footer is printed ;-)
1184 $js = "window.scrollTo(0, 5000000);";
1185 $PAGE->requires->js_init_code($js);
1190 * Try to upgrade the given language pack (or current language)
1192 * @todo hardcoded Moodle version here - shall be provided by version.php or similar script
1194 function upgrade_language_pack($lang='') {
1195 global $CFG, $OUTPUT;
1197 get_string_manager()->reset_caches();
1200 $lang = current_language();
1203 if ($lang == 'en') {
1204 return true; // Nothing to do
1207 upgrade_started(false);
1208 echo $OUTPUT->heading(get_string('langimport', 'admin').': '.$lang);
1210 @mkdir ($CFG->dataroot.'/temp/'); //make it in case it's a fresh install, it might not be there
1211 @mkdir ($CFG->dataroot.'/lang/');
1213 require_once($CFG->libdir.'/componentlib.class.php');
1215 if ($cd = new component_installer('http://download.moodle.org', 'langpack/2.0', $lang.'.zip', 'languages.md5', 'lang')) {
1216 $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
1218 if ($status == COMPONENT_INSTALLED) {
1219 remove_dir($CFG->dataroot.'/cache/languages');
1220 if ($parentlang = get_parent_language($lang)) {
1221 if ($cd = new component_installer('http://download.moodle.org', 'langpack/2.0', $parentlang.'.zip', 'languages.md5', 'lang')) {
1225 echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
1229 get_string_manager()->reset_caches();
1231 print_upgrade_separator();
1235 * Install core moodle tables and initialize
1236 * @param float $version target version
1237 * @param bool $verbose
1238 * @return void, may throw exception
1240 function install_core($version, $verbose) {
1244 set_time_limit(600);
1245 print_upgrade_part_start('moodle', true, $verbose); // does not store upgrade running flag
1247 $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
1248 upgrade_started(); // we want the flag to be stored in config table ;-)
1250 // set all core default records and default settings
1251 require_once("$CFG->libdir/db/install.php");
1252 xmldb_main_install(); // installs the capabilities too
1255 upgrade_main_savepoint(true, $version, false);
1257 // Continue with the installation
1258 log_update_descriptions('moodle');
1259 external_update_descriptions('moodle');
1260 events_update_definition('moodle');
1261 message_update_providers('moodle');
1263 // Write default settings unconditionally
1264 admin_apply_default_settings(NULL, true);
1266 print_upgrade_part_end(null, true, $verbose);
1267 } catch (exception $ex) {
1268 upgrade_handle_exception($ex);
1273 * Upgrade moodle core
1274 * @param float $version target version
1275 * @param bool $verbose
1276 * @return void, may throw exception
1278 function upgrade_core($version, $verbose) {
1281 raise_memory_limit(MEMORY_EXTRA);
1283 require_once($CFG->libdir.'/db/upgrade.php'); // Defines upgrades
1286 // Reset caches before any output
1289 // Upgrade current language pack if we can
1290 if (empty($CFG->skiplangupgrade)) {
1291 if (get_string_manager()->translation_exists(current_language())) {
1292 upgrade_language_pack(false);
1296 print_upgrade_part_start('moodle', false, $verbose);
1298 // one time special local migration pre 2.0 upgrade script
1299 if ($version < 2007101600) {
1300 $pre20upgradefile = "$CFG->dirrot/local/upgrade_pre20.php";
1301 if (file_exists($pre20upgradefile)) {
1303 require($pre20upgradefile);
1304 // reset upgrade timeout to default
1305 upgrade_set_timeout();
1309 $result = xmldb_main_upgrade($CFG->version);
1310 if ($version > $CFG->version) {
1311 // store version if not already there
1312 upgrade_main_savepoint($result, $version, false);
1315 // perform all other component upgrade routines
1316 update_capabilities('moodle');
1317 log_update_descriptions('moodle');
1318 external_update_descriptions('moodle');
1319 events_update_definition('moodle');
1320 message_update_providers('moodle');
1322 // Reset caches again, just to be sure
1325 // Clean up contexts - more and more stuff depends on existence of paths and contexts
1328 build_context_path();
1329 $syscontext = get_context_instance(CONTEXT_SYSTEM);
1330 mark_context_dirty($syscontext->path);
1332 print_upgrade_part_end('moodle', false, $verbose);
1333 } catch (Exception $ex) {
1334 upgrade_handle_exception($ex);
1339 * Upgrade/install other parts of moodle
1340 * @param bool $verbose
1341 * @return void, may throw exception
1343 function upgrade_noncore($verbose) {
1346 raise_memory_limit(MEMORY_EXTRA);
1348 // upgrade all plugins types
1350 $plugintypes = get_plugin_types();
1351 foreach ($plugintypes as $type=>$location) {
1352 upgrade_plugins($type, 'print_upgrade_part_start', 'print_upgrade_part_end', $verbose);
1354 } catch (Exception $ex) {
1355 upgrade_handle_exception($ex);
1360 * Checks if the main tables have been installed yet or not.
1363 function core_tables_exist() {
1366 if (!$tables = $DB->get_tables() ) { // No tables yet at all.
1369 } else { // Check for missing main tables
1370 $mtables = array('config', 'course', 'groupings'); // some tables used in 1.9 and 2.0, preferable something from the start and end of install.xml
1371 foreach ($mtables as $mtable) {
1372 if (!in_array($mtable, $tables)) {
1381 * upgrades the mnet rpc definitions for the given component.
1382 * this method doesn't return status, an exception will be thrown in the case of an error
1384 * @param string $component the plugin to upgrade, eg auth_mnet
1386 function upgrade_plugin_mnet_functions($component) {
1389 list($type, $plugin) = explode('_', $component);
1390 $path = get_plugin_directory($type, $plugin);
1392 $publishes = array();
1393 $subscribes = array();
1394 if (file_exists($path . '/db/mnet.php')) {
1395 require_once($path . '/db/mnet.php'); // $publishes comes from this file
1397 if (empty($publishes)) {
1398 $publishes = array(); // still need this to be able to disable stuff later
1400 if (empty($subscribes)) {
1401 $subscribes = array(); // still need this to be able to disable stuff later
1404 static $servicecache = array();
1406 // rekey an array based on the rpc method for easy lookups later
1407 $publishmethodservices = array();
1408 $subscribemethodservices = array();
1409 foreach($publishes as $servicename => $service) {
1410 if (is_array($service['methods'])) {
1411 foreach($service['methods'] as $methodname) {
1412 $service['servicename'] = $servicename;
1413 $publishmethodservices[$methodname][] = $service;
1418 // Disable functions that don't exist (any more) in the source
1419 // Should these be deleted? What about their permissions records?
1420 foreach ($DB->get_records('mnet_rpc', array('pluginname'=>$plugin, 'plugintype'=>$type), 'functionname ASC ') as $rpc) {
1421 if (!array_key_exists($rpc->functionname, $publishmethodservices) && $rpc->enabled) {
1422 $DB->set_field('mnet_rpc', 'enabled', 0, array('id' => $rpc->id));
1423 } else if (array_key_exists($rpc->functionname, $publishmethodservices) && !$rpc->enabled) {
1424 $DB->set_field('mnet_rpc', 'enabled', 1, array('id' => $rpc->id));
1428 // reflect all the services we're publishing and save them
1429 require_once($CFG->dirroot . '/lib/zend/Zend/Server/Reflection.php');
1430 static $cachedclasses = array(); // to store reflection information in
1431 foreach ($publishes as $service => $data) {
1432 $f = $data['filename'];
1433 $c = $data['classname'];
1434 foreach ($data['methods'] as $method) {
1435 $dataobject = new stdClass();
1436 $dataobject->plugintype = $type;
1437 $dataobject->pluginname = $plugin;
1438 $dataobject->enabled = 1;
1439 $dataobject->classname = $c;
1440 $dataobject->filename = $f;
1442 if (is_string($method)) {
1443 $dataobject->functionname = $method;
1445 } else if (is_array($method)) { // wants to override file or class
1446 $dataobject->functionname = $method['method'];
1447 $dataobject->classname = $method['classname'];
1448 $dataobject->filename = $method['filename'];
1450 $dataobject->xmlrpcpath = $type.'/'.$plugin.'/'.$dataobject->filename.'/'.$method;
1451 $dataobject->static = false;
1453 require_once($path . '/' . $dataobject->filename);
1454 $functionreflect = null; // slightly different ways to get this depending on whether it's a class method or a function
1455 if (!empty($dataobject->classname)) {
1456 if (!class_exists($dataobject->classname)) {
1457 throw new moodle_exception('installnosuchmethod', 'mnet', '', (object)array('method' => $dataobject->functionname, 'class' => $dataobject->classname));
1459 $key = $dataobject->filename . '|' . $dataobject->classname;
1460 if (!array_key_exists($key, $cachedclasses)) { // look to see if we've already got a reflection object
1462 $cachedclasses[$key] = Zend_Server_Reflection::reflectClass($dataobject->classname);
1463 } catch (Zend_Server_Reflection_Exception $e) { // catch these and rethrow them to something more helpful
1464 throw new moodle_exception('installreflectionclasserror', 'mnet', '', (object)array('method' => $dataobject->functionname, 'class' => $dataobject->classname, 'error' => $e->getMessage()));
1467 $r =& $cachedclasses[$key];
1468 if (!$r->hasMethod($dataobject->functionname)) {
1469 throw new moodle_exception('installnosuchmethod', 'mnet', '', (object)array('method' => $dataobject->functionname, 'class' => $dataobject->classname));
1471 // stupid workaround for zend not having a getMethod($name) function
1472 $ms = $r->getMethods();
1473 foreach ($ms as $m) {
1474 if ($m->getName() == $dataobject->functionname) {
1475 $functionreflect = $m;
1479 $dataobject->static = (int)$functionreflect->isStatic();
1481 if (!function_exists($dataobject->functionname)) {
1482 throw new moodle_exception('installnosuchfunction', 'mnet', '', (object)array('method' => $dataobject->functionname, 'file' => $dataobject->filename));
1485 $functionreflect = Zend_Server_Reflection::reflectFunction($dataobject->functionname);
1486 } catch (Zend_Server_Reflection_Exception $e) { // catch these and rethrow them to something more helpful
1487 throw new moodle_exception('installreflectionfunctionerror', 'mnet', '', (object)array('method' => $dataobject->functionname, '' => $dataobject->filename, 'error' => $e->getMessage()));
1490 $dataobject->profile = serialize(admin_mnet_method_profile($functionreflect));
1491 $dataobject->help = $functionreflect->getDescription();
1493 if ($record_exists = $DB->get_record('mnet_rpc', array('xmlrpcpath'=>$dataobject->xmlrpcpath))) {
1494 $dataobject->id = $record_exists->id;
1495 $dataobject->enabled = $record_exists->enabled;
1496 $DB->update_record('mnet_rpc', $dataobject);
1498 $dataobject->id = $DB->insert_record('mnet_rpc', $dataobject, true);
1501 // TODO this API versioning must be reworked, here the recently processed method
1502 // sets the service API which may not be correct
1503 foreach ($publishmethodservices[$dataobject->functionname] as $service) {
1504 if ($serviceobj = $DB->get_record('mnet_service', array('name'=>$service['servicename']))) {
1505 $serviceobj->apiversion = $service['apiversion'];
1506 $DB->update_record('mnet_service', $serviceobj);
1508 $serviceobj = new stdClass();
1509 $serviceobj->name = $service['servicename'];
1510 $serviceobj->apiversion = $service['apiversion'];
1511 $serviceobj->offer = 1;
1512 $serviceobj->id = $DB->insert_record('mnet_service', $serviceobj);
1514 $servicecache[$service['servicename']] = $serviceobj;
1515 if (!$DB->record_exists('mnet_service2rpc', array('rpcid'=>$dataobject->id, 'serviceid'=>$serviceobj->id))) {
1516 $obj = new stdClass();
1517 $obj->rpcid = $dataobject->id;
1518 $obj->serviceid = $serviceobj->id;
1519 $DB->insert_record('mnet_service2rpc', $obj, true);
1524 // finished with methods we publish, now do subscribable methods
1525 foreach($subscribes as $service => $methods) {
1526 if (!array_key_exists($service, $servicecache)) {
1527 if (!$serviceobj = $DB->get_record('mnet_service', array('name' => $service))) {
1528 debugging("TODO: skipping unknown service $service - somebody needs to fix MDL-21993");
1531 $servicecache[$service] = $serviceobj;
1533 $serviceobj = $servicecache[$service];
1535 foreach ($methods as $method => $xmlrpcpath) {
1536 if (!$rpcid = $DB->get_field('mnet_remote_rpc', 'id', array('xmlrpcpath'=>$xmlrpcpath))) {
1537 $remoterpc = (object)array(
1538 'functionname' => $method,
1539 'xmlrpcpath' => $xmlrpcpath,
1540 'plugintype' => $type,
1541 'pluginname' => $plugin,
1544 $rpcid = $remoterpc->id = $DB->insert_record('mnet_remote_rpc', $remoterpc, true);
1546 if (!$DB->record_exists('mnet_remote_service2rpc', array('rpcid'=>$rpcid, 'serviceid'=>$serviceobj->id))) {
1547 $obj = new stdClass();
1548 $obj->rpcid = $rpcid;
1549 $obj->serviceid = $serviceobj->id;
1550 $DB->insert_record('mnet_remote_service2rpc', $obj, true);
1552 $subscribemethodservices[$method][] = $service;
1556 foreach ($DB->get_records('mnet_remote_rpc', array('pluginname'=>$plugin, 'plugintype'=>$type), 'functionname ASC ') as $rpc) {
1557 if (!array_key_exists($rpc->functionname, $subscribemethodservices) && $rpc->enabled) {
1558 $DB->set_field('mnet_remote_rpc', 'enabled', 0, array('id' => $rpc->id));
1559 } else if (array_key_exists($rpc->functionname, $subscribemethodservices) && !$rpc->enabled) {
1560 $DB->set_field('mnet_remote_rpc', 'enabled', 1, array('id' => $rpc->id));
1568 * Given some sort of Zend Reflection function/method object, return a profile array, ready to be serialized and stored
1570 * @param Zend_Server_Reflection_Function_Abstract $function can be any subclass of this object type
1574 function admin_mnet_method_profile(Zend_Server_Reflection_Function_Abstract $function) {
1575 $proto = array_pop($function->getPrototypes());
1576 $ret = $proto->getReturnValue();
1578 'parameters' => array(),
1580 'type' => $ret->getType(),
1581 'description' => $ret->getDescription(),
1584 foreach ($proto->getParameters() as $p) {
1585 $profile['parameters'][] = array(
1586 'name' => $p->getName(),
1587 'type' => $p->getType(),
1588 'description' => $p->getDescription(),