diff --git a/module/group/model.php b/module/group/model.php index 056d98b5d7..9f7feb6565 100644 --- a/module/group/model.php +++ b/module/group/model.php @@ -291,8 +291,24 @@ class groupModel extends model $actions['actions'] = $dynamic; /* If not select any projects or products, set it empty. */ - if(isset($actions['products'][0]) && !$actions['products'][0]) $actions['products'] = array(); - if(isset($actions['projects'][0]) && !$actions['projects'][0]) $actions['projects'] = array(); + if(isset($actions['products'])) + { + $isEmpty = true; + foreach($actions['products'] as $productID) + { + if(!empty($productID)) $isEmpty = false; + } + if($isEmpty) unset($actions['products']); + } + if(isset($actions['projects'])) + { + $isEmpty = true; + foreach($actions['projects'] as $projectID) + { + if(!empty($projectID)) $isEmpty = false; + } + if($isEmpty) unset($actions['projects']); + } $actions = empty($actions) ? '' : json_encode($actions); $this->dao->update(TABLE_GROUP)->set('acl')->eq($actions)->where('id')->eq($groupID)->exec(); diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 6c827a6e4a..d8a845d234 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -531,6 +531,11 @@ class upgradeModel extends model $this->saveLogs('Execute 11_6_4'); $this->execSQL($this->getUpgradeFile('11.6.4')); $this->appendExec('11_6_4'); + case '11_6_5': + $this->saveLogs('Execute 11_6_5'); + $this->execSQL($this->getUpgradeFile('11.6.5')); + $this->fixGroupAcl(); + $this->appendExec('11_6_5'); } $this->deletePatch(); @@ -3370,6 +3375,47 @@ class upgradeModel extends model return true; } + /** + * Fix group acl. + * + * @access public + * @return bool + */ + public function fixGroupAcl() + { + $groups = $this->dao->select('*')->from(TABLE_GROUP)->fetchAll(); + foreach($groups as $group) + { + if(empty($group->acl)) continue; + + $acl = json_decode($group->acl, true); + if(isset($acl['products'])) + { + $isEmpty = true; + foreach($acl['products'] as $productID) + { + if(!empty($productID)) $isEmpty = false; + } + if($isEmpty) unset($acl['products']); + } + + if(isset($acl['projects'])) + { + $isEmpty = true; + foreach($acl['projects'] as $projectID) + { + if(!empty($projectID)) $isEmpty = false; + } + if($isEmpty) unset($acl['projects']); + } + + $acl = json_encode($acl); + $this->dao->update(TABLE_GROUP)->set('acl')->eq($acl)->where('id')->eq($group->id)->exec(); + } + + return true; + } + /** * Save Logs. *