diff --git a/core/bulkchange.class.inc.php b/core/bulkchange.class.inc.php index 6b4332d52..fae8db1eb 100644 --- a/core/bulkchange.class.inc.php +++ b/core/bulkchange.class.inc.php @@ -172,7 +172,7 @@ class RowStatus_NewObj extends RowStatus } else { - if (empty($this->m_sClass)) + if (!empty($this->m_sClass)) { $oObj = MetaModel::GetObject($this->m_sClass, $this->m_iObjKey); return 'Created '.$oObj->GetHyperLink(); @@ -281,7 +281,7 @@ class BulkChange { case 0: $aErrors[$sAttCode] = "Object not found"; - $aResults[$sAttCode]= new CellChangeSpec_Issue(null, $oTargetObj->Get($sAttCode), 'Object not found'); + $aResults[$sAttCode]= new CellChangeSpec_Issue(null, $oTargetObj->Get($sAttCode), 'Object not found - check the spelling (no space before/after)'); break; case 1: // Do change the external key attribute diff --git a/core/metamodel.class.php b/core/metamodel.class.php index 39d116f49..f93f8a897 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -2564,7 +2564,7 @@ abstract class MetaModel return $iTotalHits.' ('.implode(', ', $aRes).')'; } - public static function MakeSingleRow($sClass, $iKey) + public static function MakeSingleRow($sClass, $iKey, $bMustBeFound = true) { if (!array_key_exists($sClass, self::$aQueryCacheGetObject)) { @@ -2591,7 +2591,7 @@ abstract class MetaModel $aRow = CMDBSource::FetchArray($res); CMDBSource::FreeResult($res); - if (empty($aRow)) + if ($bMustBeFound && empty($aRow)) { throw new CoreException("No result for the single row query: '$sSQL'"); } @@ -2625,10 +2625,10 @@ abstract class MetaModel return new $sClass($aRow); } - public static function GetObject($sClass, $iKey) + public static function GetObject($sClass, $iKey, $bMustBeFound = true) { self::_check_subclass($sClass); - $aRow = self::MakeSingleRow($sClass, $iKey); + $aRow = self::MakeSingleRow($sClass, $iKey, $bMustBeFound); if (empty($aRow)) { return null; @@ -2636,9 +2636,17 @@ abstract class MetaModel return self::GetObjectByRow($sClass, $aRow); } - public static function GetHyperLink($sTargetClass, $sOldValue) + public static function GetHyperLink($sTargetClass, $iKey) { - $oObj = self::GetObject($sTargetClass, $sOldValue); + if ($iKey < 0) + { + return "$sTargetClass: $iKey (invalid value)"; + } + $oObj = self::GetObject($sTargetClass, $iKey, false); + if (is_null($oObj)) + { + return "$sTargetClass: $iKey (not found)"; + } return $oObj->GetHyperLink(); } diff --git a/pages/csvimport.php b/pages/csvimport.php index 24bf03798..256aa2957 100644 --- a/pages/csvimport.php +++ b/pages/csvimport.php @@ -75,6 +75,8 @@ function ShowTableForm($oPage, $oCSVParser, $sClass) $aFields = array(); foreach($oCSVParser->ListFields() as $iFieldIndex=>$sFieldName) { + $sFieldName = trim($sFieldName); + $aOptions = array(); $aOptions['id'] = array( 'LabelHtml' => "Private key", @@ -336,18 +338,17 @@ function Do_Welcome($oPage, $sClass) $sCSVData = utils::ReadPostedParam('csvdata'); - $oPage->add("
"); + $oPage->add(""); - // As a help to the end-user, let's display the list of possible fields - // for a class, that can be copied/pasted into the CSV area. + // As a help to the end-user, let's display the list of possible fields + // for a class, that can be copied/pasted into the CSV area. $sCurrentList = ""; $aHeadersList = array(); foreach(MetaModel::GetClasses('bizmodel') as $sClassName) @@ -385,8 +386,8 @@ function Do_Welcome($oPage, $sClass) \n"); $oPage->add_ready_script("$('#select_class').change( function() {DisplayFields(this.value);} );"); - - $oPage->add("Fields for this object: "); + $oPage->add("