diff --git a/include/class.sla.php b/include/class.sla.php index c1b4ead65df6f5d1ec796f7655e1d0a4322519f1..66e06d94cf188098e1f2b92dcff636283e5e9a8f 100644 --- a/include/class.sla.php +++ b/include/class.sla.php @@ -21,7 +21,10 @@ implements TemplateVariable { 'pk' => array('id'), ); - //TODO: Use flags + const FLAG_ACTIVE = 0x0001; + const FLAG_ESCALATE = 0x0002; + const FLAG_NOALERTS = 0x0004; + const FLAG_TRANSIENT = 0x0008; var $_config; @@ -37,19 +40,13 @@ implements TemplateVariable { return $this->grace_period; } - function getHashtable() { - $this->getHashtable(); - } - function getInfo() { - return array_merge($this->getConfig()->getInfo(), $this->ht); - } - - function getConfig() { - if (!isset($this->_config)) - $this->_config = new SlaConfig($this->getId()); - - return $this->_config; + $base = $this->ht; + $base['isactive'] = $this->flags & self::FLAG_ACTIVE; + $base['disable_overdue_alerts'] = $this->flags & self::FLAG_NOALERTS; + $base['enable_priority_escalation'] = $this->flags & self::FLAG_ESCALATE; + $base['transient'] = $this->flags & self::FLAG_TRANSIENT; + return $base; } function getCreateDate() { @@ -61,15 +58,15 @@ implements TemplateVariable { } function isActive() { - return ($this->isactive); + return $this->flags & self::FLAG_ACTIVE; } function isTransient() { - return $this->getConfig()->get('transient', false); + return $this->flags & self::FLAG_TRANSIENT; } function sendAlerts() { - return $this->disable_overdue_alerts; + return 0 === ($this->flags & self::FLAG_NOALERTS); } function alertOnOverdue() { @@ -77,7 +74,7 @@ implements TemplateVariable { } function priorityEscalation() { - return ($this->enable_priority_escalation); + return $this->flags && self::FLAG_ESCALATE; } function getTranslateTag($subtag) { @@ -123,17 +120,17 @@ implements TemplateVariable { if ($errors) return false; - $this->isactive = $vars['isactive']; $this->name = $vars['name']; $this->grace_period = $vars['grace_period']; - $this->disable_overdue_alerts = isset($vars['disable_overdue_alerts']) ? 1 : 0; - $this->enable_priority_escalation = isset($vars['enable_priority_escalation'])? 1: 0; $this->notes = Format::sanitize($vars['notes']); + $this->flags = + ($vars['isactive'] ? self::FLAG_ACTIVE : 0) + | (isset($vars['disable_overdue_alerts']) ? self::FLAG_NOALERTS : 0) + | (isset($vars['enable_priority_escalation']) ? self::FLAG_ESCALATE : 0) + | (isset($vars['transient']) ? self::FLAG_TRANSIENT : 0); - if ($this->save()) { - $this->getConfig()->set('transient', isset($vars['transient']) ? 1 : 0); + if ($this->save()) return true; - } if (isset($this->id)) { $errors['err']=sprintf(__('Unable to update %s.'), __('this SLA plan')) @@ -176,10 +173,11 @@ implements TemplateVariable { $slas = self::objects() ->order_by('name') - ->values_flat('id', 'name', 'isactive', 'grace_period'); + ->values_flat('id', 'name', 'flags', 'grace_period'); $entries = array(); foreach ($slas as $row) { + $row[2] = $row[2] & self::FLAG_ACTIVE; $entries[$row[0]] = sprintf(__('%s (%d hours - %s)' /* Tokens are <name> (<#> hours - <Active|Disabled>) */), self::getLocalById($row[0], 'name', $row[1]), @@ -211,13 +209,4 @@ implements TemplateVariable { return $sla; } } - -require_once(INCLUDE_DIR.'class.config.php'); -class SlaConfig extends Config { - var $table = CONFIG_TABLE; - - function __construct($id) { - parent::__construct("sla.$id"); - } -} ?> diff --git a/include/i18n/en_US/sla.yaml b/include/i18n/en_US/sla.yaml index 3b91325475edfed4025cfc9e95bdcd9e78fe12c4..4bbcfae98c8921eb014ae3d8e3d58e465efe2617 100644 --- a/include/i18n/en_US/sla.yaml +++ b/include/i18n/en_US/sla.yaml @@ -3,20 +3,21 @@ # # Fields: # id - (int:optional) id number in the database -# isactive - (bool:0|1) true of false if the SLA should initially be active -# enable_priority_escalation - (bool:0|1) true or false if the SLA should +# flags - (int:bitmask) +# isactive - (flag:1) true of false if the SLA should initially be active +# enable_priority_escalation - (flag:2) true or false if the SLA should # cause the ticket priority to be escalated when it is marked overdue -# disable_overdue_alerts - (bool:0|1) - true or false if the overdue alert +# disable_overdue_alerts - (flag:4) - true or false if the overdue alert # emails should _not_ go out for tickets assigned to this SLA +# transient - (flag:8) - true if the SLA should change when changing +# department or help topic. # grace_period - (int) number or hours after the ticket is opened before it # is marked overdue # name - (string) descriptive name of the SLA # notes - (string) administrative notes (viewable internally only) --- - id: 1 - isactive: 1 - enable_priority_escalation: 1 - disable_overdue_alert: 0 + flags: 3 grace_period: 48 name: Default SLA notes: | diff --git a/include/upgrader/streams/core/9143a511-00000000.cleanup.sql b/include/upgrader/streams/core/9143a511-00000000.cleanup.sql index 1ebb607cac3537e1949a77f7e6890fd88723fbf5..0243fc683894c330a314fff410932d7ded0675c5 100644 --- a/include/upgrader/streams/core/9143a511-00000000.cleanup.sql +++ b/include/upgrader/streams/core/9143a511-00000000.cleanup.sql @@ -41,9 +41,20 @@ SET @s = (SELECT IF( PREPARE stmt FROM @s; EXECUTE stmt; +-- Retire %team.[flag fields] ALTER TABLE `%TABLE_PREFIX%team` DROP `isenabled`, DROP `noalerts`; +-- Retire %dept.[flag fields] DELETE FROM `%TABLE_PREFIX%config` WHERE `key`='assign_members_only' AND `namespace` LIKE 'dept.%'; + +-- Retire %sla.[flag fields] +ALTER TABLE `%TABLE_PREFIX%sla` + DROP `isactive`, + DROP `enable_priority_escalation`, + DROP `disable_overdue_alerts`; + +DELETE FROM `%TABLE_PREFIX%config` +WHERE `key`='transient' AND `namespace` LIKE 'sla.%'; diff --git a/include/upgrader/streams/core/9143a511-00000000.patch.sql b/include/upgrader/streams/core/9143a511-00000000.patch.sql index f723319f8e612069d3b0f0df8605fcc90ef8a51e..8c0cae5c738273235569702710e4a293b2af40b6 100644 --- a/include/upgrader/streams/core/9143a511-00000000.patch.sql +++ b/include/upgrader/streams/core/9143a511-00000000.patch.sql @@ -63,6 +63,19 @@ UPDATE `%TABLE_PREFIX%department` A1 ON (`config`.`namespace` = CONCAT('dept.', A1.`id`) AND `config`.`key` = 'assign_members_only') SET A1.`flags` = 1 WHERE `config`.`value` != ''; +-- Migrate %config[namespace=sla.x, key=transient] +ALTER TABLE `%TABLE_PREFIX%sla` + ADD `flags` int(10) unsigned NOT NULL default 3 AFTER `id`; + +UPDATE `%TABLE_PREFIX%sla` A1 + SET A1.`flags` = + (CASE WHEN A1.`isactive` THEN 1 ELSE 0 END) + | (CASE WHEN A1.`enable_priority_escalation` THEN 2 ELSE 0 END) + | (CASE WHEN A1.`disable_overdue_alerts` THEN 4 ELSE 0 END) + | (CASE WHEN (SELECT `value` FROM `%TABLE_PREFIX%config` `config` + WHERE`config`.`namespace` = CONCAT('sla.', A1.`id`) AND `config`.`key` = 'transient') + = '1' THEN 8 ELSE 0 END); + -- Finished with patch UPDATE `%TABLE_PREFIX%config` SET `value` = '00000000000000000000000000000000' diff --git a/setup/inc/streams/core/install-mysql.sql b/setup/inc/streams/core/install-mysql.sql index 8f9fe2311b7b2d4bbc7eb114370ad9faee76c84e..b565e70cbf538d7a091eff23a6c9ecf0f1c974c7 100644 --- a/setup/inc/streams/core/install-mysql.sql +++ b/setup/inc/streams/core/install-mysql.sql @@ -83,9 +83,7 @@ CREATE TABLE `%TABLE_PREFIX%sequence` ( DROP TABLE IF EXISTS `%TABLE_PREFIX%sla`; CREATE TABLE `%TABLE_PREFIX%sla` ( `id` int(11) unsigned NOT NULL auto_increment, - `isactive` tinyint(1) unsigned NOT NULL default '1', - `enable_priority_escalation` tinyint(1) unsigned NOT NULL default '1', - `disable_overdue_alerts` tinyint(1) unsigned NOT NULL default '0', + `flags` int(10) unsigned NOT NULL default 3, `grace_period` int(10) unsigned NOT NULL default '0', `name` varchar(64) NOT NULL default '', `notes` text,