function handleEvent($eventName, $entityData) { global $current_user; $db = PearDatabase::getInstance(); $moduleName = $entityData->getModuleName(); //Specific to VAS if ($moduleName == 'Users') { return; } //END $recordId = $entityData->getId(); $vtEntityDelta = new VTEntityDelta(); $newEntityData = $vtEntityDelta->getNewEntity($moduleName, $recordId); $recordValues = $newEntityData->getData(); $isAssignToModified = $this->isAssignToChanged($moduleName, $recordId, $current_user); if (!$isAssignToModified) { return; } $wsModuleName = $this->getWsModuleName($moduleName); if ($wsModuleName == "Calendar") { $wsModuleName = vtws_getCalendarEntityType($recordId); } $handler = vtws_getModuleHandlerFromName($wsModuleName, $current_user); $meta = $handler->getMeta(); $recordWsValues = DataTransform::sanitizeData($recordValues, $meta); $syncServer = new SyncServer(); $syncServer->markRecordAsDeleteForAllCleints($recordWsValues); }
function handleEvent($eventName, $data) { global $log, $current_module, $adb, $current_user; $moduleName = $data->getModuleName(); $flag = ModTracker::isTrackingEnabledForModule($moduleName); if ($flag) { if ($eventName == 'vtiger.entity.aftersave.final') { $recordId = $data->getId(); $columnFields = $data->getData(); $vtEntityDelta = new VTEntityDelta(); $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true); $newerEntity = $vtEntityDelta->getNewEntity($moduleName, $recordId); $newerColumnFields = $newerEntity->getData(); if (is_array($delta)) { $inserted = false; foreach ($delta as $fieldName => $values) { if ($fieldName != 'modifiedtime') { if (!$inserted) { $checkRecordPresentResult = $adb->pquery('SELECT * FROM vtiger_modtracker_basic WHERE crmid = ?', array($recordId)); if ($adb->num_rows($checkRecordPresentResult)) { $status = ModTracker::$UPDATED; } else { $status = ModTracker::$CREATED; } // get modified time from database in case it has been hidden in GUI $crmrs = $adb->pquery('select modifiedtime from vtiger_crmentity where crmid=?', array($recordId)); $modtime = $adb->query_result($crmrs, 0, 0); $this->id = $adb->getUniqueId('vtiger_modtracker_basic'); $adb->pquery('INSERT INTO vtiger_modtracker_basic(id, crmid, module, whodid, changedon, status) VALUES(?,?,?,?,?,?)', array($this->id, $recordId, $moduleName, $current_user->id, $modtime, $status)); $inserted = true; } $adb->pquery('INSERT INTO vtiger_modtracker_detail(id,fieldname,prevalue,postvalue) VALUES(?,?,?,?)', array($this->id, $fieldName, $values['oldValue'], $values['currentValue'])); } } } } if ($eventName == 'vtiger.entity.beforedelete') { $recordId = $data->getId(); $columnFields = $data->getData(); $id = $adb->getUniqueId('vtiger_modtracker_basic'); $adb->pquery('INSERT INTO vtiger_modtracker_basic(id, crmid, module, whodid, changedon, status) VALUES(?,?,?,?,?,?)', array($id, $recordId, $moduleName, $current_user->id, date('Y-m-d H:i:s', time()), ModTracker::$DELETED)); } if ($eventName == 'vtiger.entity.afterrestore') { $recordId = $data->getId(); $columnFields = $data->getData(); $id = $adb->getUniqueId('vtiger_modtracker_basic'); $adb->pquery('INSERT INTO vtiger_modtracker_basic(id, crmid, module, whodid, changedon, status) VALUES(?,?,?,?,?,?)', array($id, $recordId, $moduleName, $current_user->id, date('Y-m-d H:i:s', time()), ModTracker::$RESTORED)); } } }
function handleEvent($eventName, $data) { $adb = PearDatabase::getInstance(); $current_user = vglobal('current_user'); $log = vglobal('log'); $current_module = vglobal('current_module'); if (!is_object($data)) { $extendedData = $data; $data = $extendedData['entityData']; } $moduleName = $data->getModuleName(); $flag = ModTracker::isTrackingEnabledForModule($moduleName); if ($flag) { if ($eventName == 'vtiger.entity.aftersave.final') { $recordId = $data->getId(); $columnFields = $data->getData(); $vtEntityDelta = new VTEntityDelta(); $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true); $newerEntity = $vtEntityDelta->getNewEntity($moduleName, $recordId); $newerColumnFields = $newerEntity->getData(); $newerColumnFields = array_change_key_case($newerColumnFields, CASE_LOWER); $delta = array_change_key_case($delta, CASE_LOWER); if (is_array($delta)) { $inserted = false; foreach ($delta as $fieldName => $values) { if ($fieldName != 'modifiedtime') { if (!$inserted) { $checkRecordPresentResult = $adb->pquery('SELECT * FROM vtiger_modtracker_basic WHERE crmid = ?', array($recordId)); if (!$adb->num_rows($checkRecordPresentResult) && $data->isNew()) { $status = ModTracker::$CREATED; } else { $status = ModTracker::$UPDATED; } $this->id = $adb->getUniqueId('vtiger_modtracker_basic'); $adb->insert('vtiger_modtracker_basic', ['id' => $this->id, 'crmid' => $recordId, 'module' => $moduleName, 'whodid' => $current_user->id, 'changedon' => $newerColumnFields['modifiedtime'], 'status' => $status, 'whodidsu' => Vtiger_Session::get('baseUserId')]); $inserted = true; } $adb->pquery('INSERT INTO vtiger_modtracker_detail(id,fieldname,prevalue,postvalue) VALUES(?,?,?,?)', array($this->id, $fieldName, $values['oldValue'], $values['currentValue'])); } } } $isMyRecord = $adb->pquery('SELECT crmid FROM vtiger_crmentity WHERE smownerid <> ? AND crmid = ?', array($current_user->id, $recordId)); if ($adb->num_rows($isMyRecord) > 0) { $adb->pquery("UPDATE vtiger_crmentity SET was_read = 0 WHERE crmid = ?;", array($recordId)); } } if ($eventName == 'vtiger.entity.beforedelete') { $recordId = $data->getId(); $columnFields = $data->getData(); $id = $adb->getUniqueId('vtiger_modtracker_basic'); $adb->insert('vtiger_modtracker_basic', ['id' => $id, 'crmid' => $recordId, 'module' => $moduleName, 'whodid' => $current_user->id, 'changedon' => date('Y-m-d H:i:s', time()), 'status' => ModTracker::$DELETED, 'whodidsu' => Vtiger_Session::get('baseUserId')]); $isMyRecord = $adb->pquery('SELECT crmid FROM vtiger_crmentity WHERE smownerid <> ? AND crmid = ?', array($current_user->id, $recordId)); if ($adb->num_rows($isMyRecord) > 0) { $adb->pquery("UPDATE vtiger_crmentity SET was_read = 0 WHERE crmid = ?;", array($recordId)); } } if ($eventName == 'vtiger.entity.afterrestore') { $recordId = $data->getId(); $columnFields = $data->getData(); $id = $adb->getUniqueId('vtiger_modtracker_basic'); $adb->insert('vtiger_modtracker_basic', ['id' => $id, 'crmid' => $recordId, 'module' => $moduleName, 'whodid' => $current_user->id, 'changedon' => date('Y-m-d H:i:s', time()), 'status' => ModTracker::$RESTORED, 'whodidsu' => Vtiger_Session::get('baseUserId')]); $isMyRecord = $adb->pquery('SELECT crmid FROM vtiger_crmentity WHERE smownerid <> ? AND crmid = ?', array($current_user->id, $recordId)); if ($adb->num_rows($isMyRecord) > 0) { $adb->pquery("UPDATE vtiger_crmentity SET was_read = 0 WHERE crmid = ?;", array($recordId)); } } if ($eventName == 'vtiger.entity.link.after') { ModTracker::linkRelation($extendedData['sourceModule'], $extendedData['sourceRecordId'], $extendedData['destinationModule'], $extendedData['destinationRecordId']); } if ($eventName == 'vtiger.entity.unlink.after') { ModTracker::unLinkRelation($extendedData['sourceModule'], $extendedData['sourceRecordId'], $extendedData['destinationModule'], $extendedData['destinationRecordId']); } } }
function handleEvent($eventName, $data) { global $log, $current_module, $adb, $current_user; $moduleName = $data->getModuleName(); $flag = ModTracker::isTrackingEnabledForModule($moduleName); if ($flag) { if ($eventName == 'vtiger.entity.aftersave.final') { $recordId = $data->getId(); $columnFields = $data->getData(); $vtEntityDelta = new VTEntityDelta(); $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true); $newerEntity = $vtEntityDelta->getNewEntity($moduleName, $recordId); $newerColumnFields = $newerEntity->getData(); $newerColumnFields = array_change_key_case($newerColumnFields, CASE_LOWER); $delta = array_change_key_case($delta, CASE_LOWER); if (is_array($delta)) { $inserted = false; foreach ($delta as $fieldName => $values) { if ($fieldName != 'modifiedtime') { if (!$inserted) { $checkRecordPresentResult = $adb->pquery('SELECT * FROM vtiger_modtracker_basic WHERE crmid = ?', array($recordId)); if (!$adb->num_rows($checkRecordPresentResult) && $data->isNew()) { $status = ModTracker::$CREATED; } else { $status = ModTracker::$UPDATED; } $this->id = $adb->getUniqueId('vtiger_modtracker_basic'); $adb->pquery('INSERT INTO vtiger_modtracker_basic(id, crmid, module, whodid, changedon, status) VALUES(?,?,?,?,?,?)', array($this->id, $recordId, $moduleName, $current_user->id, $newerColumnFields['modifiedtime'], $status)); $inserted = true; } $adb->pquery('INSERT INTO vtiger_modtracker_detail(id,fieldname,prevalue,postvalue) VALUES(?,?,?,?)', array($this->id, $fieldName, $values['oldValue'], $values['currentValue'])); } } } $isMyRecord = $adb->pquery('SELECT crmid FROM vtiger_crmentity WHERE smownerid <> ? AND crmid = ?', array($current_user->id, $recordId)); if ($adb->num_rows($isMyRecord) > 0) { $adb->pquery("UPDATE vtiger_crmentity SET was_read = 0 WHERE crmid = ?;", array($recordId)); } } if ($eventName == 'vtiger.entity.beforedelete') { $recordId = $data->getId(); $columnFields = $data->getData(); $id = $adb->getUniqueId('vtiger_modtracker_basic'); $adb->pquery('INSERT INTO vtiger_modtracker_basic(id, crmid, module, whodid, changedon, status) VALUES(?,?,?,?,?,?)', array($id, $recordId, $moduleName, $current_user->id, date('Y-m-d H:i:s', time()), ModTracker::$DELETED)); $isMyRecord = $adb->pquery('SELECT crmid FROM vtiger_crmentity WHERE smownerid <> ? AND crmid = ?', array($current_user->id, $recordId)); if ($adb->num_rows($isMyRecord) > 0) { $adb->pquery("UPDATE vtiger_crmentity SET was_read = 0 WHERE crmid = ?;", array($recordId)); } } if ($eventName == 'vtiger.entity.afterrestore') { $recordId = $data->getId(); $columnFields = $data->getData(); $id = $adb->getUniqueId('vtiger_modtracker_basic'); $adb->pquery('INSERT INTO vtiger_modtracker_basic(id, crmid, module, whodid, changedon, status) VALUES(?,?,?,?,?,?)', array($id, $recordId, $moduleName, $current_user->id, date('Y-m-d H:i:s', time()), ModTracker::$RESTORED)); $isMyRecord = $adb->pquery('SELECT crmid FROM vtiger_crmentity WHERE smownerid <> ? AND crmid = ?', array($current_user->id, $recordId)); if ($adb->num_rows($isMyRecord) > 0) { $adb->pquery("UPDATE vtiger_crmentity SET was_read = 0 WHERE crmid = ?;", array($recordId)); } } } }