mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
54 lines
3.4 KiB
PHP
54 lines
3.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* ITFlow - Database update to version 4.2.6 (from 4.2.5)
|
|
* Included by admin/database_updates.php - do not access directly
|
|
*
|
|
* One email conversation per ticket (functions/ticket_mail_thread.php):
|
|
* ticket_mail_threads - the Message-ID of each email about a ticket, ITFlow's own (mail_thread_ours 1)
|
|
* and the client's that raised it or replied on it, so the Ticket Email Parser finds the ticket an
|
|
* email answers by its In-Reply-To and References, and each email ITFlow sends names the ones before it
|
|
* email_queue.email_cc - the people copied in on an email, as JSON [{email, name}], when one email goes
|
|
* to a ticket's contact with its watchers copied in
|
|
* email_queue.email_headers - the conversation's headers an email goes with, as JSON {name: value}
|
|
* settings.config_ticket_email_copy - one email about a ticket, its watchers copied in (1), or one each (0)
|
|
* settings.config_ticket_email_relay - a client's reply goes on to the watchers who didn't have it (1)
|
|
* tickets.ticket_number indexed - every email with a ticket number in its subject finds the ticket by it
|
|
*
|
|
* Re-runnable: the table is made and each column and the index added only where it isn't there.
|
|
*/
|
|
|
|
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
|
|
|
|
mysqli_query($mysqli, "CREATE TABLE IF NOT EXISTS `ticket_mail_threads` (
|
|
`mail_thread_id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`mail_thread_ticket_id` int(11) NOT NULL,
|
|
`mail_thread_message_id` varchar(255) NOT NULL,
|
|
`mail_thread_ours` tinyint(1) NOT NULL DEFAULT 0,
|
|
`mail_thread_created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
|
PRIMARY KEY (`mail_thread_id`),
|
|
UNIQUE KEY `mail_thread_message_id` (`mail_thread_message_id`, `mail_thread_ticket_id`),
|
|
KEY `mail_thread_ticket_id` (`mail_thread_ticket_id`),
|
|
CONSTRAINT `ticket_mail_threads_ibfk_1` FOREIGN KEY (`mail_thread_ticket_id`) REFERENCES `tickets` (`ticket_id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci");
|
|
|
|
$itflow_thread_columns = [
|
|
['email_queue', 'email_cc', "text DEFAULT NULL AFTER `email_recipient_name`"],
|
|
['email_queue', 'email_headers', "text DEFAULT NULL AFTER `email_attachments`"],
|
|
['settings', 'config_ticket_email_copy', "tinyint(1) NOT NULL DEFAULT 1 AFTER `config_ticket_client_general_notifications`"],
|
|
['settings', 'config_ticket_email_relay', "tinyint(1) NOT NULL DEFAULT 1 AFTER `config_ticket_email_copy`"],
|
|
];
|
|
foreach ($itflow_thread_columns as [$itflow_table, $itflow_column, $itflow_definition]) {
|
|
$itflow_column_exists = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
|
|
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$itflow_table' AND COLUMN_NAME = '$itflow_column' LIMIT 1");
|
|
if (!$itflow_column_exists || mysqli_num_rows($itflow_column_exists) === 0) {
|
|
mysqli_query($mysqli, "ALTER TABLE `$itflow_table` ADD `$itflow_column` $itflow_definition");
|
|
}
|
|
}
|
|
|
|
$itflow_index_exists = mysqli_query($mysqli, "SELECT 1 FROM information_schema.STATISTICS
|
|
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'tickets' AND INDEX_NAME = 'ticket_number' LIMIT 1");
|
|
if (!$itflow_index_exists || mysqli_num_rows($itflow_index_exists) === 0) {
|
|
mysqli_query($mysqli, "ALTER TABLE `tickets` ADD KEY `ticket_number` (`ticket_number`)");
|
|
}
|