2017-08-14 66 views
0

在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> 

回答

0

经过大量的尝试,我终于找到了解决办法:) 我们必须重新定义类型LifeCycleAction的方法,所以我刚刚重新定义ComputeImpactedItems方法都InciudentUserRequest类。

为了使它更清楚,我在这里展示他们中的一个:

<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>