diff --git a/include/class.dept.php b/include/class.dept.php index 8abf4919468b4c9a9df8ec3f3dc84e37187f9c6c..3f623b41100dd4ad715ad0c40d25460546ef8c9b 100644 --- a/include/class.dept.php +++ b/include/class.dept.php @@ -307,6 +307,8 @@ class Dept extends VerySimpleModel { function updateSettings($vars) { $this->updateGroups($vars['groups'] ?: array(), $vars); $this->getConfig()->set('assign_members_only', $vars['assign_members_only']); + $this->path = $this->getFullPath(); + $this->save(); return true; } @@ -380,9 +382,11 @@ class Dept extends VerySimpleModel { } /*----Static functions-------*/ - static function getIdByName($name) { + static function getIdByName($name, $pid=0) { $row = static::objects() - ->filter(array('name'=>$name)) + ->filter(array( + 'name' => $name, + 'pid' => $pid ?: 0)) ->values_flat('id') ->first(); @@ -483,18 +487,21 @@ class Dept extends VerySimpleModel { static function create($vars=false, &$errors=array()) { $dept = parent::create($vars); $dept->created = SqlFunction::NOW(); + return $dept; } static function __create($vars, &$errors) { - $dept = self::create($vars); - $dept->save(); - return $dept; + $dept = self::create(); + $dept->update($vars, $errors); + + return isset($dept->id) ? $dept : null; } function save($refetch=false) { if ($this->dirty) $this->updated = SqlFunction::NOW(); + return parent::save($refetch || $this->dirty); } @@ -506,9 +513,7 @@ class Dept extends VerySimpleModel { if (!$vars['name']) { $errors['name']=__('Name required'); - } elseif (strlen($vars['name'])<4) { - $errors['name']=__('Name is too short.'); - } elseif (($did=static::getIdByName($vars['name'])) + } elseif (($did=static::getIdByName($vars['name'], $vars['pid'])) && (!isset($this->id) || $did!=$this->getId())) { $errors['name']=__('Department already exists'); } @@ -522,14 +527,14 @@ class Dept extends VerySimpleModel { if ($errors) return false; - $this->pid = $vars['pid']; + $this->pid = $vars['pid'] ?: 0; $this->updated = SqlFunction::NOW(); $this->ispublic = isset($vars['ispublic'])?$vars['ispublic']:0; $this->email_id = isset($vars['email_id'])?$vars['email_id']:0; $this->tpl_id = isset($vars['tpl_id'])?$vars['tpl_id']:0; $this->sla_id = isset($vars['sla_id'])?$vars['sla_id']:0; $this->autoresp_email_id = isset($vars['autoresp_email_id'])?$vars['autoresp_email_id']:0; - $this->manager_id = $vars['manager_id']?$vars['manager_id']:0; + $this->manager_id = $vars['manager_id'] ?: 0; $this->name = Format::striptags($vars['name']); $this->signature = Format::sanitize($vars['signature']); $this->group_membership = $vars['group_membership']; diff --git a/include/upgrader/streams/core.sig b/include/upgrader/streams/core.sig index 2babc79c7807d3a2b91a74368bd2de1aca285578..209fca107da75265e35d6cd2f12d71d5e89213a5 100644 --- a/include/upgrader/streams/core.sig +++ b/include/upgrader/streams/core.sig @@ -1 +1 @@ -7337bc63d257cd49ddbebc1eecbd394e +5cd0a25a54fd27ed95f00d62edda4c6d diff --git a/include/upgrader/streams/core/36f6b328-7337bc63.cleanup.sql b/include/upgrader/streams/core/36f6b328-5cd0a25a.cleanup.sql similarity index 100% rename from include/upgrader/streams/core/36f6b328-7337bc63.cleanup.sql rename to include/upgrader/streams/core/36f6b328-5cd0a25a.cleanup.sql diff --git a/include/upgrader/streams/core/36f6b328-7337bc63.patch.sql b/include/upgrader/streams/core/36f6b328-5cd0a25a.patch.sql similarity index 97% rename from include/upgrader/streams/core/36f6b328-7337bc63.patch.sql rename to include/upgrader/streams/core/36f6b328-5cd0a25a.patch.sql index f42351852ae42634d301f56f258a015e1536d44a..d0e5015f0a5d9ae28f66a827c6d5a3d2ead2f79d 100644 --- a/include/upgrader/streams/core/36f6b328-7337bc63.patch.sql +++ b/include/upgrader/streams/core/36f6b328-5cd0a25a.patch.sql @@ -110,9 +110,12 @@ UPDATE `%TABLE_PREFIX%config` SET `key` = 'ticket_sequence_id' WHERE `key` = 'sequence_id' AND `namespace` = 'core'; +-- add parent department support ALTER TABLE `%TABLE_PREFIX%department` + DROP INDEX `name`, ADD `pid` int(11) unsigned default NULL AFTER `id`, - ADD `path` varchar(128) NOT NULL default '/' AFTER `message_auto_response`; + ADD `path` varchar(128) NOT NULL default '/' AFTER `message_auto_response`, + ADD UNIQUE `name` ( `name` , `pid` ); UPDATE `%TABLE_PREFIX%department` SET `path` = CONCAT('/', id, '/'); diff --git a/include/upgrader/streams/core/36f6b328-7337bc63.task.php b/include/upgrader/streams/core/36f6b328-5cd0a25a.task.php similarity index 100% rename from include/upgrader/streams/core/36f6b328-7337bc63.task.php rename to include/upgrader/streams/core/36f6b328-5cd0a25a.task.php diff --git a/scp/departments.php b/scp/departments.php index db9b259bf27539cd23f97da833dad5d926646a21..d90a1953e439fd5308f870b4336349ff0fd07e48 100644 --- a/scp/departments.php +++ b/scp/departments.php @@ -33,8 +33,8 @@ if($_POST){ } break; case 'create': - $dept = Dept::create(); - if(($dept->update($_POST,$errors))){ + $_dept = Dept::create(); + if(($_dept->update($_POST,$errors))){ $msg=sprintf(__('Successfully added "%s"'),Format::htmlchars($_POST['name'])); $_REQUEST['a']=null; }elseif(!$errors['err']){ diff --git a/scp/tickets.php b/scp/tickets.php index f5019127bbec0e3cbe2c2d587b1ec16ea74e0b82..2db8701c117766449d4f23e811bf4406e2bbd99a 100644 --- a/scp/tickets.php +++ b/scp/tickets.php @@ -129,7 +129,8 @@ if($_POST && !$errors): //If no errors - them attempt the transfer. if(!$errors && $ticket->transfer($_POST['deptId'], $_POST['transfer_comments'])) { - $msg = sprintf(__('Ticket transferred successfully to %s'),$ticket->getDeptName()); + $msg = sprintf(__('Ticket transferred successfully to %s'), + $ticket->getDept()->getFullName()); //Check to make sure the staff still has access to the ticket if(!$ticket->checkStaffAccess($thisstaff)) $ticket=null; diff --git a/setup/inc/streams/core/install-mysql.sql b/setup/inc/streams/core/install-mysql.sql index 9370d7bc1a1b7dc716262d40a35372ea2ff3d744..124b65afbb7316e046f27a427bd569048d25a17f 100644 --- a/setup/inc/streams/core/install-mysql.sql +++ b/setup/inc/streams/core/install-mysql.sql @@ -216,7 +216,7 @@ CREATE TABLE `%TABLE_PREFIX%department` ( `updated` datetime NOT NULL, `created` datetime NOT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `name` (`name`), + UNIQUE KEY `name` (`name`, `pid`), KEY `manager_id` (`manager_id`), KEY `autoresp_email_id` (`autoresp_email_id`), KEY `tpl_id` (`tpl_id`)