Example #1
0
function vtws_transferOwnership($ownerId, $newOwnerId, $delete = true)
{
    $db = PearDatabase::getInstance();
    //Updating the smcreatorid,smownerid, modifiedby in vtiger_crmentity
    $sql = "UPDATE vtiger_crmentity SET smcreatorid=? WHERE smcreatorid=? AND setype<>?";
    $db->pquery($sql, array($newOwnerId, $ownerId, 'ModComments'));
    $sql = "UPDATE vtiger_crmentity SET smownerid=? WHERE smownerid=? AND setype<>?";
    $db->pquery($sql, array($newOwnerId, $ownerId, 'ModComments'));
    $sql = "update vtiger_crmentity set modifiedby=? where modifiedby=?";
    $db->pquery($sql, array($newOwnerId, $ownerId));
    //deleting from vtiger_tracker
    if ($delete) {
        $sql = "delete from vtiger_tracker where user_id=?";
        $db->pquery($sql, array($ownerId));
    }
    //updating the vtiger_import_maps
    $sql = "update vtiger_import_maps set assigned_user_id=? where assigned_user_id=?";
    $db->pquery($sql, array($newOwnerId, $ownerId));
    if (Vtiger_Utils::CheckTable('vtiger_customerportal_prefs')) {
        $query = 'UPDATE vtiger_customerportal_prefs SET prefvalue = ? WHERE prefkey = ? AND prefvalue = ?';
        $params = array($newOwnerId, 'defaultassignee', $ownerId);
        $db->pquery($query, $params);
        $query = 'UPDATE vtiger_customerportal_prefs SET prefvalue = ? WHERE prefkey = ? AND prefvalue = ?';
        $params = array($newOwnerId, 'userid', $ownerId);
        $db->pquery($query, $params);
    }
    //delete from vtiger_homestuff
    if ($delete) {
        $sql = "delete from vtiger_homestuff where userid=?";
        $db->pquery($sql, array($ownerId));
    }
    //delete from vtiger_users to vtiger_role vtiger_table
    if ($delete) {
        $sql = "delete from vtiger_users2group where userid=?";
        $db->pquery($sql, array($ownerId));
    }
    $sql = "select tabid,fieldname,tablename,columnname from vtiger_field left join " . "vtiger_fieldmodulerel on vtiger_field.fieldid=vtiger_fieldmodulerel.fieldid where uitype " . "in (52,53,77,101) or (uitype=10 and relmodule='Users')";
    $result = $db->pquery($sql, array());
    $it = new SqlResultIterator($db, $result);
    $columnList = array();
    foreach ($it as $row) {
        $column = $row->tablename . '.' . $row->columnname;
        if (!in_array($column, $columnList)) {
            $columnList[] = $column;
            if ($row->columnname == 'smcreatorid' || $row->columnname == 'smownerid') {
                $sql = "update {$row->tablename} set {$row->columnname}=? where {$row->columnname}=? and setype<>?";
                $db->pquery($sql, array($newOwnerId, $ownerId, 'ModComments'));
            } else {
                $sql = "update {$row->tablename} set {$row->columnname}=? where {$row->columnname}=?";
                $db->pquery($sql, array($newOwnerId, $ownerId));
            }
        }
    }
    //update workflow tasks Assigned User from Deleted User to Transfer User
    $newOwnerModel = Users_Record_Model::getInstanceById($newOwnerId, 'Users');
    $ownerModel = Users_Record_Model::getInstanceById($ownerId, 'Users');
    vtws_transferOwnershipForWorkflowTasks($ownerModel, $newOwnerModel);
    vtws_updateWebformsRoundrobinUsersLists($ownerId, $newOwnerId);
}
Example #2
0
 protected function transferOwnership($transferToGroup)
 {
     $db = PearDatabase::getInstance();
     $groupId = $this->getId();
     $transferGroupId = $transferToGroup->getId();
     $query = 'UPDATE vtiger_crmentity SET smownerid=? WHERE smownerid=?';
     $params = array($transferGroupId, $groupId);
     $db->pquery($query, $params);
     if (Vtiger_Utils::CheckTable('vtiger_customerportal_prefs')) {
         $query = 'UPDATE vtiger_customerportal_prefs SET prefvalue = ? WHERE prefkey = ? AND prefvalue = ?';
         $params = array($transferGroupId, 'defaultassignee', $groupId);
         $db->pquery($query, $params);
         $query = 'UPDATE vtiger_customerportal_prefs SET prefvalue = ? WHERE prefkey = ? AND prefvalue = ?';
         $params = array($transferGroupId, 'userid', $groupId);
         $db->pquery($query, $params);
     }
     //update workflow tasks Assigned User from Deleted Group to Transfer Owner
     $newOwnerModel = $this->getInstance($transferGroupId);
     if (!$newOwnerModel) {
         $newOwnerModel = Users_Record_Model::getInstanceById($transferGroupId, 'Users');
     }
     $ownerModel = $this->getInstance($groupId);
     vtws_transferOwnershipForWorkflowTasks($ownerModel, $newOwnerModel);
     vtws_updateWebformsRoundrobinUsersLists($groupId, $transferGroupId);
 }