Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,18 @@
<extkey_attcode>parent_incident_id</extkey_attcode>
<target_attcode>ref</target_attcode>
</field>
<field id="parent_request_id" xsi:type="AttributeExternalKey">
<filter><![CDATA[SELECT UserRequest WHERE id != :this->id AND status NOT IN ('rejected','resolved','closed')]]></filter>
<dependencies/>
<sql>parent_request_id</sql>
<target_class>UserRequest</target_class>
<is_null_allowed>true</is_null_allowed>
<on_target_delete>DEL_MANUAL</on_target_delete>
</field>
<field id="parent_request_ref" xsi:type="AttributeExternalField">
<extkey_attcode>parent_request_id</extkey_attcode>
<target_attcode>ref</target_attcode>
</field>
<field id="parent_problem_id" xsi:type="AttributeExternalKey">
<sql>parent_problem_id</sql>
<target_class>Problem</target_class>
Expand Down Expand Up @@ -987,6 +999,9 @@
<attribute id="parent_incident_id">
<read_only/>
</attribute>
<attribute id="parent_request_id">
<read_only/>
</attribute>
<attribute id="parent_change_id">
<read_only/>
</attribute>
Expand Down Expand Up @@ -1301,90 +1316,20 @@
<type>LifecycleAction</type>
<code><![CDATA[ public function UpdateChildRequestLog()
{
if (!MetaModel::IsValidClass('UserRequest')) return true; // Do nothing

$oLog = $this->Get('public_log');
$sLogPublic = $oLog->GetModifiedEntry('html');
if ($sLogPublic != '')
{
$sOQL = "SELECT UserRequest WHERE parent_incident_id=:ticket";
$oChildRequestSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL),
array(),
array(
'ticket' => $this->GetKey(),
)
);
while($oRequest = $oChildRequestSet->Fetch())
{
$oRequest->set('public_log',$sLogPublic);
$oRequest->DBUpdate();
}

}
$oLog = $this->Get('private_log');
$sLogPrivate = $oLog->GetModifiedEntry('html');
if ($sLogPrivate != '')
{
$sOQL = "SELECT UserRequest WHERE parent_incident_id=:ticket";
$oChildRequestSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL),
array(),
array(
'ticket' => $this->GetKey(),
)
);
while($oRequest = $oChildRequestSet->Fetch())
{
$oRequest->set('private_log',$sLogPrivate);
$oRequest->DBUpdate();
}
}
return true;

if (MetaModel::IsValidClass('UserRequest')) {
return $this->UpdateChildTicketLog('UserRequest', 'parent_incident_id', ['public_log' => 'public_log', 'private_log' => 'private_log'] );
}
return true;
}]]></code>
</method>

<method id="UpdateChildIncidentLog">
<static>false</static>
<access>public</access>
<type>LifecycleAction</type>
<code><![CDATA[ public function UpdateChildIncidentLog()
{
$oLog = $this->Get('public_log');
$sLogPublic = $oLog->GetModifiedEntry('html');
if ($sLogPublic != '')
{
$sOQL = "SELECT Incident WHERE parent_incident_id=:ticket";
$oChildIncidentSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL),
array(),
array(
'ticket' => $this->GetKey(),
)
);
while($oIncident = $oChildIncidentSet->Fetch())
{
$oIncident->set('public_log',$sLogPublic);
$oIncident->DBUpdate();
}

}
$oLog = $this->Get('private_log');
$sLogPrivate = $oLog->GetModifiedEntry('html');
if ($sLogPrivate != '')
{
$sOQL = "SELECT Incident WHERE parent_incident_id=:ticket";
$oChildIncidentSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL),
array(),
array(
'ticket' => $this->GetKey(),
)
);
while($oIncident = $oChildIncidentSet->Fetch())
{
$oIncident->set('private_log',$sLogPrivate);
$oIncident->DBUpdate();
}
}
return true;

return $this->UpdateChildTicketLog('Incident', 'parent_incident_id', ['public_log' => 'public_log', 'private_log' => 'private_log']);
}]]></code>
</method>
<method id="ComputeImpactedItems">
Expand Down Expand Up @@ -1558,6 +1503,9 @@
<item id="parent_incident_id">
<rank>10</rank>
</item>
<item id="parent_request_id">
<rank>15</rank>
</item>
<item id="parent_problem_id">
<rank>20</rank>
</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
'UI-IncidentManagementOverview-OpenIncidentByStatus' => 'Open incidents by status',
'UI-IncidentManagementOverview-OpenIncidentByAgent' => 'Open incidents by agent',
'UI-IncidentManagementOverview-OpenIncidentByCustomer' => 'Open incidents by customer',
'Class:Incident/Method:UpdateChildTicketWith:public_log' => '<i><u>Public log entry from parent Incident %2$s:</u></i><br><br>',
'Class:Incident/Method:UpdateChildTicketWith:private_log' => '<i>Private log entry from parent Incident [[Incident:%1$s]]:</i><br><br>',
]);

// Dictionnay conventions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1451,44 +1451,17 @@
<access>public</access>
<type>LifecycleAction</type>
<code><![CDATA[ public function UpdateChildRequestLog()
{
return $this->UpdateChildTicketLog('UserRequest', 'parent_request_id', ['public_log' => 'public_log', 'private_log' => 'private_log' ]);
}]]></code>
</method>
<method id="UpdateChildIncidentLog">
<static>false</static>
<access>public</access>
<type>LifecycleAction</type>
<code><![CDATA[ public function UpdateChildIncidentLog()
{
$oLog = $this->Get('public_log');
$sLogPublic = $oLog->GetModifiedEntry('html');
if ($sLogPublic != '')
{
$sOQL = "SELECT UserRequest WHERE parent_request_id=:ticket";
$oChildRequestSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL),
array(),
array(
'ticket' => $this->GetKey(),
)
);
while($oRequest = $oChildRequestSet->Fetch())
{
$oRequest->set('public_log',$sLogPublic);
$oRequest->DBUpdate();
}

}
$oLog = $this->Get('private_log');
$sLogPrivate = $oLog->GetModifiedEntry('html');
if ($sLogPrivate != '')
{
$sOQL = "SELECT UserRequest WHERE parent_request_id=:ticket";
$oChildRequestSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL),
array(),
array(
'ticket' => $this->GetKey(),
)
);
while($oRequest = $oChildRequestSet->Fetch())
{
$oRequest->set('private_log',$sLogPrivate);
$oRequest->DBUpdate();
}
}
return true;

return $this->UpdateChildTicketLog('Incident', 'parent_request_id', ['public_log' => 'public_log', 'private_log' => 'private_log']);
}]]></code>
</method>
<method id="ComputeImpactedItems">
Expand Down Expand Up @@ -1526,6 +1499,7 @@
parent::OnUpdate();
$this->Set('last_update', time());
$this->UpdateChildRequestLog();
$this->UpdateChildIncidentLog();
}]]></code>
</method>
</methods>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
'UI-RequestManagementOverview-OpenRequestByCustomer' => 'Open requests by customer',
'Class:UserRequest:KnownErrorList' => 'Known Errors',
'Class:UserRequest:KnownErrorList+' => 'Known Errors related to Functional CI linked to the current ticket',
'Class:UserRequest/Method:UpdateChildTicketWith:public_log' => '<i><u>Public log entry from parent User Request %2$s:</u></i><br><br>',
'Class:UserRequest/Method:UpdateChildTicketWith:private_log' => '<i>Private log entry from parent User Request [[UserRequest:%1$s]]:</i><br><br>',
]);

// Dictionnay conventions
Expand Down
40 changes: 2 additions & 38 deletions datamodels/2.x/itop-request-mgmt/datamodel.itop-request-mgmt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1486,44 +1486,8 @@
<access>public</access>
<type>LifecycleAction</type>
<code><![CDATA[ public function UpdateChildRequestLog()
{
$oLog = $this->Get('public_log');
$sLogPublic = $oLog->GetModifiedEntry('html');
if ($sLogPublic != '')
{
$sOQL = "SELECT UserRequest WHERE parent_request_id=:ticket";
$oChildRequestSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL),
array(),
array(
'ticket' => $this->GetKey(),
)
);
while($oRequest = $oChildRequestSet->Fetch())
{
$oRequest->set('public_log',$sLogPublic);
$oRequest->DBUpdate();
}

}
$oLog = $this->Get('private_log');
$sLogPrivate = $oLog->GetModifiedEntry('html');
if ($sLogPrivate != '')
{
$sOQL = "SELECT UserRequest WHERE parent_request_id=:ticket";
$oChildRequestSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL),
array(),
array(
'ticket' => $this->GetKey(),
)
);
while($oRequest = $oChildRequestSet->Fetch())
{
$oRequest->set('private_log',$sLogPrivate);
$oRequest->DBUpdate();
}
}
return true;

{
return $this->UpdateChildTicketLog('UserRequest', 'parent_request_id', ['public_log' => 'public_log', 'private_log' => 'private_log'] );
}]]></code>
</method>
<method id="ComputeImpactedItems">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
'Menu:UserRequest:MyWorkOrders+' => 'All work orders assigned to me',
'Class:Problem:KnownProblemList' => 'Known problems',
'Tickets:Related:OpenIncidents' => 'Open incidents',
'Class:UserRequest/Method:UpdateChildTicketWith:public_log' => '<i><u>Public log entry from parent User Request %2$s:</u></i><br><br>',
'Class:UserRequest/Method:UpdateChildTicketWith:private_log' => '<i>Private log entry from parent User Request [[UserRequest:%1$s]]:</i><br><br>',
]);

// Dictionnay conventions
Expand Down
57 changes: 57 additions & 0 deletions datamodels/2.x/itop-tickets/datamodel.itop-tickets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,63 @@
}]]></code>
<arguments/>
</method>
<method id="UpdateChildTicketLog">
<comment><![CDATA[/**
*
* Remove the current user associated Person from the contacts_list of this Ticket
* No error if there is no associated Person or if the Person is not in the list
* @return bool Return true
* @param string $sChildClass The class name of the child ticket (e.g. 'Incident', 'UserRequest', etc.)
* @param string $sChildParentAttCode The external key in the child class pointing to the parent ticket (e.g. 'parent_request_id')
* @param array $aLogAttCodes An array of parent caselog attribute codes and for each the corresponding child log attribute code to update (e.g. ['public_log' => 'private_log'])
* So in the example parent.public_log will be copied into each child.private_log
* with a prefix using a dictionary entry like 'Class:<parent_ticket_class>/Method:UpdateChildTicketWith:<caselog_attcode>' with one placeholder %1$s for the parent ticket ref
* resulting in an entry like "Copy of public log entry from parent Incident I-000123: <log entry from parent.public_log>" in the child private_log
*
*/]]>
</comment>
<static>false</static>
<access>public</access>
<type>LifecycleAction</type>
<code><![CDATA[ public function UpdateChildTicketLog($sChildClass, $sChildParentAttCode, $aLogAttCodes)
{
if (!MetaModel::IsValidClass($sChildClass) || (!MetaModel::IsValidAttCode($sChildClass, $sChildParentAttCode))) {
ErrorLog::Debug("Invalid class ($sChildClass) or attribute code ($sChildParentAttCode) provided to UpdateChildTicketLog","DataModel");
return true; // Do nothing
}
$oAttDef = MetaModel::GetAttributeDef($sChildClass, $sChildParentAttCode);
if (!$oAttDef instanceof AttributeExternalKey || ($oAttDef->GetTargetClass() !== get_class($this))) {
ErrorLog::Debug("Attribute $sChildParentAttCode should be an external key of class $sChildClass, pointing to class ".get_class($this),"DataModel");
return true; // Do nothing
}

$sParentClass = get_class($this);
$aChildEntries = [];
foreach ($aLogAttCodes as $sParentAttCode => $sChildAttCode) {
if (MetaModel::IsValidAttCode($sParentClass, $sParentAttCode) && MetaModel::GetAttributeDef($sParentClass, $sParentAttCode) instanceof AttributeCaseLog
&& MetaModel::IsValidAttCode($sChildClass, $sChildAttCode) && MetaModel::GetAttributeDef($sChildClass, $sChildAttCode) instanceof AttributeCaseLog
&& (!utils::IsNullOrEmptyString($this->Get($sParentAttCode)->GetModifiedEntry('html')))) {
$aChildEntries[$sChildAttCode] = Dict::Format('Class:'.$sParentClass.'/Method:UpdateChildTicketWith:'.$sParentAttCode, $this->GetKey(), $this->Get('ref')).$this->Get($sParentAttCode)->GetModifiedEntry('html');
}
}
if ($aChildEntries == []) {
return true; // nothing to update
}

$sOQL = "SELECT $sChildClass WHERE $sChildParentAttCode = :ticket_id";
$oChildSet = new DBObjectSet(DBObjectSearch::FromOQL_AllData($sOQL), [], ['ticket_id' => $this->GetKey()]);
Comment thread
v-dumas marked this conversation as resolved.
while ($oChild = $oChildSet->Fetch()) {
if (is_object($oChild)) { // Seems that empty set, maybe in case of OQL syntax error, can return a single empty object instead of no object at all
foreach ($aChildEntries as $sAttCode => $sEntry) {
$oChild->Set($sAttCode, $sEntry);
}
$oChild->DBUpdate();
}
}
return true;

}]]></code>
</method>
</methods>
<presentation>
<details>
Expand Down
Loading