From 3d04cf1cd66deee076f82d424725a40b5c79a7f4 Mon Sep 17 00:00:00 2001 From: Thomas Casteleyn Date: Tue, 17 May 2022 17:01:41 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=90=20Improve=20DBObject::CheckValue?= =?UTF-8?q?=20and=20CheckConsistency=20error=20messages=20(#288)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now contains attribute code and value --- application/cmdbabstract.class.inc.php | 2 +- core/dbobject.class.php | 13 ++++++------- dictionaries/en.dictionary.itop.core.php | 4 +++- dictionaries/en.dictionary.itop.ui.php | 2 +- pages/UI.php | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 937de56a7..d86c62dab 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -3957,7 +3957,7 @@ HTML; } elseif ($iFlags & OPT_ATT_SLAVE) { - $aErrors[$sAttCode] = Dict::Format('UI:AttemptingToSetASlaveAttribute_Name', $oAttDef->GetLabel()); + $aErrors[$sAttCode] = Dict::Format('UI:AttemptingToSetASlaveAttribute_Name', $oAttDef->GetLabel(), $sAttCode); } else { diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 394c16fc2..bd21dd356 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -1,6 +1,6 @@ $value) { $res = $this->CheckValue($sAttCode); if ($res !== true) { + $sAttLabel = $this->GetLabel($sAttCode); // $res contains the error description - $this->m_aCheckIssues[] = "Unexpected value for attribute '$sAttCode': $res"; + $this->m_aCheckIssues[] = Dict::Format('Core:CheckValueError', $sAttLabel, $sAttCode, $res); } $this->DoCheckLinkedSetDuplicates($sAttCode, $value); @@ -2265,7 +2266,7 @@ abstract class DBObject implements iDisplay if ($res !== true) { // $res contains the error description - $this->m_aCheckIssues[] = "Consistency rules not followed: $res"; + $this->m_aCheckIssues[] = Dict::Format('Core:CheckConsistencyError', $res); } // Synchronization: are we attempting to modify an attribute for which an external source is master? @@ -2278,12 +2279,10 @@ abstract class DBObject implements iDisplay if ($iFlags & OPT_ATT_SLAVE) { // Note: $aReasonInfo['name'] could be reported (the task owning the attribute) - $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); - $sAttLabel = $oAttDef->GetLabel(); if (!empty($aReasons)) { - // Todo: associate the attribute code with the error - $this->m_aCheckIssues[] = Dict::Format('UI:AttemptingToSetASlaveAttribute_Name', $sAttLabel); + $sAttLabel = $this->GetLabel($sAttCode); + $this->m_aCheckIssues[] = Dict::Format('UI:AttemptingToSetASlaveAttribute_Name', $sAttLabel, $sAttCode); } } } diff --git a/dictionaries/en.dictionary.itop.core.php b/dictionaries/en.dictionary.itop.core.php index 6fe9bdcf1..ede2e217b 100644 --- a/dictionaries/en.dictionary.itop.core.php +++ b/dictionaries/en.dictionary.itop.core.php @@ -2,7 +2,7 @@ /** * Localized data * - * @copyright Copyright (C) 2010-2021 Combodo SARL + * @copyright Copyright (C) 2010-2022 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 * * This file is part of iTop. @@ -29,6 +29,8 @@ Dict::Add('EN US', 'English', 'English', array( 'Core:UnknownObjectTip' => 'The object could not be found. It may have been deleted some time ago and the log has been purged since.', 'Core:UniquenessDefaultError' => 'Uniqueness rule \'%1$s\' in error', + 'Core:CheckConsistencyError' => 'Consistency rules not followed: %1$s', + 'Core:CheckValueError' => 'Unexpected value for attribute \'%1$s\' (%2$s) : %3$s', 'Core:AttributeLinkedSet' => 'Array of objects', 'Core:AttributeLinkedSet+' => 'Any kind of objects of the same class or subclass', diff --git a/dictionaries/en.dictionary.itop.ui.php b/dictionaries/en.dictionary.itop.ui.php index bef34d8d4..cdd0dcc0e 100644 --- a/dictionaries/en.dictionary.itop.ui.php +++ b/dictionaries/en.dictionary.itop.ui.php @@ -1162,7 +1162,7 @@ When associated with a trigger, each action is given an "order" number, specifyi 'UI:CaseLogTypeYourTextHere' => 'Type your text here...', 'UI:CaseLog:Header_Date_UserName' => '%1$s - %2$s:', 'UI:CaseLog:InitialValue' => 'Initial value:', - 'UI:AttemptingToSetASlaveAttribute_Name' => 'The field %1$s is not writable because it is mastered by the data synchronization. Value not set.', + 'UI:AttemptingToSetASlaveAttribute_Name' => 'The field %1$s (%2$s) is not writable because it is mastered by the data synchronization. Value not set.', 'UI:ActionNotAllowed' => 'You are not allowed to perform this action on these objects.', 'UI:BulkAction:NoObjectSelected' => 'Please select at least one object to perform this operation', 'UI:AttemptingToChangeASlaveAttribute_Name' => 'The field %1$s is not writable because it is mastered by the data synchronization. Value remains unchanged.', diff --git a/pages/UI.php b/pages/UI.php index 1ff6188c5..2f9742d97 100644 --- a/pages/UI.php +++ b/pages/UI.php @@ -1455,7 +1455,7 @@ EOF if ( ($iFlags & OPT_ATT_SLAVE) && ($paramValue != $oObj->Get($sAttCode)) ) { $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); - $aErrors[] = Dict::Format('UI:AttemptingToSetASlaveAttribute_Name', $oAttDef->GetLabel()); + $aErrors[] = Dict::Format('UI:AttemptingToSetASlaveAttribute_Name', $oAttDef->GetLabel(), $sAttCode); unset($aExpectedAttributes[$sAttCode]); } }