public function execute() { global $CFG; require_once $CFG->libdir . '/adminlib.php'; // various admin-only functions require_once $CFG->libdir . '/upgradelib.php'; // general upgrade/install related functions require_once $CFG->libdir . '/environmentlib.php'; require_once $CFG->libdir . '/pluginlib.php'; require_once $CFG->dirroot . '/course/lib.php'; //some variables you may want to use //$this->cwd - the directory where moosh command was executed //$this->mooshDir - moosh installation directory //$this->expandedOptions - commandline provided options, merged with defaults //$this->topDir - top Moodle directory //$this->arguments[0] - first argument passed //$options = $this->expandedOptions; $split = explode('_', $this->arguments[0], 2); uninstall_plugin($split[0], $split[1]); upgrade_noncore(true); /* if verbose mode was requested, show some more information/debug messages if($this->verbose) { echo "Say what you're doing now"; } */ }
/** * Uninstall a plugin * * @param array $args */ function uninstall($args) { list($file, $name) = $this->parse_name($args, __FUNCTION__); if (is_plugin_active($file)) { WP_CLI::error('The plugin is active.'); } uninstall_plugin($file); }
/** * Automatically clean-up all plugin data and remove the plugin DB tables * * @param string $type The plugin type, eg. 'mod', 'qtype', 'workshopgrading' etc. * @param string $name The plugin name, eg. 'forum', 'multichoice', 'accumulative' etc. * @uses global $OUTPUT to produce notices and other messages * @return void */ function uninstall_plugin($type, $name) { global $CFG, $DB, $OUTPUT; // recursively uninstall all module subplugins first if ($type === 'mod') { if (file_exists("{$CFG->dirroot}/mod/{$name}/db/subplugins.php")) { $subplugins = array(); include "{$CFG->dirroot}/mod/{$name}/db/subplugins.php"; foreach ($subplugins as $subplugintype => $dir) { $instances = get_plugin_list($subplugintype); foreach ($instances as $subpluginname => $notusedpluginpath) { uninstall_plugin($subplugintype, $subpluginname); } } } } $component = $type . '_' . $name; // eg. 'qtype_multichoice' or 'workshopgrading_accumulative' or 'mod_forum' if ($type === 'mod') { $pluginname = $name; // eg. 'forum' if (get_string_manager()->string_exists('modulename', $component)) { $strpluginname = get_string('modulename', $component); } else { $strpluginname = $component; } } else { $pluginname = $component; if (get_string_manager()->string_exists('pluginname', $component)) { $strpluginname = get_string('pluginname', $component); } else { $strpluginname = $component; } } echo $OUTPUT->heading($pluginname); $plugindirectory = get_plugin_directory($type, $name); $uninstalllib = $plugindirectory . '/db/uninstall.php'; if (file_exists($uninstalllib)) { require_once $uninstalllib; $uninstallfunction = 'xmldb_' . $pluginname . '_uninstall'; // eg. 'xmldb_workshop_uninstall()' if (function_exists($uninstallfunction)) { if (!$uninstallfunction()) { echo $OUTPUT->notification('Encountered a problem running uninstall function for ' . $pluginname); } } } if ($type === 'mod') { // perform cleanup tasks specific for activity modules if (!($module = $DB->get_record('modules', array('name' => $name)))) { print_error('moduledoesnotexist', 'error'); } // delete all the relevant instances from all course sections if ($coursemods = $DB->get_records('course_modules', array('module' => $module->id))) { foreach ($coursemods as $coursemod) { if (!delete_mod_from_section($coursemod->id, $coursemod->section)) { echo $OUTPUT->notification("Could not delete the {$strpluginname} with id = {$coursemod->id} from section {$coursemod->section}"); } } } // clear course.modinfo for courses that used this module $sql = "UPDATE {course}\n SET modinfo=''\n WHERE id IN (SELECT DISTINCT course\n FROM {course_modules}\n WHERE module=?)"; $DB->execute($sql, array($module->id)); // delete all the course module records $DB->delete_records('course_modules', array('module' => $module->id)); // delete module contexts if ($coursemods) { foreach ($coursemods as $coursemod) { if (!delete_context(CONTEXT_MODULE, $coursemod->id)) { echo $OUTPUT->notification("Could not delete the context for {$strpluginname} with id = {$coursemod->id}"); } } } // delete the module entry itself $DB->delete_records('modules', array('name' => $module->name)); // cleanup the gradebook require_once $CFG->libdir . '/gradelib.php'; grade_uninstalled_module($module->name); // Perform any custom uninstall tasks if (file_exists($CFG->dirroot . '/mod/' . $module->name . '/lib.php')) { require_once $CFG->dirroot . '/mod/' . $module->name . '/lib.php'; $uninstallfunction = $module->name . '_uninstall'; if (function_exists($uninstallfunction)) { debugging("{$uninstallfunction}() has been deprecated. Use the plugin's db/uninstall.php instead", DEBUG_DEVELOPER); if (!$uninstallfunction()) { echo $OUTPUT->notification('Encountered a problem running uninstall function for ' . $module->name . '!'); } } } } else { if ($type === 'enrol') { // NOTE: this is a bit brute force way - it will not trigger events and hooks properly // nuke all role assignments role_unassign_all(array('component' => $component)); // purge participants $DB->delete_records_select('user_enrolments', "enrolid IN (SELECT id FROM {enrol} WHERE enrol = ?)", array($name)); // purge enrol instances $DB->delete_records('enrol', array('enrol' => $name)); // tweak enrol settings if (!empty($CFG->enrol_plugins_enabled)) { $enabledenrols = explode(',', $CFG->enrol_plugins_enabled); $enabledenrols = array_unique($enabledenrols); $enabledenrols = array_flip($enabledenrols); unset($enabledenrols[$name]); $enabledenrols = array_flip($enabledenrols); if (is_array($enabledenrols)) { set_config('enrol_plugins_enabled', implode(',', $enabledenrols)); } } } else { if ($type === 'block') { if ($block = $DB->get_record('block', array('name' => $name))) { // Inform block it's about to be deleted if (file_exists("{$CFG->dirroot}/blocks/{$block->name}/block_{$block->name}.php")) { $blockobject = block_instance($block->name); if ($blockobject) { $blockobject->before_delete(); //only if we can create instance, block might have been already removed } } // First delete instances and related contexts $instances = $DB->get_records('block_instances', array('blockname' => $block->name)); foreach ($instances as $instance) { blocks_delete_instance($instance); } // Delete block $DB->delete_records('block', array('id' => $block->id)); } } } } // perform clean-up task common for all the plugin/subplugin types // delete calendar events $DB->delete_records('event', array('modulename' => $pluginname)); // delete all the logs $DB->delete_records('log', array('module' => $pluginname)); // delete log_display information $DB->delete_records('log_display', array('component' => $component)); // delete the module configuration records unset_all_config_for_plugin($pluginname); // delete message provider message_provider_uninstall($component); // delete message processor if ($type === 'message') { message_processor_uninstall($name); } // delete the plugin tables $xmldbfilepath = $plugindirectory . '/db/install.xml'; drop_plugin_tables($component, $xmldbfilepath, false); if ($type === 'mod' or $type === 'block') { // non-frankenstyle table prefixes drop_plugin_tables($name, $xmldbfilepath, false); } // delete the capabilities that were defined by this module capabilities_cleanup($component); // remove event handlers and dequeue pending events events_uninstall($component); echo $OUTPUT->notification(get_string('success'), 'notifysuccess'); }
echo $OUTPUT->header(); echo $OUTPUT->heading($strmanageblocks); if (!($block = blocks_get_record($delete))) { print_error('blockdoesnotexist', 'error'); } if (get_string_manager()->string_exists('pluginname', "block_{$block->name}")) { $strblockname = get_string('pluginname', "block_{$block->name}"); } else { $strblockname = $block->name; } if (!$confirm) { echo $OUTPUT->confirm(get_string('blockdeleteconfirm', '', $strblockname), 'blocks.php?delete=' . $block->id . '&confirm=1', 'blocks.php'); echo $OUTPUT->footer(); exit; } else { uninstall_plugin('block', $block->name); $a = new stdClass(); $a->block = $strblockname; $a->directory = $CFG->dirroot . '/blocks/' . $block->name; notice(get_string('blockdeletefiles', '', $a), 'blocks.php'); } } echo $OUTPUT->header(); echo $OUTPUT->heading($strmanageblocks); /// Main display starts here /// Get and sort the existing blocks if (!($blocks = $DB->get_records('block', array(), 'name ASC'))) { print_error('noblocks', 'error'); // Should never happen } $incompatible = array();
break; case 'install': $plugin_name = trim(gpc('plugin_name', 'G', '')); if ($plugin_name) { include_once PD_PLUGINS_DIR . "{$plugin_name}/install.inc.php"; install_plugin(); write_file(PD_PLUGINS_DIR . "{$plugin_name}/install.lock", "PHPDISK {$plugin_name} plugin installed!"); } $sysmsg[] = __('plugin_install_success'); redirect($_SERVER['HTTP_REFERER'], $sysmsg); break; case 'uninstall': $plugin_name = trim(gpc('plugin_name', 'G', '')); if ($plugin_name) { include_once PD_PLUGINS_DIR . "{$plugin_name}/install.inc.php"; uninstall_plugin(); @unlink(PD_PLUGINS_DIR . "{$plugin_name}/install.lock"); $ins = array('plugin_name' => $plugin_name, 'active' => 0); $sqls = "('{$ins[plugin_name]}','{$ins[active]}')"; $db->query("replace into {$tpf}plugins(plugin_name,actived) values {$sqls} ;"); } $sysmsg[] = __('plugin_uninstall_success'); redirect($_SERVER['HTTP_REFERER'], $sysmsg); break; case 'actived_plugins': $sql_do = " where actived=1"; $perpage = 10; $rs = $db->fetch_one_array("select count(*) as total_num from {$tpf}plugins {$sql_do}"); $total_num = $rs['total_num']; $start_num = ($pg - 1) * $perpage; $q = $db->query("select * from {$tpf}plugins {$sql_do} order by plugin_name asc limit {$start_num},{$perpage}");
/** * Remove directory and files of a plugin for a list of plugins. * * @since 2.6.0 * * @global WP_Filesystem_Base $wp_filesystem * * @param array $plugins List of plugins to delete. * @param string $deprecated Deprecated. * @return bool|null|WP_Error True on success, false is $plugins is empty, WP_Error on failure. * Null if filesystem credentials are required to proceed. */ function delete_plugins( $plugins, $deprecated = '' ) { global $wp_filesystem; if ( empty($plugins) ) return false; $checked = array(); foreach( $plugins as $plugin ) $checked[] = 'checked[]=' . $plugin; ob_start(); $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins'); if ( false === ($credentials = request_filesystem_credentials($url)) ) { $data = ob_get_contents(); ob_end_clean(); if ( ! empty($data) ){ include_once( ABSPATH . 'wp-admin/admin-header.php'); echo $data; include( ABSPATH . 'wp-admin/admin-footer.php'); exit; } return; } if ( ! WP_Filesystem($credentials) ) { request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again $data = ob_get_contents(); ob_end_clean(); if ( ! empty($data) ){ include_once( ABSPATH . 'wp-admin/admin-header.php'); echo $data; include( ABSPATH . 'wp-admin/admin-footer.php'); exit; } return; } if ( ! is_object($wp_filesystem) ) return new WP_Error('fs_unavailable', __('Could not access filesystem.')); if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors); // Get the base plugin folder. $plugins_dir = $wp_filesystem->wp_plugins_dir(); if ( empty( $plugins_dir ) ) { return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress Plugin directory.' ) ); } $plugins_dir = trailingslashit( $plugins_dir ); $plugin_translations = wp_get_installed_translations( 'plugins' ); $errors = array(); foreach( $plugins as $plugin_file ) { // Run Uninstall hook. if ( is_uninstallable_plugin( $plugin_file ) ) { uninstall_plugin($plugin_file); } $this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin_file ) ); // If plugin is in its own directory, recursively delete the directory. if ( strpos( $plugin_file, '/' ) && $this_plugin_dir != $plugins_dir ) { //base check on if plugin includes directory separator AND that it's not the root plugin folder $deleted = $wp_filesystem->delete( $this_plugin_dir, true ); } else { $deleted = $wp_filesystem->delete( $plugins_dir . $plugin_file ); } if ( ! $deleted ) { $errors[] = $plugin_file; continue; } // Remove language files, silently. $plugin_slug = dirname( $plugin_file ); if ( '.' !== $plugin_slug && ! empty( $plugin_translations[ $plugin_slug ] ) ) { $translations = $plugin_translations[ $plugin_slug ]; foreach ( $translations as $translation => $data ) { $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.po' ); $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.mo' ); } } } // Remove deleted plugins from the plugin updates list. if ( $current = get_site_transient('update_plugins') ) { // Don't remove the plugins that weren't deleted. $deleted = array_diff( $plugins, $errors ); foreach ( $deleted as $plugin_file ) { unset( $current->response[ $plugin_file ] ); } set_site_transient( 'update_plugins', $current ); } if ( ! empty($errors) ) return new WP_Error('could_not_remove_plugin', sprintf(__('Could not fully remove the plugin(s) %s.'), implode(', ', $errors)) ); return true; }
/** * Uninstall a plugin. * * ## OPTIONS * * <plugin>... * : One or more plugins to uninstall. * * [--deactivate] * : Deactivate the plugin before uninstalling. Default behavior is to warn and skip if the plugin is active. * * [--skip-delete] * : If set, the plugin files will not be deleted. Only the uninstall procedure * will be run. * * ## EXAMPLES * * wp plugin uninstall hello */ function uninstall($args, $assoc_args = array()) { foreach ($this->fetcher->get_many($args) as $plugin) { if (is_plugin_active($plugin->file) && !WP_CLI\Utils\get_flag_value($assoc_args, 'deactivate')) { WP_CLI::warning("The '{$plugin->name}' plugin is active."); continue; } if (\WP_CLI\Utils\get_flag_value($assoc_args, 'deactivate')) { WP_CLI::log("Deactivating '{$plugin->name}'..."); $this->deactivate(array($plugin->name)); } uninstall_plugin($plugin->file); if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'skip-delete') && $this->_delete($plugin)) { WP_CLI::success("Uninstalled and deleted '{$plugin->name}' plugin."); } else { WP_CLI::success("Ran uninstall procedure for '{$plugin->name}' plugin without deleting."); } } }
/** * Plugins admin page * * @param App $a * @return string */ function admin_page_plugins(&$a) { /* * Single plugin */ if (\App::$argc == 3) { $plugin = \App::$argv[2]; if (!is_file("addon/{$plugin}/{$plugin}.php")) { notice(t("Item not found.")); return ''; } $enabled = in_array($plugin, \App::$plugins); $info = get_plugin_info($plugin); $x = check_plugin_versions($info); // disable plugins which are installed but incompatible versions if ($enabled && !$x) { $enabled = false; $idz = array_search($plugin, \App::$plugins); if ($idz !== false) { unset(\App::$plugins[$idz]); uninstall_plugin($plugin); set_config("system", "addon", implode(", ", \App::$plugins)); } } $info['disabled'] = 1 - intval($x); if (x($_GET, "a") && $_GET['a'] == "t") { check_form_security_token_redirectOnErr('/admin/plugins', 'admin_plugins', 't'); // Toggle plugin status $idx = array_search($plugin, \App::$plugins); if ($idx !== false) { unset(\App::$plugins[$idx]); uninstall_plugin($plugin); info(sprintf(t("Plugin %s disabled."), $plugin)); } else { \App::$plugins[] = $plugin; install_plugin($plugin); info(sprintf(t("Plugin %s enabled."), $plugin)); } set_config("system", "addon", implode(", ", \App::$plugins)); goaway(z_root() . '/admin/plugins'); } // display plugin details require_once 'library/markdown.php'; if (in_array($plugin, \App::$plugins)) { $status = 'on'; $action = t('Disable'); } else { $status = 'off'; $action = t('Enable'); } $readme = null; if (is_file("addon/{$plugin}/README.md")) { $readme = file_get_contents("addon/{$plugin}/README.md"); $readme = Markdown($readme); } else { if (is_file("addon/{$plugin}/README")) { $readme = "<pre>" . file_get_contents("addon/{$plugin}/README") . "</pre>"; } } $admin_form = ''; $r = q("select * from addon where plugin_admin = 1 and name = '%s' limit 1", dbesc($plugin)); if ($r) { @(require_once "addon/{$plugin}/{$plugin}.php"); if (function_exists($plugin . '_plugin_admin')) { $func = $plugin . '_plugin_admin'; $func($a, $admin_form); } } $t = get_markup_template('admin_plugins_details.tpl'); return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Plugins'), '$toggle' => t('Toggle'), '$settings' => t('Settings'), '$baseurl' => z_root(), '$plugin' => $plugin, '$status' => $status, '$action' => $action, '$info' => $info, '$str_author' => t('Author: '), '$str_maintainer' => t('Maintainer: '), '$str_minversion' => t('Minimum project version: '), '$str_maxversion' => t('Maximum project version: '), '$str_minphpversion' => t('Minimum PHP version: '), '$str_requires' => t('Requires: '), '$disabled' => t('Disabled - version incompatibility'), '$admin_form' => $admin_form, '$function' => 'plugins', '$screenshot' => '', '$readme' => $readme, '$form_security_token' => get_form_security_token('admin_plugins'))); } /* * List plugins */ $plugins = array(); $files = glob('addon/*/'); if ($files) { foreach ($files as $file) { if (is_dir($file)) { list($tmp, $id) = array_map('trim', explode('/', $file)); $info = get_plugin_info($id); $enabled = in_array($id, \App::$plugins); $x = check_plugin_versions($info); // disable plugins which are installed but incompatible versions if ($enabled && !$x) { $enabled = false; $idz = array_search($id, \App::$plugins); if ($idz !== false) { unset(\App::$plugins[$idz]); uninstall_plugin($id); set_config("system", "addon", implode(", ", \App::$plugins)); } } $info['disabled'] = 1 - intval($x); $plugins[] = array($id, $enabled ? "on" : "off", $info); } } } usort($plugins, 'self::plugin_sort'); $admin_plugins_add_repo_form = replace_macros(get_markup_template('admin_plugins_addrepo.tpl'), array('$post' => 'admin/plugins/addrepo', '$desc' => t('Enter the public git repository URL of the plugin repo.'), '$repoURL' => array('repoURL', t('Plugin repo git URL'), '', ''), '$repoName' => array('repoName', t('Custom repo name'), '', '', t('(optional)')), '$submit' => t('Download Plugin Repo'))); $newRepoModalID = random_string(3); $newRepoModal = replace_macros(get_markup_template('generic_modal.tpl'), array('$id' => $newRepoModalID, '$title' => t('Install new repo'), '$ok' => t('Install'), '$cancel' => t('Cancel'))); $reponames = $this->listAddonRepos(); $addonrepos = []; foreach ($reponames as $repo) { $addonrepos[] = array('name' => $repo, 'description' => ''); // TODO: Parse repo info to provide more information about repos } $t = get_markup_template('admin_plugins.tpl'); return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Plugins'), '$submit' => t('Submit'), '$baseurl' => z_root(), '$function' => 'plugins', '$plugins' => $plugins, '$disabled' => t('Disabled - version incompatibility'), '$form_security_token' => get_form_security_token('admin_plugins'), '$addrepo' => t('Add Plugin Repo'), '$expandform' => false, '$form' => $admin_plugins_add_repo_form, '$newRepoModal' => $newRepoModal, '$newRepoModalID' => $newRepoModalID, '$addonrepos' => $addonrepos, '$repoUpdateButton' => t('Update'), '$repoBranchButton' => t('Switch branch'), '$repoRemoveButton' => t('Remove'))); }
/** * Run the plugin's uninstall script. * * Call it and then run your uninstall assertions. You should always test * installation before testing uninstallation. * * @since 0.1.0 */ public function uninstall() { global $wpdb; if (!$this->simulated_usage) { $wpdb->query('ROLLBACK'); // If the plugin has a usage simulation file, run it remotely. $this->simulate_usage(); } // We're going to do real table dropping, not temporary tables. $drop_temp_tables = array($this, '_drop_temporary_table'); // Back compat. See https://core.trac.wordpress.org/ticket/24800. if (method_exists($this, '_drop_temporary_tables')) { $drop_temp_tables = array($this, '_drop_temporary_tables'); } remove_filter('query', $drop_temp_tables); if (empty($this->plugin_file)) { $this->fail('Error: $plugin_file property not set.'); } uninstall_plugin($this->plugin_file); $this->flush_cache(); }
} $enabled = array_flip($enabled); $enabled[$current] = $enabled[$current + 1]; $enabled[$current + 1] = $enrol; set_config('enrol_plugins_enabled', implode(',', $enabled)); break; case 'uninstall': echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('enrolments', 'enrol')); if (get_string_manager()->string_exists('pluginname', 'enrol_' . $enrol)) { $strplugin = get_string('pluginname', 'enrol_' . $enrol); } else { $strplugin = $enrol; } if (!$confirm) { $uurl = new moodle_url('/admin/enrol.php', array('action' => 'uninstall', 'enrol' => $enrol, 'sesskey' => sesskey(), 'confirm' => 1)); echo $OUTPUT->confirm(get_string('uninstallconfirm', 'enrol', $strplugin), $uurl, $return); echo $OUTPUT->footer(); exit; } else { // Delete everything!! uninstall_plugin('enrol', $enrol); $a->plugin = $strplugin; $a->directory = "{$CFG->dirroot}/enrol/{$enrol}"; echo $OUTPUT->notification(get_string('uninstalldeletefiles', 'enrol', $a), 'notifysuccess'); echo $OUTPUT->continue_button($return); echo $OUTPUT->footer(); exit; } } redirect($return);
$confirm = optional_param('confirm', false, PARAM_BOOL); if (!empty($delete) and confirm_sesskey()) { // If data submitted, then process and store. echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('manageplagiarism', 'plagiarism')); if (!$confirm) { if (get_string_manager()->string_exists('pluginname', 'plagiarism_' . $delete)) { $strpluginname = get_string('pluginname', 'plagiarism_' . $delete); } else { $strpluginname = $delete; } echo $OUTPUT->confirm(get_string('plagiarismplugindeleteconfirm', 'plagiarism', $strpluginname), new moodle_url($PAGE->url, array('delete' => $delete, 'confirm' => 1)), $PAGE->url); echo $OUTPUT->footer(); die; } else { uninstall_plugin('plagiarism', $delete); $a = new stdclass(); $a->name = $delete; $pluginlocation = get_plugin_types(); $a->directory = $pluginlocation['plagiarism'] . '/' . $delete; echo $OUTPUT->notification(get_string('plugindeletefiles', '', $a), 'notifysuccess'); echo $OUTPUT->continue_button($PAGE->url); echo $OUTPUT->footer(); die; } } echo $OUTPUT->header(); // Print the table of all installed plagiarism plugins. $txt = get_strings(array('settings', 'name', 'version', 'delete')); $plagiarismplugins = get_plugin_list('plagiarism'); if (empty($plagiarismplugins)) {
/** * Uninstall a plugin. * * ## OPTIONS * * <plugin>... * : One or more plugins to uninstall. * * [--skip-delete] * : If set, the plugin files will not be deleted. Only the uninstall procedure * will be run. * * ## EXAMPLES * * wp plugin uninstall hello */ function uninstall($args, $assoc_args = array()) { foreach ($this->fetcher->get_many($args) as $plugin) { if (is_plugin_active($plugin->file)) { WP_CLI::warning("The '{$plugin->name}' plugin is active."); continue; } uninstall_plugin($plugin->file); if (!isset($assoc_args['skip-delete']) && $this->_delete($plugin)) { WP_CLI::success("Uninstalled and deleted '{$plugin->name}' plugin."); } else { WP_CLI::success("Ran uninstall procedure for '{$plugin->name}' plugin without deleting."); } } }
$confirm = optional_param('confirm', '', PARAM_BOOL); /// If data submitted, then process and store. if (!empty($delete) and confirm_sesskey()) { echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('tools', 'admin')); if (!$confirm) { if (get_string_manager()->string_exists('pluginname', 'tool_' . $delete)) { $strpluginname = get_string('pluginname', 'tool_' . $delete); } else { $strpluginname = $delete; } echo $OUTPUT->confirm(get_string('toolsdeleteconfirm', 'admin', $strpluginname), new moodle_url($PAGE->url, array('delete' => $delete, 'confirm' => 1)), $PAGE->url); echo $OUTPUT->footer(); die; } else { uninstall_plugin('tool', $delete); $a = new stdclass(); $a->name = $delete; $pluginlocation = get_plugin_types(); $a->directory = $pluginlocation['tool'] . '/' . $delete; echo $OUTPUT->notification(get_string('plugindeletefiles', '', $a), 'notifysuccess'); echo $OUTPUT->continue_button($PAGE->url); echo $OUTPUT->footer(); die; } } echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('tools', 'admin')); /// Print the table of all installed tool plugins $table = new flexible_table('toolplugins_administration_table'); $table->define_columns(array('name', 'version', 'delete'));
/** * Uninstall a plugin. * * @synopsis <plugin> [--no-delete] */ function uninstall($args, $assoc_args = array()) { list($file, $name) = $this->parse_name($args); if (is_plugin_active($file)) { WP_CLI::error('The plugin is active.'); } uninstall_plugin($file); if (!isset($assoc_args['no-delete'])) { $this->delete($args); } }
/** * Plugins admin page * * @param App $a * @return string */ function admin_page_plugins(&$a) { /* * Single plugin */ if ($a->argc == 3) { $plugin = $a->argv[2]; if (!is_file("addon/{$plugin}/{$plugin}.php")) { notice(t("Item not found.")); return ''; } if (x($_GET, "a") && $_GET['a'] == "t") { check_form_security_token_redirectOnErr('/admin/plugins', 'admin_plugins', 't'); // Toggle plugin status $idx = array_search($plugin, $a->plugins); if ($idx !== false) { unset($a->plugins[$idx]); uninstall_plugin($plugin); info(sprintf(t("Plugin %s disabled."), $plugin)); } else { $a->plugins[] = $plugin; install_plugin($plugin); info(sprintf(t("Plugin %s enabled."), $plugin)); } set_config("system", "addon", implode(", ", $a->plugins)); goaway($a->get_baseurl(true) . '/admin/plugins'); } // display plugin details require_once 'library/markdown.php'; if (in_array($plugin, $a->plugins)) { $status = 'on'; $action = t('Disable'); } else { $status = 'off'; $action = t('Enable'); } $readme = null; if (is_file("addon/{$plugin}/README.md")) { $readme = file_get_contents("addon/{$plugin}/README.md"); $readme = Markdown($readme); } else { if (is_file("addon/{$plugin}/README")) { $readme = "<pre>" . file_get_contents("addon/{$plugin}/README") . "</pre>"; } } $admin_form = ''; if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)) { @(require_once "addon/{$plugin}/{$plugin}.php"); if (function_exists($plugin . '_plugin_admin')) { $func = $plugin . '_plugin_admin'; $func($a, $admin_form); } } $t = get_markup_template('admin_plugins_details.tpl'); return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Plugins'), '$toggle' => t('Toggle'), '$settings' => t('Settings'), '$baseurl' => $a->get_baseurl(true), '$plugin' => $plugin, '$status' => $status, '$action' => $action, '$info' => get_plugin_info($plugin), '$str_author' => t('Author: '), '$str_maintainer' => t('Maintainer: '), '$admin_form' => $admin_form, '$function' => 'plugins', '$screenshot' => '', '$readme' => $readme, '$form_security_token' => get_form_security_token('admin_plugins'))); } /* * List plugins */ $plugins = array(); $files = glob('addon/*/'); if ($files) { foreach ($files as $file) { if (is_dir($file)) { list($tmp, $id) = array_map('trim', explode('/', $file)); $info = get_plugin_info($id); $plugins[] = array($id, in_array($id, $a->plugins) ? "on" : "off", $info); } } } $t = get_markup_template('admin_plugins.tpl'); return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Plugins'), '$submit' => t('Submit'), '$baseurl' => $a->get_baseurl(true), '$function' => 'plugins', '$plugins' => $plugins, '$form_security_token' => get_form_security_token('admin_plugins'))); }
function admin_page_plugins(&$a) { /** * Single plugin */ if ($a->argc == 3) { $plugin = $a->argv[2]; if (!is_file("addon/{$plugin}/{$plugin}.php")) { notice(t("Item not found.")); return; } if (x($_GET, "a") && $_GET['a'] == "t") { // Toggle plugin status $idx = array_search($plugin, $a->plugins); if ($idx !== false) { unset($a->plugins[$idx]); uninstall_plugin($plugin); info(sprintf(t("Plugin %s disabled."), $plugin)); } else { $a->plugins[] = $plugin; install_plugin($plugin); info(sprintf(t("Plugin %s enabled."), $plugin)); } set_config("system", "addon", implode(", ", $a->plugins)); goaway($a->get_baseurl() . '/admin/plugins'); return; // NOTREACHED } // display plugin details require_once 'library/markdown.php'; if (in_array($plugin, $a->plugins)) { $status = "on"; $action = t("Disable"); } else { $status = "off"; $action = t("Enable"); } $readme = Null; if (is_file("addon/{$plugin}/README.md")) { $readme = file_get_contents("addon/{$plugin}/README.md"); $readme = Markdown($readme); } else { if (is_file("addon/{$plugin}/README")) { $readme = "<pre>" . file_get_contents("addon/{$plugin}/README") . "</pre>"; } } $admin_form = ""; if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)) { @(require_once "addon/{$plugin}/{$plugin}.php"); $func = $plugin . '_plugin_admin'; $func($a, $admin_form); } $t = get_markup_template("admin_plugins_details.tpl"); return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Plugins'), '$toggle' => t('Toggle'), '$settings' => t('Settings'), '$baseurl' => $a->get_baseurl(), '$plugin' => $plugin, '$status' => $status, '$action' => $action, '$info' => get_plugin_info($plugin), '$admin_form' => $admin_form, '$readme' => $readme)); } /** * List plugins */ $plugins = array(); $files = glob("addon/*/"); if ($files) { foreach ($files as $file) { if (is_dir($file)) { list($tmp, $id) = array_map("trim", explode("/", $file)); $info = get_plugin_info($id); $plugins[] = array($id, in_array($id, $a->plugins) ? "on" : "off", $info); } } } $t = get_markup_template("admin_plugins.tpl"); return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Plugins'), '$submit' => t('Submit'), '$baseurl' => $a->get_baseurl(), '$plugins' => $plugins)); }
function check_plugins(&$a) { /** * * Synchronise plugins: * * $a->config['system']['addon'] contains a comma-separated list of names * of plugins/addons which are used on this system. * Go through the database list of already installed addons, and if we have * an entry, but it isn't in the config list, call the uninstall procedure * and mark it uninstalled in the database (for now we'll remove it). * Then go through the config list and if we have a plugin that isn't installed, * call the install procedure and add it to the database. * */ $r = q("SELECT * FROM `addon` WHERE `installed` = 1"); if (count($r)) { $installed = $r; } else { $installed = array(); } $plugins = get_config('system', 'addon'); $plugins_arr = array(); if ($plugins) { $plugins_arr = explode(',', str_replace(' ', '', $plugins)); } $a->plugins = $plugins_arr; $installed_arr = array(); if (count($installed)) { foreach ($installed as $i) { if (!in_array($i['name'], $plugins_arr)) { uninstall_plugin($i['name']); } else { $installed_arr[] = $i['name']; } } } if (count($plugins_arr)) { foreach ($plugins_arr as $p) { if (!in_array($p, $installed_arr)) { install_plugin($p); } } } load_hooks(); return; }
} $PAGE->set_title($strplugin); echo $OUTPUT->header(); if (!$confirm) { echo $OUTPUT->heading(get_string('editors', 'core_editor')); $deleteurl = new moodle_url('/admin/editors.php', array('action' => 'uninstall', 'editor' => $editor, 'sesskey' => sesskey(), 'confirm' => 1)); echo $OUTPUT->confirm(get_string('editordeleteconfirm', 'core_editor', $strplugin), $deleteurl, $returnurl); echo $OUTPUT->footer(); die; } else { // Remove from enabled list. $key = array_search($editor, $active_editors); unset($active_editors[$key]); set_config('texteditors', implode(',', $active_editors)); // Delete everything!! uninstall_plugin('editor', $editor); $a = new stdClass(); $a->name = $strplugin; $a->directory = "{$CFG->dirroot}/lib/editor/{$editor}"; echo $OUTPUT->notification(get_string('plugindeletefiles', '', $a), 'notifysuccess'); echo $OUTPUT->continue_button($returnurl); echo $OUTPUT->footer(); die; } default: break; } // at least one editor must be active if (empty($active_editors)) { $active_editors = array('textarea'); }
function nodeinfo_cron() { $a = get_app(); // If the plugin "statistics_json" is enabled then disable it and actrivate nodeinfo. if (nodeinfo_plugin_enabled("statistics_json")) { set_config("system", "nodeinfo", true); $plugin = "statistics_json"; $plugins = get_config("system", "addon"); $plugins_arr = array(); if ($plugins) { $plugins_arr = explode(",", str_replace(" ", "", $plugins)); $idx = array_search($plugin, $plugins_arr); if ($idx !== false) { unset($plugins_arr[$idx]); uninstall_plugin($plugin); set_config("system", "addon", implode(", ", $plugins_arr)); } } } if (!get_config("system", "nodeinfo")) { return; } $last = get_config('nodeinfo', 'last_calucation'); if ($last) { // Calculate every 24 hours $next = $last + 24 * 60 * 60; if ($next > time()) { logger("calculation intervall not reached"); return; } } logger("cron_start"); $users = q("SELECT profile.*, `user`.`login_date`, `lastitem`.`lastitem_date`\n\t\t\tFROM (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`\n\t\t\t\tFROM `item`\n\t\t\t\t\tWHERE `item`.`type` = 'wall'\n\t\t\t\t\t\tGROUP BY `item`.`uid`) AS `lastitem`\n\t\t\t\t\t\tRIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`, `contact`, `profile`\n WHERE\n\t\t\t\t\t`user`.`uid` = `contact`.`uid` AND `profile`.`uid` = `user`.`uid`\n\t\t\t\t\tAND `profile`.`is-default` AND (`profile`.`publish` OR `profile`.`net-publish`)\n\t\t\t\t\tAND `user`.`verified` AND `contact`.`self`\n\t\t\t\t\tAND NOT `user`.`blocked`\n\t\t\t\t\tAND NOT `user`.`account_removed`\n\t\t\t\t\tAND NOT `user`.`account_expired`"); if (is_array($users)) { $total_users = count($users); $active_users_halfyear = 0; $active_users_monthly = 0; $halfyear = time() - 180 * 24 * 60 * 60; $month = time() - 30 * 24 * 60 * 60; foreach ($users as $user) { if (strtotime($user['login_date']) > $halfyear or strtotime($user['lastitem_date']) > $halfyear) { ++$active_users_halfyear; } if (strtotime($user['login_date']) > $month or strtotime($user['lastitem_date']) > $month) { ++$active_users_monthly; } } set_config('nodeinfo', 'total_users', $total_users); logger("total_users: " . $total_users, LOGGER_DEBUG); set_config('nodeinfo', 'active_users_halfyear', $active_users_halfyear); set_config('nodeinfo', 'active_users_monthly', $active_users_monthly); } //$posts = q("SELECT COUNT(*) AS local_posts FROM `item` WHERE `wall` AND `uid` != 0 AND `id` = `parent` AND left(body, 6) != '[share'"); $posts = q("SELECT COUNT(*) AS `local_posts` FROM `item`\n\t\t\tINNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\tWHERE `contact`.`self` and `item`.`id` = `item`.`parent` AND left(body, 6) != '[share' AND `item`.`network` IN ('%s', '%s', '%s')", dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN)); if (!is_array($posts)) { $local_posts = -1; } else { $local_posts = $posts[0]["local_posts"]; } set_config('nodeinfo', 'local_posts', $local_posts); logger("local_posts: " . $local_posts, LOGGER_DEBUG); $posts = q("SELECT COUNT(*) AS `local_comments` FROM `item`\n\t\t\tINNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\tWHERE `contact`.`self` and `item`.`id` != `item`.`parent` AND `item`.`network` IN ('%s', '%s', '%s')", dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN)); if (!is_array($posts)) { $local_comments = -1; } else { $local_comments = $posts[0]["local_comments"]; } set_config('nodeinfo', 'local_comments', $local_comments); // Now trying to register $url = "http://the-federation.info/register/" . $a->get_hostname(); logger('registering url: ' . $url, LOGGER_DEBUG); $ret = fetch_url($url); logger('registering answer: ' . $ret, LOGGER_DEBUG); logger("cron_end"); set_config('nodeinfo', 'last_calucation', time()); }
public static function commit_saisie(&$tab_new_values, $session) { $PHP_SELF = $_SERVER['PHP_SELF']; $return = ''; if ($session == "") { $URL = "{$PHP_SELF}"; } else { $URL = "{$PHP_SELF}?session={$session}"; } $timeout = 2; // temps d'attente pour rafraichir l'écran après l'update ! foreach ($tab_new_values as $key => $value) { // CONTROLE gestion_conges_exceptionnels // si désactivation les conges exceptionnels, on verif s'il y a des conges exceptionnels enregistres ! si oui : changement impossible ! if ($key == "gestion_conges_exceptionnels" && $value == "FALSE") { $sql_abs = "SELECT ta_id, ta_libelle FROM conges_type_absence WHERE ta_type='conges_exceptionnels' "; $ReqLog_abs = \includes\SQL::query($sql_abs); if ($ReqLog_abs->num_rows != 0) { $return .= '<b>' . _('config_abs_desactive_cong_excep_impossible') . '</b><br>'; $value = "TRUE"; $timeout = 5; } } // CONTROLE jour_mois_limite_reliquats // si modif de jour_mois_limite_reliquats, on verifie le format ( 0 ou jj-mm) , sinon : changement impossible ! if ($key == "jour_mois_limite_reliquats" && $value != "0") { $t = explode("-", $value); if (checkdate($t[1], $t[0], date("Y")) == FALSE) { $return .= '<b>' . _('config_jour_mois_limite_reliquats_modif_impossible') . '</b><br>'; $sql_date = "SELECT conf_valeur FROM conges_config WHERE conf_nom='jour_mois_limite_reliquats' "; $ReqLog_date = \includes\SQL::query($sql_date); $data = $ReqLog_date->fetch_row(); $value = $data[0]; $timeout = 5; } } if (preg_match("/_installed\$/", $key) && $value == "1") { $plugin = explode("_", $key); $plugin = $plugin[0]; install_plugin($plugin); } elseif (preg_match("/_installed\$/", $key) && $value == "0") { $plugin = explode("_", $key); $plugin = $plugin[0]; uninstall_plugin($plugin); } if (preg_match("/_activated\$/", $key) && $value == "1") { $plugin = explode("_", $key); $plugin = $plugin[0]; activate_plugin($plugin); } elseif (preg_match("/_activated\$/", $key) && $value == "0") { $plugin = explode("_", $key); $plugin = $plugin[0]; disable_plugin($plugin); } // Mise à jour $sql2 = 'UPDATE conges_config SET conf_valeur = \'' . addslashes($value) . '\' WHERE conf_nom ="' . \includes\SQL::quote($key) . '" '; $ReqLog2 = \includes\SQL::query($sql2); } $_SESSION['config'] = init_config_tab(); // on re-initialise le tableau des variables de config // enregistrement dans les logs $comment_log = "nouvelle configuration de php_conges "; log_action(0, "", "", $comment_log); $return .= '<span class="messages">' . _('form_modif_ok') . '</span><br>'; $return .= '<META HTTP-EQUIV=REFRESH CONTENT="' . $timeout . '; URL=' . $URL . '">'; return $return; }
/** * Plugins admin page * * @param App $a * @return string */ function admin_page_plugins(&$a) { /** * Single plugin */ if ($a->argc == 3) { $plugin = $a->argv[2]; if (!is_file("addon/{$plugin}/{$plugin}.php")) { notice(t("Item not found.")); return ''; } if (x($_GET, "a") && $_GET['a'] == "t") { check_form_security_token_redirectOnErr('/admin/plugins', 'admin_themes', 't'); // Toggle plugin status $idx = array_search($plugin, $a->plugins); if ($idx !== false) { unset($a->plugins[$idx]); uninstall_plugin($plugin); info(sprintf(t("Plugin %s disabled."), $plugin)); } else { $a->plugins[] = $plugin; install_plugin($plugin); info(sprintf(t("Plugin %s enabled."), $plugin)); } set_config("system", "addon", implode(", ", $a->plugins)); goaway($a->get_baseurl(true) . '/admin/plugins'); return ''; // NOTREACHED } // display plugin details require_once 'library/markdown.php'; if (in_array($plugin, $a->plugins)) { $status = "on"; $action = t("Disable"); } else { $status = "off"; $action = t("Enable"); } $readme = Null; if (is_file("addon/{$plugin}/README.md")) { $readme = file_get_contents("addon/{$plugin}/README.md"); $readme = Markdown($readme); } else { if (is_file("addon/{$plugin}/README")) { $readme = "<pre>" . file_get_contents("addon/{$plugin}/README") . "</pre>"; } } $admin_form = ""; if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)) { @(require_once "addon/{$plugin}/{$plugin}.php"); $func = $plugin . '_plugin_admin'; $func($a, $admin_form); } $t = get_markup_template("admin_plugins_details.tpl"); return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Plugins'), '$toggle' => t('Toggle'), '$settings' => t('Settings'), '$baseurl' => $a->get_baseurl(true), '$plugin' => $plugin, '$status' => $status, '$action' => $action, '$info' => get_plugin_info($plugin), '$str_author' => t('Author: '), '$str_maintainer' => t('Maintainer: '), '$admin_form' => $admin_form, '$function' => 'plugins', '$screenshot' => '', '$readme' => $readme, '$form_security_token' => get_form_security_token("admin_themes"))); } /** * List plugins */ $plugins = array(); $files = glob("addon/*/"); /* */ if ($files) { foreach ($files as $file) { if (is_dir($file)) { list($tmp, $id) = array_map("trim", explode("/", $file)); $info = get_plugin_info($id); $show_plugin = true; // If the addon is unsupported, then only show it, when it is enabled if (strtolower($info["status"]) == "unsupported" and !in_array($id, $a->plugins)) { $show_plugin = false; } // Override the above szenario, when the admin really wants to see outdated stuff if (get_config("system", "show_unsupported_addons")) { $show_plugin = true; } if ($show_plugin) { $plugins[] = array($id, in_array($id, $a->plugins) ? "on" : "off", $info); } } } } $t = get_markup_template("admin_plugins.tpl"); return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Plugins'), '$submit' => t('Save Settings'), '$baseurl' => $a->get_baseurl(true), '$function' => 'plugins', '$plugins' => $plugins, '$form_security_token' => get_form_security_token("admin_themes"))); }
exit; } } $format = $formatplugins[$formatname]; $deleteurl = $format->get_uninstall_url(); if (!$deleteurl) { // somebody was trying to cheat and type non-existing link echo $OUTPUT->error_text(get_string('cannotuninstall', 'admin', $format->displayname)); echo $OUTPUT->footer(); exit; } if (!$confirm) { if ($coursecount) { $message = get_string('formatuninstallwithcourses', 'admin', (object) array('count' => $coursecount, 'format' => $format->displayname, 'defaultformat' => $defaultformat->displayname)); } else { $message = get_string('formatuninstallconfirm', 'admin', $format->displayname); } $deleteurl->param('confirm', 1); echo $OUTPUT->confirm($message, $deleteurl, $return); } else { $a = new stdClass(); $a->plugin = $format->displayname; $a->directory = $format->rootdir; uninstall_plugin('format', $formatname); echo $OUTPUT->notification(get_string('formatuninstalled', 'admin', $a), 'notifysuccess'); echo $OUTPUT->continue_button($return); } echo $OUTPUT->footer(); exit; } redirect($return);
echo $OUTPUT->heading($stractivities); if (get_string_manager()->string_exists('modulename', $delete)) { $strmodulename = get_string('modulename', $delete); } else { $strmodulename = $delete; } if (!$confirm) { echo $OUTPUT->confirm(get_string("moduledeleteconfirm", "", $strmodulename), "modules.php?delete={$delete}&confirm=1", "modules.php"); echo $OUTPUT->footer(); exit; } else { // Delete everything!! if ($delete == "forum") { print_error("cannotdeleteforummodule", 'forum'); } uninstall_plugin('mod', $delete); $a->module = $strmodulename; $a->directory = "{$CFG->dirroot}/mod/{$delete}"; echo $OUTPUT->notification(get_string("moduledeletefiles", "", $a), 'notifysuccess'); echo $OUTPUT->continue_button("modules.php"); echo $OUTPUT->footer(); exit; } } echo $OUTPUT->header(); echo $OUTPUT->heading($stractivities); /// Get and sort the existing modules if (!($modules = $DB->get_records('modules', array(), 'name ASC'))) { print_error('moduledoesnotexist', 'error'); } /// Print the table of all modules
$confirm = optional_param('confirm', '', PARAM_BOOL); /// If data submitted, then process and store. if (!empty($delete) and confirm_sesskey()) { echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('localplugins')); if (!$confirm) { if (get_string_manager()->string_exists('pluginname', 'local_' . $delete)) { $strpluginname = get_string('pluginname', 'local_' . $delete); } else { $strpluginname = $delete; } echo $OUTPUT->confirm(get_string('localplugindeleteconfirm', '', $strpluginname), new moodle_url($PAGE->url, array('delete' => $delete, 'confirm' => 1)), $PAGE->url); echo $OUTPUT->footer(); die; } else { uninstall_plugin('local', $delete); $a = new stdclass(); $a->name = $delete; $pluginlocation = get_plugin_types(); $a->directory = $pluginlocation['local'] . '/' . $delete; echo $OUTPUT->notification(get_string('plugindeletefiles', '', $a), 'notifysuccess'); echo $OUTPUT->continue_button($PAGE->url); echo $OUTPUT->footer(); die; } } echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('localplugins')); /// Print the table of all installed local plugins $table = new flexible_table('localplugins_administration_table'); $table->define_columns(array('name', 'version', 'delete'));
/** * Uninstall the given plugin. * * Automatically cleans-up all remaining configuration data, log records, events, * files from the file pool etc. * * In the future, the functionality of {@link uninstall_plugin()} function may be moved * into this method and all the code should be refactored to use it. At the moment, we * mimic this future behaviour by wrapping that function call. * * @param string $component * @param progress_trace $progress traces the process * @return bool true on success, false on errors/problems */ public function uninstall_plugin($component, progress_trace $progress) { $pluginfo = $this->get_plugin_info($component); if (is_null($pluginfo)) { return false; } // Give the pluginfo class a chance to execute some steps. $result = $pluginfo->uninstall($progress); if (!$result) { return false; } // Call the legacy core function to uninstall the plugin. ob_start(); uninstall_plugin($pluginfo->type, $pluginfo->name); $progress->output(ob_get_clean()); return true; }
/** * Uninstall a plugin on this site. */ function _wprp_uninstall_plugin($plugin) { global $wp_filesystem; if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) { return new WP_Error('disallow-file-mods', __("File modification is disabled with the DISALLOW_FILE_MODS constant.", 'wpremote')); } include_once ABSPATH . 'wp-admin/includes/admin.php'; include_once ABSPATH . 'wp-admin/includes/upgrade.php'; include_once ABSPATH . 'wp-includes/update.php'; if (!_wpr_check_filesystem_access() || !WP_Filesystem()) { return new WP_Error('filesystem-not-writable', __('The filesystem is not writable with the supplied credentials', 'wpremote')); } $plugins_dir = $wp_filesystem->wp_plugins_dir(); if (empty($plugins_dir)) { return new WP_Error('missing-plugin-dir', __('Unable to locate WordPress Plugin directory.', 'wpremote')); } $plugins_dir = trailingslashit($plugins_dir); if (is_uninstallable_plugin($plugin)) { uninstall_plugin($plugin); } $this_plugin_dir = trailingslashit(dirname($plugins_dir . $plugin)); // If plugin is in its own directory, recursively delete the directory. if (strpos($plugin, '/') && $this_plugin_dir != $plugins_dir) { //base check on if plugin includes directory separator AND that it's not the root plugin folder $deleted = $wp_filesystem->delete($this_plugin_dir, true); } else { $deleted = $wp_filesystem->delete($plugins_dir . $plugin); } if ($deleted) { if ($current = get_site_transient('update_plugins')) { unset($current->response[$plugin]); set_site_transient('update_plugins', $current); } return array('status' => 'success'); } else { return new WP_Error('plugin-uninstall', __('Plugin uninstalled, but not deleted.', 'wpremote')); } }
/** * Automatically clean-up all plugin data and remove the plugin DB tables * * NOTE: do not call directly, use new /admin/plugins.php?uninstall=component instead! * * @param string $type The plugin type, eg. 'mod', 'qtype', 'workshopgrading' etc. * @param string $name The plugin name, eg. 'forum', 'multichoice', 'accumulative' etc. * @uses global $OUTPUT to produce notices and other messages * @return void */ function uninstall_plugin($type, $name) { global $CFG, $DB, $OUTPUT; // This may take a long time. core_php_time_limit::raise(); // Recursively uninstall all subplugins first. $subplugintypes = core_component::get_plugin_types_with_subplugins(); if (isset($subplugintypes[$type])) { $base = core_component::get_plugin_directory($type, $name); if (file_exists("{$base}/db/subplugins.php")) { $subplugins = array(); include "{$base}/db/subplugins.php"; foreach ($subplugins as $subplugintype => $dir) { $instances = core_component::get_plugin_list($subplugintype); foreach ($instances as $subpluginname => $notusedpluginpath) { uninstall_plugin($subplugintype, $subpluginname); } } } } $component = $type . '_' . $name; // eg. 'qtype_multichoice' or 'workshopgrading_accumulative' or 'mod_forum' if ($type === 'mod') { $pluginname = $name; // eg. 'forum' if (get_string_manager()->string_exists('modulename', $component)) { $strpluginname = get_string('modulename', $component); } else { $strpluginname = $component; } } else { $pluginname = $component; if (get_string_manager()->string_exists('pluginname', $component)) { $strpluginname = get_string('pluginname', $component); } else { $strpluginname = $component; } } echo $OUTPUT->heading($pluginname); // Delete all tag instances associated with this plugin. require_once $CFG->dirroot . '/tag/lib.php'; tag_delete_instances($component); // Custom plugin uninstall. $plugindirectory = core_component::get_plugin_directory($type, $name); $uninstalllib = $plugindirectory . '/db/uninstall.php'; if (file_exists($uninstalllib)) { require_once $uninstalllib; $uninstallfunction = 'xmldb_' . $pluginname . '_uninstall'; // eg. 'xmldb_workshop_uninstall()' if (function_exists($uninstallfunction)) { // Do not verify result, let plugin complain if necessary. $uninstallfunction(); } } // Specific plugin type cleanup. $plugininfo = core_plugin_manager::instance()->get_plugin_info($component); if ($plugininfo) { $plugininfo->uninstall_cleanup(); core_plugin_manager::reset_caches(); } $plugininfo = null; // perform clean-up task common for all the plugin/subplugin types //delete the web service functions and pre-built services require_once $CFG->dirroot . '/lib/externallib.php'; external_delete_descriptions($component); // delete calendar events $DB->delete_records('event', array('modulename' => $pluginname)); // Delete scheduled tasks. $DB->delete_records('task_scheduled', array('component' => $pluginname)); // Delete Inbound Message datakeys. $DB->delete_records_select('messageinbound_datakeys', 'handler IN (SELECT id FROM {messageinbound_handlers} WHERE component = ?)', array($pluginname)); // Delete Inbound Message handlers. $DB->delete_records('messageinbound_handlers', array('component' => $pluginname)); // delete all the logs $DB->delete_records('log', array('module' => $pluginname)); // delete log_display information $DB->delete_records('log_display', array('component' => $component)); // delete the module configuration records unset_all_config_for_plugin($component); if ($type === 'mod') { unset_all_config_for_plugin($pluginname); } // delete message provider message_provider_uninstall($component); // delete the plugin tables $xmldbfilepath = $plugindirectory . '/db/install.xml'; drop_plugin_tables($component, $xmldbfilepath, false); if ($type === 'mod' or $type === 'block') { // non-frankenstyle table prefixes drop_plugin_tables($name, $xmldbfilepath, false); } // delete the capabilities that were defined by this module capabilities_cleanup($component); // remove event handlers and dequeue pending events events_uninstall($component); // Delete all remaining files in the filepool owned by the component. $fs = get_file_storage(); $fs->delete_component_files($component); // Finally purge all caches. purge_all_caches(); // Invalidate the hash used for upgrade detections. set_config('allversionshash', ''); echo $OUTPUT->notification(get_string('success'), 'notifysuccess'); }
function check_config(&$a) { $build = get_config('system', 'build'); if (!x($build)) { $build = set_config('system', 'build', DB_UPDATE_VERSION); } $url = get_config('system', 'url'); // if the url isn't set or the stored url is radically different // than the currently visited url, store the current value accordingly. // "Radically different" ignores common variations such as http vs https // and www.example.com vs example.com. if (!x($url) || !link_compare($url, $a->get_baseurl())) { $url = set_config('system', 'url', $a->get_baseurl()); } if ($build != DB_UPDATE_VERSION) { $stored = intval($build); $current = intval(DB_UPDATE_VERSION); if ($stored < $current && file_exists('update.php')) { load_config('database'); // We're reporting a different version than what is currently installed. // Run any existing update scripts to bring the database up to current. require_once 'update.php'; // make sure that boot.php and update.php are the same release, we might be // updating right this very second and the correct version of the update.php // file may not be here yet. This can happen on a very busy site. if (DB_UPDATE_VERSION == UPDATE_VERSION) { for ($x = $stored; $x < $current; $x++) { if (function_exists('update_' . $x)) { // There could be a lot of processes running or about to run. // We want exactly one process to run the update command. // So store the fact that we're taking responsibility // after first checking to see if somebody else already has. // If the update fails or times-out completely you may need to // delete the config entry to try again. if (get_config('database', 'update_' . $x)) { break; } set_config('database', 'update_' . $x, '1'); // call the specific update $func = 'update_' . $x; $retval = $func(); if ($retval) { //send the administrator an e-mail $email_tpl = get_intltext_template("update_fail_eml.tpl"); $email_msg = replace_macros($email_tpl, array('$sitename' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$update' => $x, '$error' => sprintf(t('Update %s failed. See error logs.'), $x))); $subject = sprintf(t('Update Error at %s'), $a->get_baseurl()); mail($a->config['admin_email'], $subject, $email_msg, 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-transfer-encoding: 8bit'); //try the logger logger('CRITICAL: Update Failed: ' . $x); } else { set_config('database', 'update_' . $x, 'success'); } } } set_config('system', 'build', DB_UPDATE_VERSION); } } } /** * * Synchronise plugins: * * $a->config['system']['addon'] contains a comma-separated list of names * of plugins/addons which are used on this system. * Go through the database list of already installed addons, and if we have * an entry, but it isn't in the config list, call the uninstall procedure * and mark it uninstalled in the database (for now we'll remove it). * Then go through the config list and if we have a plugin that isn't installed, * call the install procedure and add it to the database. * */ $r = q("SELECT * FROM `addon` WHERE `installed` = 1"); if (count($r)) { $installed = $r; } else { $installed = array(); } $plugins = get_config('system', 'addon'); $plugins_arr = array(); if ($plugins) { $plugins_arr = explode(',', str_replace(' ', '', $plugins)); } $a->plugins = $plugins_arr; $installed_arr = array(); if (count($installed)) { foreach ($installed as $i) { if (!in_array($i['name'], $plugins_arr)) { uninstall_plugin($i['name']); } else { $installed_arr[] = $i['name']; } } } if (count($plugins_arr)) { foreach ($plugins_arr as $p) { if (!in_array($p, $installed_arr)) { install_plugin($p); } } } load_hooks(); return; }
/** * Remove directory and files of a plugin for a single or list of plugin(s). * * If the plugins parameter list is empty, false will be returned. True when * completed. * * @since 2.6.0 * * @param array $plugins List of plugin * @param string $redirect Redirect to page when complete. * @return mixed */ function delete_plugins($plugins, $redirect = '') { global $wp_filesystem; if (empty($plugins)) { return false; } $checked = array(); foreach ($plugins as $plugin) { $checked[] = 'checked[]=' . $plugin; } ob_start(); $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins'); if (false === ($credentials = request_filesystem_credentials($url))) { $data = ob_get_contents(); ob_end_clean(); if (!empty($data)) { include_once ABSPATH . 'wp-admin/admin-header.php'; echo $data; include ABSPATH . 'wp-admin/admin-footer.php'; exit; } return; } if (!WP_Filesystem($credentials)) { request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again $data = ob_get_contents(); ob_end_clean(); if (!empty($data)) { include_once ABSPATH . 'wp-admin/admin-header.php'; echo $data; include ABSPATH . 'wp-admin/admin-footer.php'; exit; } return; } if (!is_object($wp_filesystem)) { return new WP_Error('fs_unavailable', __('Could not access filesystem.')); } if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors); } //Get the base plugin folder $plugins_dir = $wp_filesystem->wp_plugins_dir(); if (empty($plugins_dir)) { return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.')); } $plugins_dir = trailingslashit($plugins_dir); $errors = array(); foreach ($plugins as $plugin_file) { // Run Uninstall hook if (is_uninstallable_plugin($plugin_file)) { uninstall_plugin($plugin_file); } $this_plugin_dir = trailingslashit(dirname($plugins_dir . $plugin_file)); // If plugin is in its own directory, recursively delete the directory. if (strpos($plugin_file, '/') && $this_plugin_dir != $plugins_dir) { //base check on if plugin includes directory separator AND that its not the root plugin folder $deleted = $wp_filesystem->delete($this_plugin_dir, true); } else { $deleted = $wp_filesystem->delete($plugins_dir . $plugin_file); } if (!$deleted) { $errors[] = $plugin_file; } } if (!empty($errors)) { return new WP_Error('could_not_remove_plugin', sprintf(__('Could not fully remove the plugin(s) %s.'), implode(', ', $errors))); } // Force refresh of plugin update information if ($current = get_site_transient('update_plugins')) { unset($current->response[$plugin_file]); set_site_transient('update_plugins', $current); } return true; }
/** * Uninstall a plugin. * * ## OPTIONS * * <plugin>... * : One or more plugins to uninstall. * * [--deactivate] * : Deactivate the plugin before uninstalling. Default behavior is to warn and skip if the plugin is active. * * [--skip-delete] * : If set, the plugin files will not be deleted. Only the uninstall procedure * will be run. * * ## EXAMPLES * * $ wp plugin uninstall hello * Uninstalled and deleted 'hello' plugin. * Success: Installed 1 of 1 plugins. */ public function uninstall($args, $assoc_args = array()) { $successes = $errors = 0; $plugins = $this->fetcher->get_many($args); foreach ($plugins as $plugin) { if (is_plugin_active($plugin->file) && !WP_CLI\Utils\get_flag_value($assoc_args, 'deactivate')) { WP_CLI::warning("The '{$plugin->name}' plugin is active."); $errors++; continue; } if (\WP_CLI\Utils\get_flag_value($assoc_args, 'deactivate')) { WP_CLI::log("Deactivating '{$plugin->name}'..."); $this->chained_command = true; $this->deactivate(array($plugin->name)); $this->chained_command = false; } uninstall_plugin($plugin->file); if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'skip-delete') && $this->_delete($plugin)) { WP_CLI::log("Uninstalled and deleted '{$plugin->name}' plugin."); } else { WP_CLI::log("Ran uninstall procedure for '{$plugin->name}' plugin without deleting."); } $successes++; } if (!$this->chained_command) { Utils\report_batch_operation_results('plugin', 'uninstall', count($args), $successes, $errors); } }