Example #1
0
function wsapp_get($key, $module, $token, $user)
{
    $name = wsapp_getApplicationName($key);
    $handlerDetails = wsapp_getHandler($name);
    require_once $handlerDetails['handlerpath'];
    $handler = new $handlerDetails['handlerclass']($key);
    return $handler->get($module, $token, $user);
}
Example #2
0
function wsapp_put($key, $element, $user)
{
    $name = wsapp_getApplicationName($key);
    $handlerDetails = wsapp_getHandler($name);
    require_once $handlerDetails['handlerpath'];
    $handler = new $handlerDetails['handlerclass']($key);
    return $handler->put($element, $user);
}
Example #3
0
 function getDestinationHandleDetails()
 {
     return wsapp_getHandler('Google_vtigerHandler');
 }
Example #4
0
 function getDestinationHandleDetails()
 {
     return wsapp_getHandler('vtigerCRM');
 }
Example #5
0
	/**
	 * Share the Create/Update/Delete state information
	 */
	function get($key, $module, $token, $user) {
		$db = PearDatabase::getInstance();
		$appid = $this->appid_with_key($key);
		if (empty($appid)) {
			throw new WebServiceException('WSAPP04',"Access restricted to app");
		}
		$clientApplicationSyncType = wsapp_getAppSyncType($key);
        //hardcoded since the destination handler will be vtigerCRM
        $serverKey = wsapp_getAppKey("vtigerCRM");
        $handlerDetails  = wsapp_getHandler('vtigerCRM');
        require_once $handlerDetails['handlerpath'];
        $this->destHandler = new $handlerDetails['handlerclass']($serverKey);
		$this->destHandler->setClientSyncType($clientApplicationSyncType);
        $result = $this->destHandler->get($module, $token,$user);
        // Lookup Ids
		$updatedIds = array(); $deletedIds = array();
		foreach($result['updated'] as $u){
            $updatedIds[] = $u['id'];
        }
		foreach($result['deleted'] as $d){
            $deletedIds[] = $d;
        }
        $syncServerDeleteIds = $this->getQueueDeleteRecord($appid);
        foreach($syncServerDeleteIds as $deleteServerId){
            $deletedIds[] = $deleteServerId;
        }

		$updateDeleteCommonIds = array_values(array_intersect($updatedIds,$deletedIds));
		//if the record exist in both the update and delete , then send record as update
		// and unset the id from deleted list
		$deletedIds = array_diff($deletedIds,$updateDeleteCommonIds);

        $updatedLookupIds = $this->idmap_get_clientmap($appid, $updatedIds);
		$deletedLookupIds = $this->idmap_get_clientmap($appid, $deletedIds);
		$filteredCreates = array(); $filteredUpdates = array();
        foreach ($result['updated'] as $u) {
            if(in_array($u['id'],$updatedIds)){
                if (isset($updatedLookupIds[$u['id']]) && ($u['modifiedtime'] > $updatedLookupIds[$u['id']]['servermodifiedtime'])) {
					$u['_id'] = $u['id'];
                    $u['id'] = $updatedLookupIds[$u['id']]['clientid']; // Replace serverid with clientid
                    $u['_modifiedtime'] = $u['modifiedtime'];
                    $filteredUpdates[] = $u;
                    } else if (empty($updatedLookupIds[$u['id']])){
                    $u['_id'] = $u['id'];// Rename the id key
                    $u['_modifiedtime'] = $u['modifiedtime'];
                    unset($u['id']);
                    $filteredCreates[] = $u;
                }
            }
		}
	
		$filteredDeletes = array();
		foreach ($deletedIds as $d) {
          	if (isset($deletedLookupIds[$d])) {
				$filteredDeletes[] = $deletedLookupIds[$d]['clientid']; // Replace serverid with clientid;
			}
		}
	
		$result['created'] = $filteredCreates;
		$result['updated'] = $filteredUpdates;
		$result['deleted'] = $filteredDeletes;
        return $result;
	}