protected function RecordAttChanges(array $aValues, array $aOrigValues) { parent::RecordAttChanges($aValues, $aOrigValues); // $aValues is an array of $sAttCode => $value // foreach ($aValues as $sAttCode => $value) { $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); if ($oAttDef->IsExternalField()) { continue; } if ($oAttDef->IsLinkSet()) { continue; } if ($oAttDef->GetTrackingLevel() == ATTRIBUTE_TRACKING_NONE) { continue; } if (array_key_exists($sAttCode, $aOrigValues)) { $original = $aOrigValues[$sAttCode]; } else { $original = null; } if ($oAttDef instanceof AttributeOneWayPassword) { // One Way encrypted passwords' history is stored -one way- encrypted $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeOneWayPassword"); $oMyChangeOp->Set("objclass", get_class($this)); $oMyChangeOp->Set("objkey", $this->GetKey()); $oMyChangeOp->Set("attcode", $sAttCode); if (is_null($original)) { $original = ''; } $oMyChangeOp->Set("prev_pwd", $original); $iId = $oMyChangeOp->DBInsertNoReload(); } elseif ($oAttDef instanceof AttributeEncryptedString) { // Encrypted string history is stored encrypted $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeEncrypted"); $oMyChangeOp->Set("objclass", get_class($this)); $oMyChangeOp->Set("objkey", $this->GetKey()); $oMyChangeOp->Set("attcode", $sAttCode); if (is_null($original)) { $original = ''; } $oMyChangeOp->Set("prevstring", $original); $iId = $oMyChangeOp->DBInsertNoReload(); } elseif ($oAttDef instanceof AttributeBlob) { // Data blobs $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeBlob"); $oMyChangeOp->Set("objclass", get_class($this)); $oMyChangeOp->Set("objkey", $this->GetKey()); $oMyChangeOp->Set("attcode", $sAttCode); if (is_null($original)) { $original = new ormDocument(); } $oMyChangeOp->Set("prevdata", $original); $iId = $oMyChangeOp->DBInsertNoReload(); } elseif ($oAttDef instanceof AttributeStopWatch) { // Stop watches - record changes for sub items only (they are visible, the rest is not visible) // if (is_null($original)) { $original = new OrmStopWatch(); } foreach ($oAttDef->ListSubItems() as $sSubItemAttCode => $oSubItemAttDef) { $item_value = $oSubItemAttDef->GetValue($value); $item_original = $oSubItemAttDef->GetValue($original); if ($item_value != $item_original) { $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeScalar"); $oMyChangeOp->Set("objclass", get_class($this)); $oMyChangeOp->Set("objkey", $this->GetKey()); $oMyChangeOp->Set("attcode", $sSubItemAttCode); $oMyChangeOp->Set("oldvalue", $item_original); $oMyChangeOp->Set("newvalue", $item_value); $iId = $oMyChangeOp->DBInsertNoReload(); } } } elseif ($oAttDef instanceof AttributeCaseLog) { $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeCaseLog"); $oMyChangeOp->Set("objclass", get_class($this)); $oMyChangeOp->Set("objkey", $this->GetKey()); $oMyChangeOp->Set("attcode", $sAttCode); $oMyChangeOp->Set("lastentry", $value->GetLatestEntryIndex()); $iId = $oMyChangeOp->DBInsertNoReload(); } elseif ($oAttDef instanceof AttributeLongText) { // Data blobs $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeLongText"); $oMyChangeOp->Set("objclass", get_class($this)); $oMyChangeOp->Set("objkey", $this->GetKey()); $oMyChangeOp->Set("attcode", $sAttCode); if (!is_null($original) && $original instanceof ormCaseLog) { $original = $original->GetText(); } $oMyChangeOp->Set("prevdata", $original); $iId = $oMyChangeOp->DBInsertNoReload(); } elseif ($oAttDef instanceof AttributeText) { // Data blobs $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeText"); $oMyChangeOp->Set("objclass", get_class($this)); $oMyChangeOp->Set("objkey", $this->GetKey()); $oMyChangeOp->Set("attcode", $sAttCode); if (!is_null($original) && $original instanceof ormCaseLog) { $original = $original->GetText(); } $oMyChangeOp->Set("prevdata", $original); $iId = $oMyChangeOp->DBInsertNoReload(); } elseif ($oAttDef instanceof AttributeBoolean) { $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeScalar"); $oMyChangeOp->Set("objclass", get_class($this)); $oMyChangeOp->Set("objkey", $this->GetKey()); $oMyChangeOp->Set("attcode", $sAttCode); $oMyChangeOp->Set("oldvalue", $original ? 1 : 0); $oMyChangeOp->Set("newvalue", $value ? 1 : 0); $iId = $oMyChangeOp->DBInsertNoReload(); } elseif ($oAttDef instanceof AttributeHierarchicalKey) { // Hierarchical keys // $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeScalar"); $oMyChangeOp->Set("objclass", get_class($this)); $oMyChangeOp->Set("objkey", $this->GetKey()); $oMyChangeOp->Set("attcode", $sAttCode); $oMyChangeOp->Set("oldvalue", $original); $oMyChangeOp->Set("newvalue", $value[$sAttCode]); $iId = $oMyChangeOp->DBInsertNoReload(); } else { // Scalars // $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeScalar"); $oMyChangeOp->Set("objclass", get_class($this)); $oMyChangeOp->Set("objkey", $this->GetKey()); $oMyChangeOp->Set("attcode", $sAttCode); $oMyChangeOp->Set("oldvalue", $original); $oMyChangeOp->Set("newvalue", $value); $iId = $oMyChangeOp->DBInsertNoReload(); } } }