Browse Source

Closes #168 Provide a way to uninstall Mods for HESK

merge-requests/2/head
Mike Koch 7 years ago
parent
commit
adfc275cb5
  1. 27
      install/mods-for-hesk/ajax/uninstall-database-ajax.php
  2. 12
      install/mods-for-hesk/index.html
  3. 92
      install/mods-for-hesk/js/uninstall-scripts.js
  4. 4
      install/mods-for-hesk/sql/installSql.php
  5. 9
      install/mods-for-hesk/sql/uninstallSql.php
  6. 23
      install/mods-for-hesk/uninstallModsForHesk.php

27
install/mods-for-hesk/ajax/uninstall-database-ajax.php

@ -7,10 +7,31 @@ hesk_load_database_functions();
require('../sql/uninstallSql.php');
$task = $_POST['task'];
if ($task == 1) {
executePre140Scripts();
if ($task == 'status-change') {
replaceStatusColumn();
} elseif ($task == 'autorefresh') {
removeAutorefresh();
} elseif ($task == 'parent-child') {
removeParentColumn();
} elseif ($task == 'settings-access') {
removeHelpDeskSettingsPermission();
} elseif ($task == 'activate-user') {
removeActiveColumn();
} elseif ($task == 'notify-note-unassigned') {
removeNotifyNoteUnassigned();
} elseif ($task == 'user-manage-notification-settings') {
removeUserManageOwnNotificationSettingsColumn();
} elseif ($task == 'settings-table') {
removeSettingsTable();
} elseif ($task == 'verified-emails-table') {
removeVerifiedEmailsTable();
} elseif ($task == 'pending-verification-emails-table') {
removePendingVerificationEmailsTable();
} elseif ($task == 'pending-verification-tickets-table') {
removeTicketsPendingVerificationTable();
} elseif ($task == 'miscellaneous') {
executeMiscellaneousSql();
} else {
print 'The task "'.$task.'" was not recognized. Check the value submitted and try again.';
http_response_code(400);
}
return;

12
install/mods-for-hesk/index.html

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
window.location.replace("modsForHesk.php");
</script>
</body>
</html>

92
install/mods-for-hesk/js/uninstall-scripts.js

@ -1,28 +1,104 @@
function processUninstallation() {
var tasks = ['status-change', 'autorefresh', 'parent-child', 'settings-access', 'activate-user',
function getTasks() {
return ['status-change', 'autorefresh', 'parent-child', 'settings-access', 'activate-user',
'notify-note-unassigned', 'user-manage-notification-settings', 'settings-table', 'verified-emails-table',
'pending-verification-emails-table', 'pending-verification-tickets-table'];
'pending-verification-emails-table', 'pending-verification-tickets-table', 'miscellaneous'];
}
function processUninstallation() {
var tasks = getTasks();
//-- Change status column to default HESK values
tasks.forEach(function(task) {
startUninstallation(task);
executeUninstallation(task);
});
}
function startUninstallation(task) {
$('#spinner-'+task)
.removeClass('fa-exclamation-triangle')
.addClass('fa-spinner')
.addClass('fa-pulse');
changeRowTo('row', task, 'info');
changeTextTo('span', task, 'In Progress');
}
function changeTextTo(prefix, task, text) {
$('#'+prefix+'-'+task).text(text);
}
function changeRowTo(prefix, task, clazz) {
//-- Remove all classes
$('#'+prefix+'-'+task)
.removeClass('info')
.removeClass('warning')
.removeClass('danger')
.removeClass('success');
//-- Re-add the requested class
$('#'+prefix+'-'+task).addClass(clazz);
}
function executeUninstallation(task) {
appendToInstallConsole('<tr><td><span class="label label-info">INFO</span></td><td>Starting task code: ' + task + '</td></tr>');
$.ajax({
type: 'POST',
url: 'ajax/install-database-ajax.php',
url: 'ajax/uninstall-database-ajax.php',
data: { task: task },
success: function(data) {
markUninstallAsSuccess(cssclass, formattedVersion);
markUninstallAsSuccess(task);
checkForCompletion();
},
error: function(data) {
appendToInstallConsole('<tr><td><span class="label label-danger">ERROR</span></td><td>'+ data.responseText + '</td></tr>');
markUninstallAsFailure(cssclass);
if (data.status == 400) {
appendToInstallConsole('<tr><td><span class="label label-danger">ERROR</span></td><td>The task <code>'+ task +'</code> was not recognized. Check the value submitted and try again.</td></tr>');
} else {
appendToInstallConsole('<tr><td><span class="label label-danger">ERROR</span></td><td>'+ data.responseText + '</td></tr>');
}
markUninstallAsFailure(task);
}
});
}
function checkForCompletion() {
// If all rows have a .success row, installation is finished
var numberOfTasks = getTasks().length;
var numberOfCompletions = $('tr.success').length;
if (numberOfTasks == numberOfCompletions) {
uninstallationFinished();
}
}
function uninstallationFinished() {
appendToInstallConsole('<tr><td><span class="label label-success">SUCCESS</span></td><td>Uninstallation complete</td></tr>');
var output = '<div class="panel-body">' +
'<div class="col-md-12 text-center">' +
'<i class="fa fa-check-circle fa-4x" style="color: #008000"></i><br><br>' +
'<h4>Awesome! The automated portion of uninstalling Mods for HESK has completed. ' +
'Please follow <a href="http://mods-for-hesk.mkochcs.com/uninstall-instructions.php" target="_blank">these instructions</a> ' +
'on the Mods for HESK website to finish uninstallation.</h4>' +
'</div>' +
'</div>';
$('#uninstall-information').html(output);
}
function markUninstallAsSuccess(task) {
removeSpinner(task);
$('#spinner-'+task).addClass('fa-check-circle');
changeTextTo('span', task, 'Completed Successfully');
changeRowTo('row', task, 'success');
appendToInstallConsole('<tr><td><span class="label label-success">SUCCESS</span></td><td>Uninstall for task code: <code>' + task + '</code> complete</td></tr>');
}
function markUninstallAsFailure(task) {
removeSpinner(task);
$('#spinner-'+task).addClass('fa-times-circle');
changeRowTo('row', task, 'danger');
changeTextTo('span', task, 'Uninstall failed! Check the console for more information');
}
function removeSpinner(task) {
$('#spinner-'+task)
.removeClass('fa-pulse')
.removeClass('fa-spinner');
}
jQuery(document).ready(loadJquery);

4
install/mods-for-hesk/sql/installSql.php

@ -335,6 +335,10 @@ function execute210Scripts() {
hesk_dbConnect();
executeQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."settings` SET `Value` = '2.1.0' WHERE `Key` = 'modsForHeskVersion'");
// Some old tables may not have been dropped during the 2.0.0 upgrade. Check and drop if necessary
executeQuery("DROP TABLE IF EXISTS `".hesk_dbEscape($hesk['db_pfix'])."denied_ips`");
executeQuery("DROP TABLE IF EXISTS `".hesk_dbEscape($hesk['db_pfix'])."denied_emails`");
}
function execute210FileUpdate() {

9
install/mods-for-hesk/sql/uninstallSql.php

@ -127,4 +127,13 @@ function removeTicketsPendingVerificationTable() {
hesk_dbConnect();
executeQuery("DROP TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."stage_tickets`");
}
function executeMiscellaneousSql() {
global $hesk_settings;
hesk_dbConnect();
// These queries are ran in case someone used an unfortunate installation they may have not properly cleaned up tables
executeQuery('DROP TABLE IF EXISTS `'.hesk_dbEscape($hesk_settings['db_pfix']).'denied_ips`');
executeQuery('DROP TABLE IF EXISTS `'.hesk_dbEscape($hesk_settings['db_pfix']).'denied_emails`');
}

23
install/mods-for-hesk/uninstallModsForHesk.php

@ -16,10 +16,11 @@ function echoTaskRows() {
printUninstallRow('Remove verified emails table', 'verified-emails-table');
printUninstallRow('Remove pending verification emails table', 'pending-verification-emails-table');
printUninstallRow('Remove tickets pending verification table', 'pending-verification-tickets-table');
printUninstallRow('Miscellaneous database cleanup changes', 'miscellaneous');
}
function printUninstallRow($text, $id) {
echo '<tr id="'.$id.'">';
echo '<tr id="row-'.$id.'">';
echo '<td>'.$text.'</td>';
echo '<td><i id="spinner-'.$id.'" class="fa fa-spinner"></i> <span id="span-'.$id.'">Waiting...</span></td>';
echo '</tr>';
@ -50,7 +51,7 @@ function printUninstallRow($text, $id) {
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Uninstallation Progress</div>
<div class="uninstall-information">
<div id="uninstall-information">
<table class="table table-striped" style="table-layout:fixed;">
<thead>
<?php echoTaskRows(); ?>
@ -60,6 +61,24 @@ function printUninstallRow($text, $id) {
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Console</div>
<div style="max-height: 400px; overflow: auto;">
<table class="table table-striped">
<thead>
<tr>
<th>Severity</th>
<th>Message</th>
</tr>
</thead>
<tbody id="consoleBody"></tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script>
processUninstallation();

Loading…
Cancel
Save