From 523e19528e9bd54a78b18a4efe99caa4f059ae5c Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Fri, 28 Dec 2018 18:16:32 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B01915=20import=20:=20fix=20cannot=20creat?= =?UTF-8?q?e=20object=20with=20value=20for=20field=20that=20is=20readonly?= =?UTF-8?q?=20in=20modification=20GetAttributeFlags=20method=20returns=20O?= =?UTF-8?q?PT=5FATT=5FREADONLY=20for=20this=20field,=20but=20not=20GetInit?= =?UTF-8?q?ialStateAttributeFlags=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/bulkchange.class.inc.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/core/bulkchange.class.inc.php b/core/bulkchange.class.inc.php index 64f78ae54..b9589b982 100644 --- a/core/bulkchange.class.inc.php +++ b/core/bulkchange.class.inc.php @@ -332,7 +332,20 @@ class BulkChange return true; } - protected function PrepareObject(&$oTargetObj, $aRowData, &$aErrors) + /** + * @param \DBObject $oTargetObj + * @param array $aRowData + * @param array $aErrors + * @param bool $bIsNewObject + * + * @return array + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \MissingQueryArgument + * @throws \MySQLException + * @throws \MySQLHasGoneAwayException + */ + protected function PrepareObject(&$oTargetObj, $aRowData, &$aErrors, $bIsNewObject = false) { $aResults = array(); $aErrors = array(); @@ -477,7 +490,9 @@ class BulkChange if (!$oAttDef->IsWritable() && in_array($sAttCode, $this->m_aReconcilKeys)){ continue; } $aReasons = array(); - $iFlags = $oTargetObj->GetAttributeFlags($sAttCode, $aReasons); + $iFlags = ($bIsNewObject) + ? $oTargetObj->GetInitialStateAttributeFlags($sAttCode, $aReasons) + : $oTargetObj->GetAttributeFlags($sAttCode, $aReasons); if ( (($iFlags & OPT_ATT_READONLY) == OPT_ATT_READONLY) && ( $oTargetObj->Get($sAttCode) != $aRowData[$iCol]) ) { $aErrors[$sAttCode] = Dict::Format('UI:CSVReport-Value-Issue-Readonly', $sAttCode, $oTargetObj->Get($sAttCode), $aRowData[$iCol]); @@ -685,7 +700,7 @@ class BulkChange } } - $aResult[$iRow] = $this->PrepareObject($oTargetObj, $aRowData, $aErrors); + $aResult[$iRow] = $this->PrepareObject($oTargetObj, $aRowData, $aErrors, true); if (count($aErrors) > 0) { @@ -733,7 +748,7 @@ class BulkChange protected function UpdateObject(&$aResult, $iRow, $oTargetObj, $aRowData, CMDBChange $oChange = null) { - $aResult[$iRow] = $this->PrepareObject($oTargetObj, $aRowData, $aErrors); + $aResult[$iRow] = $this->PrepareObject($oTargetObj, $aRowData, $aErrors, false); // Reporting //