Skip to content
Snippets Groups Projects
Commit 7a182d35 authored by Jared Hancock's avatar Jared Hancock
Browse files

Add migration patch for custom ticket numbers

parent 5cfa1f97
Branches
Tags
No related merge requests found
#
# Sequences installed with the system
#
# Fields:
# id: PK
# name: Name of the sequence
# next: Next value of the sequence
# padding: Padding character
# increment: Distance between two numbers of the sequence
# flags: Bitmask of flag settings. Currently known values are
# INTERNAL:=0x0001 (restrict delete)
#
---
# ID:1 is reserved for upgrades. When transitioning to osTicket 1.10, the
# sequence ID:1 will be configured to start counting from the current
# MAX(ticket.ticket_id). The upgrade will miss this step if there is no
# sequence with ID:1
- id: 1
name: "General Tickets"
next: 1
padding: '0'
increment: 1
flags: 1
/**
* @version v1.10.0
* @signature 00000000000000000000000000000000
* @title Custom Ticket Numbers
*
* This patch adds support for ticket number sequences to the database
* rather than the original implementation which had support for generating
* random numbers or using the database-created ticket_id value.
*
* This script will also migrate the previous settings, namely the
* use_random_ids config settings to the new system.
*/
DROP TABLE IF EXISTS `%TABLE_PREFIX%sequence`;
CREATE TABLE `%TABLE_PREFIX%sequence` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(64) DEFAULT NULL,
`flags` int(10) unsigned DEFAULT NULL,
`next` bigint(20) unsigned NOT NULL DEFAULT '1',
`increment` int(11) DEFAULT '1',
`padding` char(1) DEFAULT '0',
`updated` datetime NOT NULL,
PRIMARY KEY (`id`)
-- InnoDB is intended here because transaction support is required for row
-- locking
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SET @random = (SELECT `value` FROM `%TABLE_PREFIX%config`
WHERE `namespace` = 'core' AND `key` = 'use_random_ids');
-- Sequence (id=1) will be loaded in the task file
INSERT INTO `%TABLE_PREFIX%config` (`namespace`, `key`, `value`)
VALUES
('core', 'number_format', CASE WHEN @random THEN '######' ELSE '#' END),
('core', 'sequence_id', CASE WHEN @random THEN 0 ELSE 1 END);
DELETE FROM `%TABLE_PREFIX%config`
WHERE `namespace`='core' AND `key` = 'use_random_ids';
ALTER TABLE `%TABLE_PREFIX%help_topic`
ADD `flags` int(10) unsigned DEFAULT '0' AFTER `noautoresp`,
ADD `sequence_id` int(10) unsigned NOT NULL DEFAULT '0' AFTER `form_id`,
ADD `number_format` varchar(32) DEFAULT NULL AFTER `topic`;
-- Finished with patch
UPDATE `%TABLE_PREFIX%config`
SET `value` = '00000000000000000000000000000000'
WHERE `key` = 'schema_signature' AND `namespace` = 'core';
<?php
/*
* Loads the initial sequence from the inital data files
*/
class SequenceLoader extends MigrationTask {
var $description = "Loading initial data for sequences";
function run($max_time) {
$i18n = new Internationalization('en_US');
$sequences = $i18n->getTemplate('sequence.yaml')->getData();
foreach ($sequences as $s) {
Sequence::create($s);
$s->save();
}
db_query('UPDATE '.SEQUENCE_TABLE.' SET `next`= '
.'(SELECT MAX(ticket_id) FROM '.TICKET_TABLE.') '
.'WHERE `id`=1');
}
}
return 'SequenceLoader';
?>
...@@ -61,6 +61,20 @@ CREATE TABLE IF NOT EXISTS `%TABLE_PREFIX%faq_topic` ( ...@@ -61,6 +61,20 @@ CREATE TABLE IF NOT EXISTS `%TABLE_PREFIX%faq_topic` (
PRIMARY KEY (`faq_id`,`topic_id`) PRIMARY KEY (`faq_id`,`topic_id`)
) DEFAULT CHARSET=utf8; ) DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `%TABLE_PREFIX%sequence`;
CREATE TABLE `%TABLE_PREFIX%sequence` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(64) DEFAULT NULL,
`flags` int(10) unsigned DEFAULT NULL,
`next` bigint(20) unsigned NOT NULL DEFAULT '1',
`increment` int(11) DEFAULT '1',
`padding` char(1) DEFAULT '0',
`updated` datetime NOT NULL,
PRIMARY KEY (`id`)
-- InnoDB is intended here because transaction support is required for row
-- locking
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `%TABLE_PREFIX%sla`; DROP TABLE IF EXISTS `%TABLE_PREFIX%sla`;
CREATE TABLE `%TABLE_PREFIX%sla` ( CREATE TABLE `%TABLE_PREFIX%sla` (
`id` int(11) unsigned NOT NULL auto_increment, `id` int(11) unsigned NOT NULL auto_increment,
...@@ -404,6 +418,7 @@ CREATE TABLE `%TABLE_PREFIX%help_topic` ( ...@@ -404,6 +418,7 @@ CREATE TABLE `%TABLE_PREFIX%help_topic` (
`isactive` tinyint(1) unsigned NOT NULL default '1', `isactive` tinyint(1) unsigned NOT NULL default '1',
`ispublic` tinyint(1) unsigned NOT NULL default '1', `ispublic` tinyint(1) unsigned NOT NULL default '1',
`noautoresp` tinyint(3) unsigned NOT NULL default '0', `noautoresp` tinyint(3) unsigned NOT NULL default '0',
`flags` int(10) unsigned DEFAULT '0',
`priority_id` tinyint(3) unsigned NOT NULL default '0', `priority_id` tinyint(3) unsigned NOT NULL default '0',
`dept_id` tinyint(3) unsigned NOT NULL default '0', `dept_id` tinyint(3) unsigned NOT NULL default '0',
`staff_id` int(10) unsigned NOT NULL default '0', `staff_id` int(10) unsigned NOT NULL default '0',
...@@ -411,8 +426,10 @@ CREATE TABLE `%TABLE_PREFIX%help_topic` ( ...@@ -411,8 +426,10 @@ CREATE TABLE `%TABLE_PREFIX%help_topic` (
`sla_id` int(10) unsigned NOT NULL default '0', `sla_id` int(10) unsigned NOT NULL default '0',
`page_id` int(10) unsigned NOT NULL default '0', `page_id` int(10) unsigned NOT NULL default '0',
`form_id` int(10) unsigned NOT NULL default '0', `form_id` int(10) unsigned NOT NULL default '0',
`sequence_id` int(10) unsigned NOT NULL DEFAULT '0',
`sort` int(10) unsigned NOT NULL default '0', `sort` int(10) unsigned NOT NULL default '0',
`topic` varchar(32) NOT NULL default '', `topic` varchar(32) NOT NULL default '',
`number_format` varchar(32) DEFAULT NULL,
`notes` text, `notes` text,
`created` datetime NOT NULL, `created` datetime NOT NULL,
`updated` datetime NOT NULL, `updated` datetime NOT NULL,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment