* SPDX-License-Identifier: AGPL-3.0-only ************************************/ /* not used at the moment */ class OwnerChangeHandler extends VTEventHandler { public $tablename = 'vtesync_ownerchanges'; function handleEvent($eventName, $entityData) { global $adb, $table_prefix, $current_user; if($eventName == 'vte.entity.aftersave') {//crmv@207852 if ($current_user->id == 0) { return false; } $this->setupTable(); $moduleName = $entityData->getModuleName(); $recordId = $entityData->getId(); if (in_array($moduleName, array('ModNotifications', 'ChangeLog'))) return; $vtEntityDelta = new VTEntityDelta(); $oldOwner = $vtEntityDelta->getOldValue($moduleName, $recordId, 'assigned_user_id'); $newOwner = $vtEntityDelta->getCurrentValue($moduleName, $recordId, 'assigned_user_id'); if ($oldOwner != $newOwner) { $this->insertIntoTable($recordId, $oldOwner, $newOwner); } } } function insertIntoTable($crmid, $oldOwner, $newOwner) { global $adb, $table_prefix; /*$res = $adb->pquery("select crmid from {$this->tablename} where crmid = ?", array($crmid)); if ($res && $adb->num_rows($res) > 0) { // update $adb->pquery("update {$this->tablename} set prev_smownerid = ?, next_smownerid = ?, changetime = ? where crmid = ?", array($oldOwner, $newOwner, date('Y-m-d H:i:s'), $crmid)); } else { // insert $module = getSalesEntityType($crmid); $adb->pquery("insert into {$this->tablename} (crmid, module, prev_smownerid, next_smownerid, changetime) values (?,?,?,?,?)", array($crmid, $module, $oldOwner, $newOwner, date('Y-m-d H:i:s'))); }*/ $module = getSalesEntityType($crmid); $id = $adb->getUniqueId($this->tablename); $adb->pquery("insert into {$this->tablename} (id, crmid, module, prev_smownerid, next_smownerid, changetime) values (?, ?,?,?,?,?)", array($id, $crmid, $module, $oldOwner, $newOwner, date('Y-m-d H:i:s'))); } function setupTable() { global $adb, $table_prefix; $table = $this->tablename; $schema_table = ' ENGINE=InnoDB crmid module prev_smownerid next_smownerid
'; if(!Vtecrm_Utils::CheckTable($table)) { $schema_obj = new adoSchema($adb->database); $schema_obj->ExecuteSchema($schema_obj->ParseSchemaString($schema_table)); } } } ?>