示例#1
0
文件: plugins.php 项目: Burick/moodle
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(dirname(__FILE__)) . '/config.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->libdir . '/pluginlib.php';
admin_externalpage_setup('pluginsoverview');
require_capability('moodle/site:config', context_system::instance());
$fetchremote = optional_param('fetchremote', false, PARAM_BOOL);
$updatesonly = optional_param('updatesonly', false, PARAM_BOOL);
$contribonly = optional_param('contribonly', false, PARAM_BOOL);
$pluginman = plugin_manager::instance();
$checker = available_update_checker::instance();
// Filtering options.
$options = array('updatesonly' => $updatesonly, 'contribonly' => $contribonly);
if ($fetchremote) {
    require_sesskey();
    $checker->fetch();
    redirect(new moodle_url($PAGE->url, $options));
}
$output = $PAGE->get_renderer('core', 'admin');
$deployer = available_update_deployer::instance();
if ($deployer->enabled()) {
    $myurl = new moodle_url($PAGE->url, array('updatesonly' => $updatesonly, 'contribonly' => $contribonly));
    $deployer->initialize($myurl, $myurl);
    $deploydata = $deployer->submitted_data();
    if (!empty($deploydata)) {
        echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata);
        die;
    }
}
echo $output->plugin_management_page($pluginman, $checker, $options);
示例#2
0
文件: util.php 项目: Burick/moodle
 /**
  * Reset contents of all database tables to initial values, reset caches, etc.
  *
  * Note: this is relatively slow (cca 2 seconds for pg and 7 for mysql) - please use with care!
  *
  * @static
  * @param bool $logchanges log changes in global state and database in error log
  * @return void
  */
 public static function reset_all_data($logchanges = false)
 {
     global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION;
     // Stop any message redirection.
     phpunit_util::stop_message_redirection();
     // Release memory and indirectly call destroy() methods to release resource handles, etc.
     gc_collect_cycles();
     // Show any unhandled debugging messages, the runbare() could already reset it.
     self::display_debugging_messages();
     self::reset_debugging();
     // reset global $DB in case somebody mocked it
     $DB = self::get_global_backup('DB');
     if ($DB->is_transaction_started()) {
         // we can not reset inside transaction
         $DB->force_transaction_rollback();
     }
     $resetdb = self::reset_database();
     $warnings = array();
     if ($logchanges) {
         if ($resetdb) {
             $warnings[] = 'Warning: unexpected database modification, resetting DB state';
         }
         $oldcfg = self::get_global_backup('CFG');
         $oldsite = self::get_global_backup('SITE');
         foreach ($CFG as $k => $v) {
             if (!property_exists($oldcfg, $k)) {
                 $warnings[] = 'Warning: unexpected new $CFG->' . $k . ' value';
             } else {
                 if ($oldcfg->{$k} !== $CFG->{$k}) {
                     $warnings[] = 'Warning: unexpected change of $CFG->' . $k . ' value';
                 }
             }
             unset($oldcfg->{$k});
         }
         if ($oldcfg) {
             foreach ($oldcfg as $k => $v) {
                 $warnings[] = 'Warning: unexpected removal of $CFG->' . $k;
             }
         }
         if ($USER->id != 0) {
             $warnings[] = 'Warning: unexpected change of $USER';
         }
         if ($COURSE->id != $oldsite->id) {
             $warnings[] = 'Warning: unexpected change of $COURSE';
         }
     }
     // restore original globals
     $_SERVER = self::get_global_backup('_SERVER');
     $CFG = self::get_global_backup('CFG');
     $SITE = self::get_global_backup('SITE');
     $COURSE = $SITE;
     // reinitialise following globals
     $OUTPUT = new bootstrap_renderer();
     $PAGE = new moodle_page();
     $FULLME = null;
     $ME = null;
     $SCRIPT = null;
     $SESSION = new stdClass();
     $_SESSION['SESSION'] =& $SESSION;
     // set fresh new not-logged-in user
     $user = new stdClass();
     $user->id = 0;
     $user->mnethostid = $CFG->mnet_localhost_id;
     session_set_user($user);
     // reset all static caches
     accesslib_clear_all_caches(true);
     get_string_manager()->reset_caches(true);
     reset_text_filters_cache(true);
     events_get_handlers('reset');
     textlib::reset_caches();
     if (class_exists('repository')) {
         repository::reset_caches();
     }
     filter_manager::reset_caches();
     //TODO MDL-25290: add more resets here and probably refactor them to new core function
     // Reset course and module caches.
     if (class_exists('format_base')) {
         // If file containing class is not loaded, there is no cache there anyway.
         format_base::reset_course_cache(0);
     }
     get_fast_modinfo(0, 0, true);
     // Reset other singletons.
     if (class_exists('plugin_manager')) {
         plugin_manager::reset_caches(true);
     }
     if (class_exists('available_update_checker')) {
         available_update_checker::reset_caches(true);
     }
     if (class_exists('available_update_deployer')) {
         available_update_deployer::reset_caches(true);
     }
     // purge dataroot directory
     self::reset_dataroot();
     // restore original config once more in case resetting of caches changed CFG
     $CFG = self::get_global_backup('CFG');
     // inform data generator
     self::get_data_generator()->reset();
     // fix PHP settings
     error_reporting($CFG->debug);
     // verify db writes just in case something goes wrong in reset
     if (self::$lastdbwrites != $DB->perf_get_writes()) {
         error_log('Unexpected DB writes in phpunit_util::reset_all_data()');
         self::$lastdbwrites = $DB->perf_get_writes();
     }
     if ($warnings) {
         $warnings = implode("\n", $warnings);
         trigger_error($warnings, E_USER_WARNING);
     }
 }
示例#3
0
 /**
  * Reset caches used by this script
  *
  * @param bool $phpunitreset is this called as a part of PHPUnit reset?
  */
 public static function reset_caches($phpunitreset = false)
 {
     if ($phpunitreset) {
         self::$singletoninstance = null;
     }
 }
示例#4
0
 /**
  * Helper method to render the information about the available plugin update
  *
  * The passed objects always provides at least the 'version' property containing
  * the (higher) version of the plugin available.
  *
  * @param available_update_info $updateinfo information about the available update for the plugin
  */
 protected function plugin_available_update_info(available_update_info $updateinfo)
 {
     $boxclasses = 'pluginupdateinfo';
     $info = array();
     if (isset($updateinfo->release)) {
         $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_plugin', $updateinfo->release), array('class' => 'info release'));
     }
     if (isset($updateinfo->maturity)) {
         $info[] = html_writer::tag('span', get_string('maturity' . $updateinfo->maturity, 'core_admin'), array('class' => 'info maturity'));
         $boxclasses .= ' maturity' . $updateinfo->maturity;
     }
     if (isset($updateinfo->download)) {
         $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
     }
     if (isset($updateinfo->url)) {
         $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'), array('class' => 'info more'));
     }
     $box = $this->output->box_start($boxclasses);
     $box .= html_writer::tag('div', get_string('updateavailable', 'core_plugin', $updateinfo->version), array('class' => 'version'));
     $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
     $deployer = available_update_deployer::instance();
     if ($deployer->initialized()) {
         $impediments = $deployer->deployment_impediments($updateinfo);
         if (empty($impediments)) {
             $widget = $deployer->make_confirm_widget($updateinfo);
             $box .= $this->output->render($widget);
         } else {
             if (isset($impediments['notwritable'])) {
                 $box .= $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
             }
             if (isset($impediments['notdownloadable'])) {
                 $box .= $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
             }
         }
     }
     $box .= $this->output->box_end();
     return $box;
 }