MDL-45619 repository: corrections to uninstall, display link

This commit is contained in:
Marina Glancy 2015-03-04 13:36:25 +08:00 committed by Stephen Bourget
parent f31f5f6659
commit a1ec48c9e8
2 changed files with 19 additions and 31 deletions

View File

@ -264,6 +264,7 @@ if (($action == 'edit') || ($action == 'new')) {
$strshow = get_string('on', 'repository');
$strhide = get_string('off', 'repository');
$strdelete = get_string('disabled', 'repository');
$struninstall = get_string('uninstallplugin', 'core_admin');
$actionchoicesforexisting = array(
'show' => $strshow,
@ -286,9 +287,9 @@ if (($action == 'edit') || ($action == 'new')) {
// Table to list plug-ins
$table = new html_table();
$table->head = array(get_string('name'), get_string('isactive', 'repository'), get_string('order'), $settingsstr);
$table->head = array(get_string('name'), get_string('isactive', 'repository'), get_string('order'), $settingsstr, $struninstall);
$table->colclasses = array('leftalign', 'centeralign', 'centeralign', 'centeralign', 'centeralign');
$table->colclasses = array('leftalign', 'centeralign', 'centeralign', 'centeralign', 'centeralign', 'centeralign');
$table->id = 'repositoriessetting';
$table->data = array();
$table->attributes['class'] = 'admintable generaltable';
@ -384,7 +385,12 @@ if (($action == 'edit') || ($action == 'new')) {
$updowncount++;
$table->data[] = array($i->get_readablename(), $OUTPUT->render($select), $updown, $settings);
$uninstall = '';
if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('repository_' . $typename, 'manage')) {
$uninstall = html_writer::link($uninstallurl, $struninstall);
}
$table->data[] = array($i->get_readablename(), $OUTPUT->render($select), $updown, $settings, $uninstall);
if (!in_array($typename, $alreadyplugins)) {
$alreadyplugins[] = $typename;
@ -400,7 +406,11 @@ if (($action == 'edit') || ($action == 'new')) {
if (!in_array($plugin, $alreadyplugins)) {
$select = new single_select(repository_action_url($plugin, 'repos'), 'action', $actionchoicesfornew, 'delete', null, 'applyto' . basename($plugin));
$select->set_label(get_string('action'), array('class' => 'accesshide'));
$table->data[] = array(get_string('pluginname', 'repository_'.$plugin), $OUTPUT->render($select), '', '');
$uninstall = '';
if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('repository_' . $plugin, 'manage')) {
$uninstall = html_writer::link($uninstallurl, $struninstall);
}
$table->data[] = array(get_string('pluginname', 'repository_'.$plugin), $OUTPUT->render($select), '', '', $uninstall);
}
}
}

View File

@ -87,34 +87,12 @@ class repository extends base {
* and cleans up all records in the DB for that repository.
*/
public function uninstall_cleanup() {
global $DB;
global $CFG;
require_once($CFG->dirroot.'/repository/lib.php');
// Get all instances of this repository.
$count = $DB->count_records('repository', array('type' => $this->name));
if ($count > 0) {
// This repository is in use.
$rec = $DB->get_record('repository', array('type' => $this->name));
$repos = $DB->get_records('repository_instances', array('typeid' => $rec->id));
foreach ($repos as $repo) {
// Convert all files to local storage.
$fs = get_file_storage();
$files = $fs->get_external_files($repo->id);
foreach ($files as $storedfile) {
$fs->import_external_file($storedfile);
}
// Clean up from the DB.
$DB->delete_records('repository_instances', array('id' => $repo->id));
$DB->delete_records('repository_instance_config', array('instanceid' => $repo->id));
}
// Clean up from config_plugins.
// NOTE: Repository plugins are not using the correct plugin names.
$DB->delete_records('config_plugins', array('plugin' => $this->name));
// Remove the record from the repository table.
$DB->delete_records('repository', array('id' => $rec->id));
$repo = \repository::get_type_by_typename($this->name);
if ($repo) {
$repo->delete(true);
}
parent::uninstall_cleanup();