Files
itflow/admin/database_updates/4.2.8.php

56 lines
2.8 KiB
PHP

<?php
/*
* ITFlow - Database update to version 4.2.8 (from 4.2.7)
* Included by admin/database_updates.php - do not access directly
*
* Watchers are CCs - the people copied in on every email about a ticket, whose replies count as
* the client's. Their table and columns take the name:
* ticket_watchers -> ticket_ccs
* watcher_id -> ticket_cc_id
* watcher_name -> ticket_cc_name
* watcher_email -> ticket_cc_email
* watcher_ticket_id -> ticket_cc_ticket_id, its index with it
*
* Re-runnable: the table is renamed only while ticket_watchers is there and ticket_ccs isn't, and
* each column and the index only while it has its old name.
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
$itflow_table_exists = function ($table) use ($mysqli) {
$result = mysqli_query($mysqli, "SELECT 1 FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$table' LIMIT 1");
return $result && mysqli_num_rows($result) > 0;
};
if ($itflow_table_exists('ticket_watchers') && !$itflow_table_exists('ticket_ccs')) {
mysqli_query($mysqli, "RENAME TABLE `ticket_watchers` TO `ticket_ccs`");
}
if ($itflow_table_exists('ticket_ccs')) {
$itflow_cc_columns = [
'watcher_id' => "`ticket_cc_id` int(11) NOT NULL AUTO_INCREMENT",
'watcher_name' => "`ticket_cc_name` varchar(255) DEFAULT NULL",
'watcher_email' => "`ticket_cc_email` varchar(255) NOT NULL",
'watcher_ticket_id' => "`ticket_cc_ticket_id` int(11) NOT NULL",
];
foreach ($itflow_cc_columns as $itflow_old_column => $itflow_definition) {
$itflow_column_exists = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'ticket_ccs' AND COLUMN_NAME = '$itflow_old_column' LIMIT 1");
if ($itflow_column_exists && mysqli_num_rows($itflow_column_exists) > 0) {
mysqli_query($mysqli, "ALTER TABLE `ticket_ccs` CHANGE `$itflow_old_column` $itflow_definition");
}
}
// The index on the ticket, under its new name
$itflow_index = function ($name) use ($mysqli) {
$result = mysqli_query($mysqli, "SELECT 1 FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'ticket_ccs' AND INDEX_NAME = '$name' LIMIT 1");
return $result && mysqli_num_rows($result) > 0;
};
if ($itflow_index('watcher_ticket_id')) {
mysqli_query($mysqli, "ALTER TABLE `ticket_ccs` DROP INDEX `watcher_ticket_id`");
}
if (!$itflow_index('ticket_cc_ticket_id')) {
mysqli_query($mysqli, "ALTER TABLE `ticket_ccs` ADD KEY `ticket_cc_ticket_id` (`ticket_cc_ticket_id`)");
}
}