2015-03-17 22:02:19 -04:00
< ? php
require ( HESK_PATH . 'hesk_settings.inc.php' );
2015-09-12 00:46:46 -04:00
function executeQuery ( $sql )
{
2015-03-17 22:02:19 -04:00
global $hesk_last_query ;
global $hesk_db_link ;
2015-09-12 00:46:46 -04:00
if ( function_exists ( 'mysqli_connect' )) {
2015-03-17 22:02:19 -04:00
2015-09-12 00:46:46 -04:00
if ( ! $hesk_db_link && ! hesk_dbConnect ()) {
2015-03-17 22:02:19 -04:00
return false ;
}
$hesk_last_query = $sql ;
2015-09-12 00:46:46 -04:00
if ( $res = @ mysqli_query ( $hesk_db_link , $sql )) {
2015-03-17 22:02:19 -04:00
return $res ;
2015-09-12 00:46:46 -04:00
} else {
print " Could not execute query: $sql . MySQL said: " . mysqli_error ( $hesk_db_link );
2015-03-17 22:02:19 -04:00
http_response_code ( 500 );
die ();
}
} else {
2015-09-12 00:46:46 -04:00
if ( ! $hesk_db_link && ! hesk_dbConnect ()) {
2015-03-17 22:02:19 -04:00
return false ;
}
$hesk_last_query = $sql ;
2015-09-12 00:46:46 -04:00
if ( $res = @ mysql_query ( $sql , $hesk_db_link )) {
2015-03-17 22:02:19 -04:00
return $res ;
2015-09-12 00:46:46 -04:00
} else {
print " Could not execute query: $sql . MySQL said: " . mysql_error ();
2015-03-17 22:02:19 -04:00
http_response_code ( 500 );
die ();
}
}
}
2015-09-12 00:46:46 -04:00
function replaceStatusColumn ()
{
2015-03-17 22:02:19 -04:00
global $hesk_settings ;
hesk_dbConnect ();
2015-09-12 00:46:46 -04:00
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` ADD COLUMN `status_int` ENUM('0','1','2','3','4','5') NOT NULL AFTER `status`; " );
$ticketsRS = executeQuery ( " SELECT `id`, `status` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets`; " );
while ( $currentResult = $ticketsRS -> fetch_assoc ()) {
2015-03-17 22:02:19 -04:00
2015-09-12 00:46:46 -04:00
executeQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` SET `status_int` = ' " . intval ( $currentResult [ 'status' ]) . " ' WHERE `id` = " . $currentResult [ 'id' ]);
2015-03-17 22:02:19 -04:00
}
2015-09-12 00:46:46 -04:00
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` DROP COLUMN `status` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` CHANGE COLUMN `status_int` `status` ENUM('0','1','2','3','4','5') NOT NULL " );
executeQuery ( " DROP TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " statuses` " );
2015-03-17 22:02:19 -04:00
}
2015-09-12 00:46:46 -04:00
function removeOtherColumns ()
{
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` DROP COLUMN `autorefresh` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` DROP COLUMN `parent` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` DROP COLUMN `can_manage_settings` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` DROP COLUMN `active` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` DROP COLUMN `notify_note_unassigned` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` DROP COLUMN `can_change_notification_settings` " );
executeQuery ( " DROP TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " settings` " );
executeQuery ( " DROP TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " verified_emails` " );
executeQuery ( " DROP TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " pending_verification_emails` " );
executeQuery ( " DROP TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " stage_tickets` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " service_messages` DROP COLUMN `icon` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` DROP COLUMN `latitude` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` DROP COLUMN `longitude` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " stage_tickets` DROP COLUMN `latitude` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " stage_tickets` DROP COLUMN `longitude` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " categories` DROP COLUMN `manager` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` DROP COLUMN `permission_template` " );
executeQuery ( " DROP TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " permission_templates` " );
executeQuery ( " DROP TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " quick_help_sections` " );
executeQuery ( " DROP TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " text_to_status_xref` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " attachments` DROP COLUMN `download_count` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " kb_attachments` DROP COLUMN `download_count` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` DROP COLUMN `html` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " stage_tickets` DROP COLUMN `html` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " replies` DROP COLUMN `html` " );
2015-10-18 23:55:29 -04:00
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` DROP COLUMN `user_agent` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` DROP COLUMN `screen_resolution_width` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` DROP COLUMN `screen_resolution_height` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " stage_tickets` DROP COLUMN `user_agent` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " stage_tickets` DROP COLUMN `screen_resolution_width` " );
executeQuery ( " ALTER TABLE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " stage_tickets` DROP COLUMN `screen_resolution_height` " );
2015-05-15 22:12:30 -04:00
2015-03-19 20:48:46 -04:00
// These queries are ran in case someone used an unfortunate installation they may have not properly cleaned up tables
2015-09-12 00:46:46 -04:00
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`' );
2015-03-17 22:02:19 -04:00
}