MDL-39088 migrate enrol uninstallation to plugin_manager

This commit is contained in:
Petr Škoda
2013-06-27 22:20:35 +02:00
parent b07526e8de
commit 5643f932e9
5 changed files with 50 additions and 64 deletions
+29 -2
View File
@@ -3605,11 +3605,38 @@ class plugininfo_enrol extends plugininfo_base {
}
public function is_uninstall_allowed() {
if ($this->name === 'manual') {
return false;
}
return true;
}
public function get_uninstall_url() {
return new moodle_url('/admin/enrol.php', array('action' => 'uninstall', 'enrol' => $this->name, 'sesskey' => sesskey()));
/**
* Return warning with number of activities and number of affected courses.
*
* @return string
*/
public function get_uninstall_extra_warning() {
global $DB, $OUTPUT;
$sql = "SELECT COUNT('x')
FROM {user_enrolments} ue
JOIN {enrol} e ON e.id = ue.enrolid
WHERE e.enrol = :plugin";
$count = $DB->count_records_sql($sql, array('plugin'=>$this->name));
if (!$count) {
return '';
}
$migrateurl = new moodle_url('/admin/enrol.php', array('action'=>'migrate', 'enrol'=>$this->name, 'sesskey'=>sesskey()));
$migrate = new single_button($migrateurl, get_string('migratetomanual', 'core_enrol'));
$button = $OUTPUT->render($migrate);
$result = '<p>'.get_string('uninstallextraconfirmenrol', 'core_plugin', array('enrolments'=>$count)).'</p>';
$result .= $button;
return $result;
}
}