iTop - 在票证中获取来电者的IP



在iTop中,如何在票证中保存呼叫者的IP地址(用户请求和事件(

我尝试在我的扩展模块中修改datamodel.itop-tickets.xml。我成功添加了一个名为"ip"的字段,但在<methods>部分中我无法使用$_SERVER['REMOTE_ADDR']获取客户的 IP。

<methods>
<method id="DBInsertNoReload"  _delta="redefine">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[
public function DBInsertNoReload()
{
$oMutex = new iTopMutex('ticket_insert');
$oMutex->Lock();
$iNextId = MetaModel::GetNextKey(get_class($this));
$sRef = $this->MakeTicketRef($iNextId);
$this->Set('ref', $sRef);
$iKey = parent::DBInsertNoReload();
$oMutex->Unlock();
return $iKey;
$this->Set('ip', $_SERVER['REMOTE_ADDR'] );
}
]]></code>
</method>               
</methods>

还有另一种选择,在 itop 海关扩展中,您可以包含另一个数据模型。(您可以使用 XML 或 PHP 数据模型(。 因此,您必须创建一个新的 php 文件并编写您想要的类以扩展数据模型。您必须使用 : https://www.combodo.com/documentation/api-ref-extensions/packages/Extensibility.html 扩展它们

如果您使用接口"iApplicationObjectExtension",则可以使用方法OnDBInsert在对象中设置其他字段/

例如

Class YourClassName implements iApplicationObjectExtension {
public function OnIsModified($oObject){}
public function OnCheckToWrite($oObject){}
public function OnCheckToDelete($oObject){}
public function OnDBUpdate($oObject, $oChange = null){}
public function OnDBDelete($oObject, $oChange = null){}
public function OnDBInsert($oObject, $oChange = null) {
if ($oObject instanceof UserRequest) {
// Do what you want with $oObject
$oObject->DBUpdate(); // Update object
}
}
}

经过多次尝试,我终于找到了解决方案:) 我们必须重新定义LifeCycleAction类型的方法,因此我刚刚在InciudentUserRequest类中重新定义了ComputeImpactedItems方法。

为了更清楚地说明,我在这里展示其中之一:

<class id="Incident">
<methods>
<method id="ComputeImpactedItems"  _delta="redefine">
<static>false</static>
<access>public</access>
<type>LifecycleAction</type>
<code><![CDATA[ public function ComputeImpactedItems()
{
// This method is kept for backward compatibility
// in case a delta redefines it, but you may call
// UpdateImpactedItems directly
$this->UpdateImpactedItems();
// This line is added by this exstension for saving caller's ip
$this->Set('ip', $_SERVER['REMOTE_ADDR']);
}]]></code>
</method>
</methods>
</class>

最新更新