In iTop, How is it possible to save caller's IP address in tickets (User Request and Incident)
I tried to modify datamodel.itop-tickets.xml in my extension module. I added a field named 'ip' successfully but in <methods>
section I can not get client's IP using $_SERVER['REMOTE_ADDR']
.
<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>
After lots of attempts I finally found the solution :) We must redefine a method of type LifeCycleAction and so I've just redefined ComputeImpactedItems method in both Inciudent and UserRequest classes.
For make it much clear I show one of them here:
<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>