/** * Function to delete the role * @param <Settings_Roles_Record_Model> $transferToRole */ public function delete($transferToRole) { $db = PearDatabase::getInstance(); $roleId = $this->getId(); $transferRoleId = $transferToRole->getId(); $db->pquery('UPDATE vtiger_user2role SET roleid=? WHERE roleid=?', array($transferRoleId, $roleId)); $db->pquery('DELETE FROM vtiger_role2profile WHERE roleid=?', array($roleId)); $db->pquery('DELETE FROM vtiger_group2role WHERE roleid=?', array($roleId)); $db->pquery('DELETE FROM vtiger_group2rs WHERE roleandsubid=?', array($roleId)); //delete handling for sharing rules deleteRoleRelatedSharingRules($roleId); $db->pquery('DELETE FROM vtiger_role WHERE roleid=?', array($roleId)); $allChildren = $this->getAllChildren(); $transferParentRoleSequence = $transferToRole->getParentRoleString(); $currentParentRoleSequence = $this->getParentRoleString(); foreach ($allChildren as $roleId => $roleModel) { $oldChildParentRoleString = $roleModel->getParentRoleString(); $newChildParentRoleString = str_replace($currentParentRoleSequence, $transferParentRoleSequence, $oldChildParentRoleString); $newChildDepth = count(explode('::', $newChildParentRoleString)) - 1; $roleModel->set('depth', $newChildDepth); $roleModel->set('parentrole', $newChildParentRoleString); $roleModel->save(); } }
/** * Function to delete the role * @param <Settings_Roles_Record_Model> $transferToRole */ public function delete($transferToRole) { $db = PearDatabase::getInstance(); $roleId = $this->getId(); $transferRoleId = $transferToRole->getId(); $db->pquery('UPDATE vtiger_user2role SET roleid=? WHERE roleid=?', array($transferRoleId, $roleId)); $db->pquery('DELETE FROM vtiger_role2profile WHERE roleid=?', array($roleId)); $db->pquery('DELETE FROM vtiger_group2role WHERE roleid=?', array($roleId)); $db->pquery('DELETE FROM vtiger_group2rs WHERE roleandsubid=?', array($roleId)); /* $noOfUsers = $db->num_rows($user_result); $array_users = array(); if($noOfUsers > 0) { for($i=0; $i<$noOfUsers; ++$i) { $array_users[] = $db->query_result($user_result, $i, 'userid'); } } */ //delete handling for sharing rules deleteRoleRelatedSharingRules($roleId); $db->pquery('DELETE FROM vtiger_role WHERE roleid=?', array($roleId)); $allChildren = $this->getAllChildren(); $transferParentRoleSequence = $transferToRole->getParentRoleString(); $currentParentRoleSequence = $this->getParentRoleString(); foreach ($allChildren as $roleId => $roleModel) { $oldChildParentRoleString = $roleModel->getParentRoleString(); $newChildParentRoleString = str_replace($currentParentRoleSequence, $transferParentRoleSequence, $oldChildParentRoleString); $newChildDepth = count(explode('::', $newChildParentRoleString)) - 1; $roleModel->set('depth', $newChildDepth); $roleModel->set('parentrole', $newChildParentRoleString); $roleModel->save(); } if (is_array($array_users)) { require_once 'modules/Users/CreateUserPrivilegeFile.php'; foreach ($array_users as $userid) { createUserPrivilegesfile($userid); createUserSharingPrivilegesfile($userid); } } }