From 3175734b4f7b1aaec503f421434e3daa6b6a7d97 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:18 +0000 Subject: [PATCH 01/40] Adds separate file for 'CMDBChangeOpCreate.php'. --- .../Core/DataModel/CMDBChange/CMDBChangeOpCreate.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpCreate.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpCreate.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpCreate.php From af78129b7db8ea8e0265dc8b0c8b3ad4e9e2db2f Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:18 +0000 Subject: [PATCH 02/40] Adds separate file for 'CMDBChangeOpDelete.php'. --- .../Core/DataModel/CMDBChange/CMDBChangeOpDelete.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpDelete.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpDelete.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpDelete.php From c21169d6a7573c994fe04bf8e89d159139940fcd Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:18 +0000 Subject: [PATCH 03/40] Changes content in separated file 'CMDBChangeOpCreate.php'. --- .../CMDBChange/CMDBChangeOpCreate.php | 1191 +---------------- 1 file changed, 19 insertions(+), 1172 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpCreate.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpCreate.php index 26703dc62..f307bde8b 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpCreate.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpCreate.php @@ -1,1190 +1,37 @@ - /** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object + * Record the creation of an object * * @package iTopORM */ class CMDBChangeOpCreate extends CMDBChangeOp { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() + /** + * @inheritDoc + */ + public static function Init() { $aParams = array ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_create", + "db_key_field" => "id", + "db_finalclass_field" => "", ); MetaModel::Init_Params($aParams); MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list } - /** - * @inheritDoc - */ - public function GetDescription() + /** + * @inheritDoc + */ + public function GetDescription() { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; + return Dict::S('Change:ObjectCreated'); } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} +} \ No newline at end of file From 4993240c199ebb43faf0c19a9fc02d2749053dd7 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:18 +0000 Subject: [PATCH 04/40] Changes content in separated file 'CMDBChangeOpDelete.php'. --- .../CMDBChange/CMDBChangeOpDelete.php | 1194 +---------------- 1 file changed, 23 insertions(+), 1171 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpDelete.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpDelete.php index 26703dc62..23dad7263 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpDelete.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpDelete.php @@ -1,1190 +1,42 @@ - /** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object + * Record the deletion of an object * * @package iTopORM */ class CMDBChangeOpDelete extends CMDBChangeOp { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() + /** + * @inheritDoc + */ + public static function Init() { $aParams = array ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_delete", + "db_key_field" => "id", + "db_finalclass_field" => "", ); MetaModel::Init_Params($aParams); MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list + // Final class of the object (objclass must be set to the root class for efficiency purposes) + MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values" => null, "sql" => "fclass", "default_value" => "", "is_null_allowed" => false, "depends_on" => array()))); + // Last friendly name of the object + MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values" => null, "sql" => "fname", "default_value" => "", "is_null_allowed" => true, "depends_on" => array()))); } - /** - * @inheritDoc - */ - public function GetDescription() + /** + * @inheritDoc + */ + public function GetDescription() { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; + return Dict::S('Change:ObjectDeleted'); } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} +} \ No newline at end of file From 4adefa5cd84652fd968f2e9686806103de85960b Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:19 +0000 Subject: [PATCH 05/40] Adds separate file for 'CMDBChangeOp.php'. --- .../Core/DataModel/CMDBChange/CMDBChangeOp.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOp.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOp.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOp.php From 621b71f6720f34a95cb9ba7090b6497d1dd9c67b Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:19 +0000 Subject: [PATCH 06/40] Adds separate file for 'CMDBChangeOpPlugin.php'. --- .../Core/DataModel/CMDBChange/CMDBChangeOpPlugin.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpPlugin.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpPlugin.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpPlugin.php From 67e288fbc80a04b6088e6b1e48e8dfc63e513918 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:19 +0000 Subject: [PATCH 07/40] Adds separate file for 'CMDBChangeOpSetAttributeBlob.php'. --- .../Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeBlob.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeBlob.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeBlob.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeBlob.php From e05b5192150017f127c6907fe928928e53f1e7a8 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:19 +0000 Subject: [PATCH 08/40] Adds separate file for 'CMDBChangeOpSetAttributeCaseLog.php'. --- .../Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCaseLog.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCaseLog.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCaseLog.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCaseLog.php From d8876eef2477c19793a429fb508458e9b0ba4702 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:19 +0000 Subject: [PATCH 09/40] Changes content in separated file 'CMDBChangeOp.php'. --- .../DataModel/CMDBChange/CMDBChangeOp.php | 1220 +---------------- 1 file changed, 48 insertions(+), 1172 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOp.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOp.php index 26703dc62..6db47390b 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOp.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOp.php @@ -1,1190 +1,66 @@ - /** - * Persistent classes (internal) : cmdbChangeOp and derived + * Various atomic change operations, to be tracked * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - class CMDBChangeOp extends DBObject implements iCMDBChangeOp { - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() + public static function Init() { $aParams = array ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", + "category" => "core/cmdb, grant_by_profile", + "key_type" => "autoincrement", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop", + "db_key_field" => "id", + "db_finalclass_field" => "optype", + 'indexes' => array( + array('objclass', 'objkey'), + ), ); MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); + //MetaModel::Init_InheritAttributes(); + MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values" => null, "sql" => "changeid", "targetclass" => "CMDBChange", "is_null_allowed" => false, "on_target_delete" => DEL_MANUAL, "depends_on" => array()))); + MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values" => null, "extkey_attcode" => "change", "target_attcode" => "date"))); + MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values" => null, "extkey_attcode" => "change", "target_attcode" => "userinfo"))); + MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values" => null, "extkey_attcode" => "change", "target_attcode" => "user_id"))); + MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values" => null, "sql" => "objclass", "default_value" => "", "is_null_allowed" => false, "depends_on" => array()))); + MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values" => null, "class_attcode" => "objclass", "sql" => "objkey", "is_null_allowed" => false, "depends_on" => array()))); - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list + MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details } - /** - * @inheritDoc - */ - public function GetDescription() + /** + * @inheritDoc + */ + public function GetDescription() { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; + return ''; } -} -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} + /** + * Safety net: + * * if change isn't persisted yet, use the current change and persist it if needed + * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) + * + * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed + */ + protected function OnInsert() + { + $iChange = $this->Get('change'); + if (($iChange <= 0) || (is_null($iChange))) { + $oChange = CMDBObject::GetCurrentChange(); + if ($oChange->IsNew()) { + $oChange->DBWrite(); + } + $this->Set('change', $oChange); + } + + parent::OnInsert(); + } +} \ No newline at end of file From e07e435f659db91c0ce83911327ce9444c6d88d0 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:19 +0000 Subject: [PATCH 10/40] Changes content in separated file 'CMDBChangeOpPlugin.php'. --- .../CMDBChange/CMDBChangeOpPlugin.php | 1214 +---------------- 1 file changed, 33 insertions(+), 1181 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpPlugin.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpPlugin.php index 26703dc62..e9933c569 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpPlugin.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpPlugin.php @@ -1,1190 +1,42 @@ - /** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in + * Record an action made by a plug-in * * @package iTopORM */ class CMDBChangeOpPlugin extends CMDBChangeOp { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } + /** + * @inheritDoc + */ + public static function Init() + { + $aParams = array + ( + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_plugin", + "db_key_field" => "id", + "db_finalclass_field" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values" => null, "sql" => "description", "default_value" => '', "is_null_allowed" => false, "depends_on" => array()))); + /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled + MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); + */ + MetaModel::Init_InheritAttributes(); + } - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} + /** + * @inheritDoc + */ + public function GetDescription() + { + return $this->Get('description'); + } +} \ No newline at end of file From de93208fde2dcfd7ca604419c11cd3c5da69b2fd Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:19 +0000 Subject: [PATCH 11/40] Changes content in separated file 'CMDBChangeOpSetAttributeBlob.php'. --- .../CMDBChangeOpSetAttributeBlob.php | 1235 +---------------- 1 file changed, 63 insertions(+), 1172 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeBlob.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeBlob.php index 26703dc62..4fea93cc4 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeBlob.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeBlob.php @@ -1,409 +1,4 @@ - - -/** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} /** * Record the modification of a blob @@ -412,779 +7,75 @@ class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute */ class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); + /** + * @inheritDoc + */ + public static function Init() + { + $aParams = array + ( + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_setatt_data", + "db_key_field" => "id", + "db_finalclass_field" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); + MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on" => array()))); - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } + // Display lists + MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list + } - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); + /** + * @inheritDoc + */ + public function GetDescription() + { + // Temporary, until we change the options of GetDescription() -needs a more global revision + $bIsHtml = true; - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); + $sResult = ''; + $oTargetObjectClass = $this->Get('objclass'); + $oTargetObjectKey = $this->Get('objkey'); + $oTargetSearch = new DBObjectSearch($oTargetObjectClass); + $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); + $oMonoObjectSet = new DBObjectSet($oTargetSearch); + if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { + if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { + $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); + $sAttName = $oAttDef->GetLabel(); + } else { + // The attribute was renamed or removed from the object ? + $sAttName = $this->Get('attcode'); + } + /** @var \ormDocument $oPrevDoc */ + $oPrevDoc = $this->Get('prevdata'); + if ($oPrevDoc->IsEmpty()) { + $sPrevious = ''; + $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); + } else { + $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); + $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); + $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - $sDocView = <<GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); + + $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} + $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); + } + } + return $sResult; + } +} \ No newline at end of file From b7f0915e2fbb6b2e111854905febba8237f341b0 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:20 +0000 Subject: [PATCH 12/40] Adds separate file for 'CMDBChangeOpSetAttributeCustomFields.php'. --- .../DataModel/CMDBChange/CMDBChangeOpSetAttributeCustomFields.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCustomFields.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCustomFields.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCustomFields.php From c9682227b8981c1d61fac10de51569783c195500 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:20 +0000 Subject: [PATCH 13/40] Adds separate file for 'CMDBChangeOpSetAttributeEncrypted.php'. --- .../DataModel/CMDBChange/CMDBChangeOpSetAttributeEncrypted.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeEncrypted.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeEncrypted.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeEncrypted.php From 50feffe40f17ab379cd2fe4895cfc8aca7642587 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:20 +0000 Subject: [PATCH 14/40] Adds separate file for 'CMDBChangeOpSetAttributeHTML.php'. --- .../Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeHTML.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeHTML.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeHTML.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeHTML.php From 5836b2a403a302b27ef45f53af1c740080920a00 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:20 +0000 Subject: [PATCH 15/40] Changes content in separated file 'CMDBChangeOpSetAttributeCaseLog.php'. --- .../CMDBChangeOpSetAttributeCaseLog.php | 1233 +---------------- 1 file changed, 61 insertions(+), 1172 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCaseLog.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCaseLog.php index 26703dc62..eb4785927 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCaseLog.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCaseLog.php @@ -1,811 +1,4 @@ - - -/** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} /** * Record the modification of a caselog (text) @@ -817,374 +10,70 @@ class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText */ class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); + /** + * @inheritDoc + */ + public static function Init() + { + $aParams = array + ( + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_setatt_log", + "db_key_field" => "id", + "db_finalclass_field" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); + MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values" => null, "sql" => "lastentry", "default_value" => 0, "is_null_allowed" => true, "depends_on" => array()))); - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } + // Display lists + MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list + } - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); + /** + * @inheritDoc + */ + public function GetDescription() + { + // Temporary, until we change the options of GetDescription() -needs a more global revision + $bIsHtml = true; - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; + $sResult = ''; + $oTargetObjectClass = $this->Get('objclass'); + $oTargetObjectKey = $this->Get('objkey'); + $oTargetSearch = new DBObjectSearch($oTargetObjectClass); + $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } + $oMonoObjectSet = new DBObjectSet($oTargetSearch); + if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { + if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { + $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); + $sAttName = $oAttDef->GetLabel(); + } else { + // The attribute was renamed or removed from the object ? + $sAttName = $this->Get('attcode'); + } + $oObj = $oMonoObjectSet->Fetch(); + $oCaseLog = $oObj->Get($this->Get('attcode')); + $sTextEntry = '
' . $oCaseLog->GetEntryAt($this->Get('lastentry')) . '
'; - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} + $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); + } + return $sResult; + } -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} + /** + * @param string $sRawText + * + * @return string + */ + protected function ToHtml($sRawText) + { + return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); + } +} \ No newline at end of file From 23a84b786476ff43c32767a2090a0067207afc02 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:20 +0000 Subject: [PATCH 16/40] Changes content in separated file 'CMDBChangeOpSetAttributeCustomFields.php'. --- .../CMDBChangeOpSetAttributeCustomFields.php | 1120 ----------------- 1 file changed, 1120 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCustomFields.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCustomFields.php index 26703dc62..baa09430a 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCustomFields.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeCustomFields.php @@ -1,1124 +1,4 @@ - - -/** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} /** * Record the modification of custom fields From d54abbe4014162a3f33275cd24f2c3f9e2487b81 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:20 +0000 Subject: [PATCH 17/40] Changes content in separated file 'CMDBChangeOpSetAttributeEncrypted.php'. --- .../CMDBChangeOpSetAttributeEncrypted.php | 1229 +---------------- 1 file changed, 50 insertions(+), 1179 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeEncrypted.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeEncrypted.php index 26703dc62..1f983f495 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeEncrypted.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeEncrypted.php @@ -1,1190 +1,61 @@ - - -/** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} /** * Safely record the modification of an encrypted field */ class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); + /** + * @inheritDoc + */ + public static function Init() + { + $aParams = array + ( + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_setatt_encrypted", + "db_key_field" => "id", + "db_finalclass_field" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); + MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed" => true, "allowed_values" => null, "depends_on" => array()))); - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } + // Display lists + MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list + } - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); + /** + * @inheritDoc + */ + public function GetDescription() + { + // Temporary, until we change the options of GetDescription() -needs a more global revision + $bIsHtml = true; - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} + $sResult = ''; + $oTargetObjectClass = $this->Get('objclass'); + $oTargetObjectKey = $this->Get('objkey'); + $oTargetSearch = new DBObjectSearch($oTargetObjectClass); + $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} + $oMonoObjectSet = new DBObjectSet($oTargetSearch); + if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { + if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { + $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); + $sAttName = $oAttDef->GetLabel(); + } else { + // The attribute was renamed or removed from the object ? + $sAttName = $this->Get('attcode'); + } + $sPrevString = $this->GetAsHTML('prevstring'); + $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); + } + return $sResult; + } +} \ No newline at end of file From e49b3c7366bc8eb1ab713e58f3497f0c296ef96f Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:20 +0000 Subject: [PATCH 18/40] Changes content in separated file 'CMDBChangeOpSetAttributeHTML.php'. --- .../CMDBChangeOpSetAttributeHTML.php | 1225 +---------------- 1 file changed, 48 insertions(+), 1177 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeHTML.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeHTML.php index 26703dc62..7a9d8b162 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeHTML.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeHTML.php @@ -1,750 +1,4 @@ - - -/** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} /** * Record the modification of a multiline string (text) containing some HTML markup @@ -753,438 +7,55 @@ class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute */ class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } + /** + * @inheritDoc + */ + public static function Init() + { + $aParams = array + ( + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_setatt_html", + "db_key_field" => "id", + "db_finalclass_field" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); + // Display lists + MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list + } - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} + /** + * @inheritDoc + */ + public function GetDescription() + { + $sResult = ''; + $oTargetObjectClass = $this->Get('objclass'); + $oTargetObjectKey = $this->Get('objkey'); + $oTargetSearch = new DBObjectSearch($oTargetObjectClass); + $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); + $oMonoObjectSet = new DBObjectSet($oTargetSearch); + if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { + if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { + $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); + $sAttName = $oAttDef->GetLabel(); + } else { + // The attribute was renamed or removed from the object ? + $sAttName = $this->Get('attcode'); + } + $sTextView = $this->Get('prevdata'); - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} + //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); + $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); + } + return $sResult; + } +} \ No newline at end of file From 8da798be3bb59499c97444cb4712c36ed684a0cf Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:21 +0000 Subject: [PATCH 19/40] Adds separate file for 'CMDBChangeOpSetAttributeLinksAddRemove.php'. --- .../CMDBChange/CMDBChangeOpSetAttributeLinksAddRemove.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksAddRemove.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksAddRemove.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksAddRemove.php From d9f49a795894a71ddd8f4b50c6f45ccc965f7497 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:21 +0000 Subject: [PATCH 20/40] Adds separate file for 'CMDBChangeOpSetAttributeLinks.php'. --- .../Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinks.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinks.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinks.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinks.php From 47f0302967070b60ce5610a848a794fd96649023 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:21 +0000 Subject: [PATCH 21/40] Adds separate file for 'CMDBChangeOpSetAttributeLinksTune.php'. --- .../DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksTune.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksTune.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksTune.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksTune.php From 2d27794f854b05610289b7b6bfa1630719e7c0dc Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:21 +0000 Subject: [PATCH 22/40] Changes content in separated file 'CMDBChangeOpSetAttributeLinksAddRemove.php'. --- ...CMDBChangeOpSetAttributeLinksAddRemove.php | 1225 +---------------- 1 file changed, 50 insertions(+), 1175 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksAddRemove.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksAddRemove.php index 26703dc62..e40dc3eb1 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksAddRemove.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksAddRemove.php @@ -1,1190 +1,65 @@ - /** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set + * Record added/removed objects from within a link set * * @package iTopORM */ class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); + /** + * @inheritDoc + */ + public static function Init() + { + $aParams = array + ( + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_links_addremove", + "db_key_field" => "id", + "db_finalclass_field" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } + MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values" => new ValueSetEnum('added,removed'), "sql" => "type", "default_value" => "added", "is_null_allowed" => false, "depends_on" => array()))); + } - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); + /** + * @inheritDoc + */ + public function GetDescription() + { + $sResult = ''; + $oTargetObjectClass = $this->Get('objclass'); + $oTargetObjectKey = $this->Get('objkey'); + $oTargetSearch = new DBObjectSearch($oTargetObjectClass); + $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... + $oMonoObjectSet = new DBObjectSet($oTargetSearch); + if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { + if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); + $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); + $sAttName = $oAttDef->GetLabel(); - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); + $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; + $sResult = $sAttName . ' - '; + switch ($this->Get('type')) { + case 'added': + $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); + break; - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} + case 'removed': + $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); + break; + } + } + return $sResult; + } +} \ No newline at end of file From c2479757f49b3f50e3e616164b8fdcac0a92e84d Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:21 +0000 Subject: [PATCH 23/40] Changes content in separated file 'CMDBChangeOpSetAttributeLinks.php'. --- .../CMDBChangeOpSetAttributeLinks.php | 1206 +---------------- 1 file changed, 25 insertions(+), 1181 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinks.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinks.php index 26703dc62..601d41bc8 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinks.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinks.php @@ -1,1190 +1,34 @@ - /** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set + * Record added/removed objects from within a link set * * @package iTopORM */ abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); + /** + * @inheritDoc + */ + public static function Init() + { + $aParams = array + ( + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_links", + "db_key_field" => "id", + "db_finalclass_field" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} + // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) + // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) + MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values" => null, "sql" => "item_class", "default_value" => '', "is_null_allowed" => false, "depends_on" => array()))); + MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values" => null, "sql" => "item_id", "default_value" => 0, "is_null_allowed" => false, "depends_on" => array()))); + } +} \ No newline at end of file From 407b41155cf2b80e2d9942d5a2a3fc84174754ae Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:21 +0000 Subject: [PATCH 24/40] Changes content in separated file 'CMDBChangeOpSetAttributeLinksTune.php'. --- .../CMDBChangeOpSetAttributeLinksTune.php | 1242 +---------------- 1 file changed, 69 insertions(+), 1173 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksTune.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksTune.php index 26703dc62..0c46fb415 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksTune.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLinksTune.php @@ -1,1190 +1,86 @@ - - -/** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} /** * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change + * A single record redirects to the modifications made within the same change * * @package iTopORM */ class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); + /** + * @inheritDoc + */ + public static function Init() + { + $aParams = array + ( + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_links_tune", + "db_key_field" => "id", + "db_finalclass_field" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } + MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values" => null, "sql" => "link_id", "default_value" => 0, "is_null_allowed" => false, "depends_on" => array()))); + } - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); + /** + * @inheritDoc + */ + public function GetDescription() + { + $sResult = ''; + $oTargetObjectClass = $this->Get('objclass'); + $oTargetObjectKey = $this->Get('objkey'); + $oTargetSearch = new DBObjectSearch($oTargetObjectClass); + $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... + $oMonoObjectSet = new DBObjectSet($oTargetSearch); + if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { + if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); + $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); + $sAttName = $oAttDef->GetLabel(); - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); + $sLinkClass = $oAttDef->GetLinkedClass(); + $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } + // Search for changes on the corresponding link + // + $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); + $oSearch->AddCondition('change', $this->Get('change'), '='); + $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); + if (count($aLinkClasses) == 1) { + // Faster than the whole building of the expression below for just one value ?? + $oSearch->AddCondition('objclass', $sLinkClass, '='); + } else { + $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); + $sListExpr = '(' . implode(', ', CMDBSource::Quote($aLinkClasses)) . ')'; + $sOQLCondition = $oField->RenderExpression() . " IN $sListExpr"; + $oNewCondition = Expression::FromOQL($sOQLCondition); + $oSearch->AddConditionExpression($oNewCondition); + } + $oSet = new DBObjectSet($oSearch); + $aChanges = array(); + while ($oChangeOp = $oSet->Fetch()) { + $aChanges[] = $oChangeOp->GetDescription(); + } + if (count($aChanges) == 0) { + return ''; + } - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); + $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} + $sResult = $sAttName . ' - '; + $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); + $sResult .= ' : ' . implode(', ', $aChanges); + } + return $sResult; + } +} \ No newline at end of file From 0c5e032d9aefc5f3b5463cf73ea181bda45b6aad Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:22 +0000 Subject: [PATCH 25/40] Adds separate file for 'CMDBChangeOpSetAttributeLongText.php'. --- .../DataModel/CMDBChange/CMDBChangeOpSetAttributeLongText.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLongText.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLongText.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLongText.php From 079cceb48b0b4df59c2a6aad88d52b18945a44c7 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:22 +0000 Subject: [PATCH 26/40] Adds separate file for 'CMDBChangeOpSetAttributeOneWayPassword.php'. --- .../CMDBChange/CMDBChangeOpSetAttributeOneWayPassword.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeOneWayPassword.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeOneWayPassword.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeOneWayPassword.php From 17b05efbba08ae7e2bedb96b6d12b5fefa8c4062 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:22 +0000 Subject: [PATCH 27/40] Adds separate file for 'CMDBChangeOpSetAttribute.php'. --- .../Core/DataModel/CMDBChange/CMDBChangeOpSetAttribute.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttribute.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttribute.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttribute.php From 36de69b3d06ea418b68b9bc6348d4bad80d0e8ac Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:22 +0000 Subject: [PATCH 28/40] Adds separate file for 'CMDBChangeOpSetAttributeScalar.php'. --- .../Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeScalar.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeScalar.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeScalar.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeScalar.php From 32ce6ac336e71162b17a7a7877e8a60f824e5cfb Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:22 +0000 Subject: [PATCH 29/40] Changes content in separated file 'CMDBChangeOpSetAttributeLongText.php'. --- .../CMDBChangeOpSetAttributeLongText.php | 1226 +---------------- 1 file changed, 49 insertions(+), 1177 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLongText.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLongText.php index 26703dc62..c020a0eed 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLongText.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeLongText.php @@ -1,685 +1,4 @@ - - -/** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} /** * Record the modification of a multiline string (text) @@ -688,503 +7,56 @@ class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute */ class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); + /** + * @inheritDoc + */ + public static function Init() + { + $aParams = array + ( + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_setatt_longtext", + "db_key_field" => "id", + "db_finalclass_field" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); + MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values" => null, "sql" => "prevdata", "default_value" => "", "is_null_allowed" => true, "depends_on" => array()))); - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } + // Display lists + MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list + } - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); + /** + * @inheritDoc + */ + public function GetDescription() + { + $sResult = ''; + $oTargetObjectClass = $this->Get('objclass'); + $oTargetObjectKey = $this->Get('objkey'); + $oTargetSearch = new DBObjectSearch($oTargetObjectClass); + $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; + $oMonoObjectSet = new DBObjectSet($oTargetSearch); + if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { + if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { + $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); + $sAttName = $oAttDef->GetLabel(); + } else { + // The attribute was renamed or removed from the object ? + $sAttName = $this->Get('attcode'); + } + $sTextView = '
' . $this->GetAsHtml('prevdata') . '
'; - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} + //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); + $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); + } + return $sResult; + } +} \ No newline at end of file From b18733ac31fc15b0d40f7d70853942f64d840bb3 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:22 +0000 Subject: [PATCH 30/40] Changes content in separated file 'CMDBChangeOpSetAttributeOneWayPassword.php'. --- ...CMDBChangeOpSetAttributeOneWayPassword.php | 1228 +---------------- 1 file changed, 49 insertions(+), 1179 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeOneWayPassword.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeOneWayPassword.php index 26703dc62..1ae5c9385 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeOneWayPassword.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeOneWayPassword.php @@ -1,1190 +1,60 @@ - - -/** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} /** * Safely record the modification of one way encrypted password */ class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); + /** + * @inheritDoc + */ + public static function Init() + { + $aParams = array + ( + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_setatt_pwd", + "db_key_field" => "id", + "db_finalclass_field" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); + MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed" => true, "allowed_values" => null, "depends_on" => array()))); - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } + // Display lists + MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list + } - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); + /** + * @inheritDoc + */ + public function GetDescription() + { + // Temporary, until we change the options of GetDescription() -needs a more global revision + $bIsHtml = true; - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} + $sResult = ''; + $oTargetObjectClass = $this->Get('objclass'); + $oTargetObjectKey = $this->Get('objkey'); + $oTargetSearch = new DBObjectSearch($oTargetObjectClass); + $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} + $oMonoObjectSet = new DBObjectSet($oTargetSearch); + if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { + if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { + $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); + $sAttName = $oAttDef->GetLabel(); + } else { + // The attribute was renamed or removed from the object ? + $sAttName = $this->Get('attcode'); + } + $sResult = Dict::Format('Change:AttName_Changed', $sAttName); + } + return $sResult; + } +} \ No newline at end of file From 714079df9f35fd1cde418d63e93ddaffc5804743 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:22 +0000 Subject: [PATCH 31/40] Changes content in separated file 'CMDBChangeOpSetAttribute.php'. --- .../CMDBChange/CMDBChangeOpSetAttribute.php | 1188 +---------------- 1 file changed, 16 insertions(+), 1172 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttribute.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttribute.php index 26703dc62..5a3a7b7f5 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttribute.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttribute.php @@ -1,188 +1,4 @@ - - -/** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} /** * Record the modification of an attribute (abstract) @@ -191,1000 +7,28 @@ class CMDBChangeOpDelete extends CMDBChangeOp */ class CMDBChangeOpSetAttribute extends CMDBChangeOp { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() + /** + * @inheritDoc + */ + public static function Init() { $aParams = array ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_setatt", + "db_key_field" => "id", + "db_finalclass_field" => "", ); MetaModel::Init_Params($aParams); MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values" => null, "sql" => "attcode", "default_value" => "", "is_null_allowed" => false, "depends_on" => array()))); // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list + MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} +} \ No newline at end of file From d2ca1d59a6a31a8703175bb4868a47bd133cb95b Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:23 +0000 Subject: [PATCH 32/40] Adds separate file for 'CMDBChangeOpSetAttributeTagSet.php'. --- .../Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeTagSet.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeTagSet.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeTagSet.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeTagSet.php From 9fba36ae2932e7ddd97f45cab2a6602f606733b2 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:23 +0000 Subject: [PATCH 33/40] Adds separate file for 'CMDBChangeOpSetAttributeText.php'. --- .../Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeText.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeText.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeText.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeText.php From fddf54b8630a1110dabed153c8e9320b3a428e45 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:23 +0000 Subject: [PATCH 34/40] Adds separate file for 'CMDBChangeOpSetAttributeURL.php'. --- .../Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeURL.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeURL.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeURL.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeURL.php From 5de3a5331b4533e38fa8a3b7d2da6696cf317035 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:23 +0000 Subject: [PATCH 35/40] Changes content in separated file 'CMDBChangeOpSetAttributeScalar.php'. --- .../CMDBChangeOpSetAttributeScalar.php | 1177 +---------------- 1 file changed, 23 insertions(+), 1154 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeScalar.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeScalar.php index 26703dc62..2a5e28689 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeScalar.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeScalar.php @@ -1,329 +1,51 @@ - /** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute + * Record the modification of a scalar attribute * * @package iTopORM */ class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() + /** + * @inheritDoc + */ + public static function Init() { $aParams = array ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_setatt_scalar", + "db_key_field" => "id", + "db_finalclass_field" => "", ); MetaModel::Init_Params($aParams); MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "default_value" => null, "is_null_allowed" => true, "depends_on" => array()))); + MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values" => null, "sql" => "newvalue", "default_value" => null, "is_null_allowed" => true, "depends_on" => array()))); // Display lists MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list } - /** - * @inheritDoc - */ - public function GetDescription() + /** + * @inheritDoc + */ + public function GetDescription() { $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); + $oTargetObjectClass = $this->Get('objclass'); $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); + $oTargetSearch = new DBObjectSearch($oTargetObjectClass); $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { + if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); @@ -334,857 +56,4 @@ class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute } return $sResult; } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} +} \ No newline at end of file From 500ae157b3b961d42e99b26a151dc968ac84db85 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:23 +0000 Subject: [PATCH 36/40] Changes content in separated file 'CMDBChangeOpSetAttributeTagSet.php'. --- .../CMDBChangeOpSetAttributeTagSet.php | 1170 +---------------- 1 file changed, 20 insertions(+), 1150 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeTagSet.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeTagSet.php index 26703dc62..c0ab1bf0a 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeTagSet.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeTagSet.php @@ -1,280 +1,4 @@ - - -/** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} /** * Record the modification of a tag set attribute @@ -283,36 +7,36 @@ class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute */ class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute { - /** - * @inheritDoc - */ - public static function Init() + /** + * @inheritDoc + */ + public static function Init() { $aParams = array ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_setatt_tagset", + "db_key_field" => "id", + "db_finalclass_field" => "", ); MetaModel::Init_Params($aParams); MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "default_value" => null, "is_null_allowed" => true, "depends_on" => array()))); + MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values" => null, "sql" => "newvalue", "default_value" => null, "is_null_allowed" => true, "depends_on" => array()))); // Display lists MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list } - /** - * @inheritDoc - */ - public function GetDescription() + /** + * @inheritDoc + */ + public function GetDescription() { $sResult = ''; $sTargetObjectClass = $this->Get('objclass'); @@ -322,8 +46,7 @@ class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { + if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); @@ -334,857 +57,4 @@ class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute } return $sResult; } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} +} \ No newline at end of file From ea9c458c9f253d4f04358051a6fbab67d78f016a Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:23 +0000 Subject: [PATCH 37/40] Changes content in separated file 'CMDBChangeOpSetAttributeText.php'. --- .../CMDBChangeOpSetAttributeText.php | 1227 +---------------- 1 file changed, 51 insertions(+), 1176 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeText.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeText.php index 26703dc62..4636917ce 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeText.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeText.php @@ -1,617 +1,4 @@ - - -/** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp -{ - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} /** * Record the modification of a multiline string (text) @@ -620,571 +7,59 @@ class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute */ class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute { - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); + /** + * @inheritDoc + */ + public static function Init() + { + $aParams = array + ( + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_setatt_text", + "db_key_field" => "id", + "db_finalclass_field" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); + MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values" => null, "sql" => "prevdata", "default_value" => "", "is_null_allowed" => true, "depends_on" => array()))); - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } + // Display lists + MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list + } - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); + /** + * @inheritDoc + */ + public function GetDescription() + { + // Temporary, until we change the options of GetDescription() -needs a more global revision + $bIsHtml = true; - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; + $sResult = ''; + $oTargetObjectClass = $this->Get('objclass'); + $oTargetObjectKey = $this->Get('objkey'); + $oTargetSearch = new DBObjectSearch($oTargetObjectClass); + $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} + $oMonoObjectSet = new DBObjectSet($oTargetSearch); + if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { + if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { + $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); + $sAttName = $oAttDef->GetLabel(); + } else { + // The attribute was renamed or removed from the object ? + $sAttName = $this->Get('attcode'); + } + $sTextView = '
' . $this->GetAsHtml('prevdata') . '
'; -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} + //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); + $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); + } + return $sResult; + } +} \ No newline at end of file From 30ff03bce0d17b9afa8153464801859ba4b023a1 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:24 +0000 Subject: [PATCH 38/40] Adds separate file for 'iCMDBChangeOp.php'. --- .../Core/DataModel/CMDBChange/iCMDBChangeOp.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/cmdbchangeop.class.inc.php => sources/Core/DataModel/CMDBChange/iCMDBChangeOp.php (100%) diff --git a/core/cmdbchangeop.class.inc.php b/sources/Core/DataModel/CMDBChange/iCMDBChangeOp.php similarity index 100% rename from core/cmdbchangeop.class.inc.php rename to sources/Core/DataModel/CMDBChange/iCMDBChangeOp.php From 14095baf67d9ac4b0a447b1619bf22630b7020a3 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:24 +0000 Subject: [PATCH 39/40] Changes content in separated file 'CMDBChangeOpSetAttributeURL.php'. --- .../CMDBChangeOpSetAttributeURL.php | 1189 +---------------- 1 file changed, 34 insertions(+), 1155 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeURL.php b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeURL.php index 26703dc62..4b061232c 100644 --- a/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeURL.php +++ b/sources/Core/DataModel/CMDBChange/CMDBChangeOpSetAttributeURL.php @@ -1,329 +1,61 @@ - /** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked + * Record the modification of an URL * * @package iTopORM */ - -/** - * Interface iCMDBChangeOp - * - * @since 3.0.0 - */ -interface iCMDBChangeOp +class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute { - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() + /** + * @inheritDoc + */ + public static function Init() { $aParams = array ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", + "category" => "core/cmdb, grant_by_profile", + "key_type" => "", + "name_attcode" => "change", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_changeop_setatt_url", + "db_key_field" => "id", + "db_finalclass_field" => "", ); MetaModel::Init_Params($aParams); MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); + + // N°4910 (oldvalue), N°5423 (newvalue) + // We cannot have validation here, as AttributeUrl validation is field dependant. + // The validation will be done when editing the iTop object, it isn't the history API responsibility + // + // Pattern is retrieved using this order : + // 1. try to get the pattern from the field definition (datamodel) + // 2. from the iTop config + // 3. config parameter default value + // see \AttributeURL::GetValidationPattern + MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); + MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); // Display lists MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list } - /** - * @inheritDoc - */ - public function GetDescription() + /** + * @inheritDoc + */ + public function GetDescription() { $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); + $oTargetObjectClass = $this->Get('objclass'); $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); + $oTargetSearch = new DBObjectSearch($oTargetObjectClass); $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { + if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); @@ -334,857 +66,4 @@ class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute } return $sResult; } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} +} \ No newline at end of file From 346b10505408cde1fd3ad6e60b0b8b1f176f2576 Mon Sep 17 00:00:00 2001 From: Potherca-Bot Date: Tue, 2 Sep 2025 22:28:24 +0000 Subject: [PATCH 40/40] Changes content in separated file 'iCMDBChangeOp.php'. --- .../DataModel/CMDBChange/iCMDBChangeOp.php | 1188 +---------------- 1 file changed, 7 insertions(+), 1181 deletions(-) diff --git a/sources/Core/DataModel/CMDBChange/iCMDBChangeOp.php b/sources/Core/DataModel/CMDBChange/iCMDBChangeOp.php index 26703dc62..9e8c14b14 100644 --- a/sources/Core/DataModel/CMDBChange/iCMDBChangeOp.php +++ b/sources/Core/DataModel/CMDBChange/iCMDBChangeOp.php @@ -1,35 +1,4 @@ - - -/** - * Persistent classes (internal) : cmdbChangeOp and derived - * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 - */ - - -/** - * Various atomic change operations, to be tracked - * - * @package iTopORM - */ /** * Interface iCMDBChangeOp @@ -38,1153 +7,10 @@ */ interface iCMDBChangeOp { - /** - * Describe (as an HTML string) the modifications corresponding to this change - * - * @return string - */ - public function GetDescription(); -} - -class CMDBChangeOp extends DBObject implements iCMDBChangeOp -{ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "autoincrement", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop", - "db_key_field" => "id", - "db_finalclass_field" => "optype", - 'indexes' => array( - array('objclass', 'objkey'), - ), - ); - MetaModel::Init_Params($aParams); - //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo"))); - MetaModel::Init_AddAttribute(new AttributeExternalField("user_id", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"user_id"))); - MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array()))); - - MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return ''; - } - - /** - * Safety net: - * * if change isn't persisted yet, use the current change and persist it if needed - * * in case the change is not given, let's guarantee that it will be set to the current ongoing change (or create a new one) - * - * @since 2.7.7 3.0.2 3.1.0 N°3717 do persist the current change if needed - */ - protected function OnInsert() - { - $iChange = $this->Get('change'); - if (($iChange <= 0) || (is_null($iChange))) { - $oChange = CMDBObject::GetCurrentChange(); - if ($oChange->IsNew()) { - $oChange->DBWrite(); - } - $this->Set('change', $oChange); - } - - parent::OnInsert(); - } -} - -/** - * Record the creation of an object - * - * @package iTopORM - */ -class CMDBChangeOpCreate extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_create", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectCreated'); - } -} - -/** - * Record the deletion of an object - * - * @package iTopORM - */ -class CMDBChangeOpDelete extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_delete", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Final class of the object (objclass must be set to the root class for efficiency purposes) - MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - // Last friendly name of the object - MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return Dict::S('Change:ObjectDeleted'); - } -} - -/** - * Record the modification of an attribute (abstract) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } -} - -/** - * Record the modification of a scalar attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_scalar", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a tag set attribute - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_tagset", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeText("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $sTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $sAttCode = $this->Get('attcode'); - $oTargetSearch = new DBObjectSearch($sTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of an URL - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_url", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // N°4910 (oldvalue), N°5423 (newvalue) - // We cannot have validation here, as AttributeUrl validation is field dependant. - // The validation will be done when editing the iTop object, it isn't the history API responsibility - // - // Pattern is retrieved using this order : - // 1. try to get the pattern from the field definition (datamodel) - // 2. from the iTop config - // 3. config parameter default value - // see \AttributeURL::GetValidationPattern - MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values" => null, "sql" => "oldvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values" => null, "sql" => "newvalue", "target" => '_blank', "default_value" => null, "is_null_allowed" => true, "depends_on" => array(), "validation_pattern" => '.*'))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - $sNewValue = $this->Get('newvalue'); - $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); - } - return $sResult; - } -} - -/** - * Record the modification of a blob - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_data", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - /** @var \ormDocument $oPrevDoc */ - $oPrevDoc = $this->Get('prevdata'); - if ($oPrevDoc->IsEmpty()) { - $sPrevious = ''; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevious); - } else { - $sFieldAsHtml = $oPrevDoc->GetAsHTML(); - - $sDisplayLabel = Dict::S('UI:OpenDocumentInNewWindow_'); - $sDisplayUrl = $oPrevDoc->GetDisplayURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDownloadLabel = Dict::S('UI:DownloadDocument_'); - $sDownloadUrl = $oPrevDoc->GetDownloadURL(get_class($this), $this->GetKey(), 'prevdata'); - - $sDocView = <<{$sDisplayLabel} / {$sDownloadLabel} -HTML; - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView); - } - } - return $sResult; - } -} - -/** - * Safely record the modification of one way encrypted password - */ -class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_pwd", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sResult = Dict::Format('Change:AttName_Changed', $sAttName); - } - return $sResult; - } -} - -/** - * Safely record the modification of an encrypted field - */ -class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_encrypted", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sPrevString = $this->GetAsHTML('prevstring'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_text", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_longtext", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = '
'.$this->GetAsHtml('prevdata').'
'; - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a multiline string (text) containing some HTML markup - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeHTML extends CMDBChangeOpSetAttributeLongText -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_html", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } else { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $sTextView = $this->Get('prevdata'); - - //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata'); - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - return $sResult; - } -} - -/** - * Record the modification of a caselog (text) - * since the caselog itself stores the history - * of its entries, there is no need to duplicate - * the text here - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_log", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - // Temporary, until we change the options of GetDescription() -needs a more global revision - $bIsHtml = true; - - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - } - else - { - // The attribute was renamed or removed from the object ? - $sAttName = $this->Get('attcode'); - } - $oObj = $oMonoObjectSet->Fetch(); - $oCaseLog = $oObj->Get($this->Get('attcode')); - $sTextEntry = '
'.$oCaseLog->GetEntryAt($this->Get('lastentry')).'
'; - - $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName, $sTextEntry); - } - return $sResult; - } - - /** - * @param string $sRawText - * - * @return string - */ - protected function ToHtml($sRawText) - { - return str_replace(array("\r\n", "\n", "\r"), "
", utils::EscapeHtml($sRawText)); - } -} - -/** - * Record an action made by a plug-in - * - * @package iTopORM - */ -class CMDBChangeOpPlugin extends CMDBChangeOp -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_plugin", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled - MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - */ - MetaModel::Init_InheritAttributes(); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - return $this->Get('description'); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface) - // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract) - MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } -} - -/** - * Record added/removed objects from within a link set - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_addremove", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - switch ($this->Get('type')) - { - case 'added': - $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc); - break; - - case 'removed': - $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc); - break; - } - } - return $sResult; - } -} - -/** - * Record attribute changes from within a link set - * A single record redirects to the modifications made within the same change - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_links_tune", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - - MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array()))); - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes... - - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - $sLinkClass = $oAttDef->GetLinkedClass(); - $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); - - // Search for changes on the corresponding link - // - $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); - $oSearch->AddCondition('change', $this->Get('change'), '='); - $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); - if (count($aLinkClasses) == 1) - { - // Faster than the whole building of the expression below for just one value ?? - $oSearch->AddCondition('objclass', $sLinkClass, '='); - } - else - { - $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); - $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')'; - $sOQLCondition = $oField->RenderExpression()." IN $sListExpr"; - $oNewCondition = Expression::FromOQL($sOQLCondition); - $oSearch->AddConditionExpression($oNewCondition); - } - $oSet = new DBObjectSet($oSearch); - $aChanges = array(); - while ($oChangeOp = $oSet->Fetch()) - { - $aChanges[] = $oChangeOp->GetDescription(); - } - if (count($aChanges) == 0) - { - return ''; - } - - $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); - - $sResult = $sAttName.' - '; - $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); - $sResult .= ' : '.implode(', ', $aChanges); - } - return $sResult; - } -} - -/** - * Record the modification of custom fields - * - * @package iTopORM - */ -class CMDBChangeOpSetAttributeCustomFields extends CMDBChangeOpSetAttribute -{ - /** - * @inheritDoc - */ - public static function Init() - { - $aParams = array - ( - "category" => "core/cmdb, grant_by_profile", - "key_type" => "", - "name_attcode" => "change", - "state_attcode" => "", - "reconc_keys" => array(), - "db_table" => "priv_changeop_setatt_custfields", - "db_key_field" => "id", - "db_finalclass_field" => "", - ); - MetaModel::Init_Params($aParams); - MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array()))); - - // Display lists - MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list - } - - /** - * @inheritDoc - */ - public function GetDescription() - { - $sResult = ''; - if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) - { - $oTargetObjectClass = $this->Get('objclass'); - $oTargetObjectKey = $this->Get('objkey'); - $oTargetSearch = new DBObjectSearch($oTargetObjectClass); - $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); - - $oMonoObjectSet = new DBObjectSet($oTargetSearch); - if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) - { - $aValues = json_decode($this->Get('prevdata'), true); - $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); - $sAttName = $oAttDef->GetLabel(); - - try - { - $oHandler = $oAttDef->GetHandler($aValues); - $sValueDesc = $oHandler->GetAsHTML($aValues); - } - catch (Exception $e) { - $sValueDesc = 'Custom field error: '.utils::EscapeHtml($e->getMessage()); - } - $sTextView = '
'.$sValueDesc.'
'; - - $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView); - } - } - return $sResult; - } -} + /** + * Describe (as an HTML string) the modifications corresponding to this change + * + * @return string + */ + public function GetDescription(); +} \ No newline at end of file