diff --git a/packages/vtiger/optional/Google.zip b/packages/vtiger/optional/Google.zip index 23cc620f01c5d57a8f4cc9430898022c150dff12..3d1ae659a25bbfe011a50e6316f84c8e22846658 100644 Binary files a/packages/vtiger/optional/Google.zip and b/packages/vtiger/optional/Google.zip differ diff --git a/pkg/vtiger/modules/Google/modules/Google/handlers/Vtiger.php b/pkg/vtiger/modules/Google/modules/Google/handlers/Vtiger.php new file mode 100644 index 0000000000000000000000000000000000000000..680b6f8473ee572d230e41d6fa4d9dab8ad33da3 --- /dev/null +++ b/pkg/vtiger/modules/Google/modules/Google/handlers/Vtiger.php @@ -0,0 +1,123 @@ +<?php +/*+*********************************************************************************** + * The contents of this file are subject to the vtiger CRM Public License Version 1.0 + * ("License"); You may not use this file except in compliance with the License + * The Original Code is: vtiger CRM Open Source + * The Initial Developer of the Original Code is vtiger. + * Portions created by vtiger are Copyright (C) vtiger. + * All Rights Reserved. + *************************************************************************************/ +vimport('~~/modules/WSAPP/Handlers/vtigerCRMHandler.php'); +vimport('~~/include/Webservices/Utils.php'); +class Google_Vtiger_Handler extends vtigerCRMHandler { + public function put($recordDetails, $user) { + global $current_user; + $current_user = $user; + $this->user = $user; + $recordDetails = $this->syncToNativeFormat($recordDetails); + $createdRecords = $recordDetails['created']; + $updatedRecords = $recordDetails['updated']; + $deletedRecords = $recordDetails['deleted']; + + if (count($createdRecords) > 0) { + $createdRecords = $this->translateReferenceFieldNamesToIds($createdRecords, $user); + $createdRecords = $this->fillNonExistingMandatoryPicklistValues($createdRecords); + $createdRecords = $this->fillMandatoryFields($createdRecords, $user); + } + foreach ($createdRecords as $index => $record) { + try { + $createdRecords[$index] = vtws_create($record['module'], $record, $this->user); + } catch (Exception $ex) { + unset($createdRecords[$index]); + continue; + } + } + + if (count($updatedRecords) > 0) { + $updatedRecords = $this->translateReferenceFieldNamesToIds($updatedRecords, $user); + } + + $crmIds = array(); + foreach ($updatedRecords as $index => $record) { + $webserviceRecordId = $record["id"]; + $recordIdComp = vtws_getIdComponents($webserviceRecordId); + $crmIds[] = $recordIdComp[1]; + } + $assignedRecordIds = array(); + if ($this->isClientUserSyncType()|| $this->isClientUserAndGroupSyncType()) { + $assignedRecordIds = wsapp_checkIfRecordsAssignToUser($crmIds, $this->user->id); + // To check if the record assigned to group + if($this->isClientUserAndGroupSyncType()){ + $groupIds = $this->getGroupIds($this->user->id); + foreach ($groupIds as $group) { + $groupRecordId = wsapp_checkIfRecordsAssignToUser($crmIds, $group); + $assignedRecordIds = array_merge($assignedRecordIds, $groupRecordId); + } + } + // End + } + foreach ($updatedRecords as $index => $record) { + $webserviceRecordId = $record["id"]; + //While Updating Vtiger Record, should not update these values for event + if($record['module'] == 'Events') { + unset($record['eventstatus']); + unset($record['activitytype']); + unset($record['duration_hours']); + } + $recordIdComp = vtws_getIdComponents($webserviceRecordId); + try { + if (in_array($recordIdComp[1], $assignedRecordIds)) { + $updatedRecords[$index] = vtws_revise($record, $this->user); + } else if (!$this->isClientUserSyncType()) { + $updatedRecords[$index] = vtws_revise($record, $this->user); + } else { + $this->assignToChangedRecords[$index] = $record; + } + } catch (Exception $e) { + unset($updatedRecords[$index]); + continue; + } + } + $hasDeleteAccess = null; + $deletedCrmIds = array(); + foreach ($deletedRecords as $index => $record) { + $webserviceRecordId = $record; + $recordIdComp = vtws_getIdComponents($webserviceRecordId); + $deletedCrmIds[] = $recordIdComp[1]; + } + $assignedDeletedRecordIds = wsapp_checkIfRecordsAssignToUser($deletedCrmIds, $this->user->id); + + // To get record id's assigned to group of the current user + if($this->isClientUserAndGroupSyncType()){ + foreach ($groupIds as $group) { + $groupRecordId = wsapp_checkIfRecordsAssignToUser($deletedCrmIds, $group); + $assignedDeletedRecordIds = array_merge($assignedDeletedRecordIds, $groupRecordId); + } + } + // End + + foreach ($deletedRecords as $index => $record) { + $idComp = vtws_getIdComponents($record); + if (empty($hasDeleteAccess)) { + $handler = vtws_getModuleHandlerFromId($idComp[0], $this->user); + $meta = $handler->getMeta(); + $hasDeleteAccess = $meta->hasDeleteAccess(); + } + if ($hasDeleteAccess) { + if (in_array($idComp[1], $assignedDeletedRecordIds)) { + try { + vtws_delete($record, $this->user); + } catch (Exception $e) { + unset($deletedRecords[$index]); + continue; + } + } + } + } + + $recordDetails['created'] = $createdRecords; + $recordDetails['updated'] = $updatedRecords; + $recordDetails['deleted'] = $deletedRecords; + return $this->nativeToSyncFormat($recordDetails); + } +} diff --git a/pkg/vtiger/modules/Google/modules/Google/handlers/VtigerSync.php b/pkg/vtiger/modules/Google/modules/Google/handlers/VtigerSync.php new file mode 100644 index 0000000000000000000000000000000000000000..ffe28050ee0ad82725ae82553517792d6dc3b533 --- /dev/null +++ b/pkg/vtiger/modules/Google/modules/Google/handlers/VtigerSync.php @@ -0,0 +1,15 @@ +<?php +/*+*********************************************************************************** + * The contents of this file are subject to the vtiger CRM Public License Version 1.0 + * ("License"); You may not use this file except in compliance with the License + * The Original Code is: vtiger CRM Open Source + * The Initial Developer of the Original Code is vtiger. + * Portions created by vtiger are Copyright (C) vtiger. + * All Rights Reserved. + *************************************************************************************/ +vimport('~~/modules/WSAPP/synclib/handlers/VtigerSyncEventHandler.php'); +class Google_VtigerSync_Handler extends WSAPP_VtigerSyncEventHandler { + public function getSyncServerInstance(){ + return new Google_SyncServer_Controller(); + } +} diff --git a/pkg/vtiger/modules/Google/modules/Google/views/List.php b/pkg/vtiger/modules/Google/modules/Google/views/List.php index 35a52e4793347be8b7679d1244a6c8cc16369e82..5a7a668ab5e00914dc4c0101b419f2eb2b25e292 100644 --- a/pkg/vtiger/modules/Google/modules/Google/views/List.php +++ b/pkg/vtiger/modules/Google/modules/Google/views/List.php @@ -51,7 +51,7 @@ class Google_List_View extends Vtiger_PopupAjax_View { $oauth2 = new Google_Oauth2_Connector($sourceModule); if ($request->has('oauth_verifier')) { try { - $oauth->getHttpClient($sourceModule); + $oauth2->getHttpClient($sourceModule); } catch (Exception $e) { $viewer->assign('DENY', true); }