Explorar o código

N°804 Portal: Object display crashed when a linkedset attribute has corrupted data (eg. an external key to 0)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4638 a333f486-631f-4898-b8df-5754b55c2be0
glajarige %!s(int64=8) %!d(string=hai) anos
pai
achega
df32884238

+ 13 - 2
sources/renderer/bootstrap/fieldrenderer/bslinkedsetfieldrenderer.class.inc.php

@@ -19,7 +19,9 @@
 
 namespace Combodo\iTop\Renderer\Bootstrap\FieldRenderer;
 
+use \Exception;
 use \utils;
+use \IssueLog;
 use \Dict;
 use \UserRights;
 use \InlineImage;
@@ -479,8 +481,17 @@ EOF
 			// In case of indirect linked set, we must retrieve the remote object
 			if ($this->oField->IsIndirect())
 			{
-				// Note : AllowAllData set to true here instead of checking scope's flag because we are displaying a value that has been set and validated
-				$oRemoteItem = MetaModel::GetObject($this->oField->GetTargetClass(), $oItem->Get($this->oField->GetExtKeyToRemote()), true, true);
+			    try{
+                    // Note : AllowAllData set to true here instead of checking scope's flag because we are displaying a value that has been set and validated
+                    $oRemoteItem = MetaModel::GetObject($this->oField->GetTargetClass(), $oItem->Get($this->oField->GetExtKeyToRemote()), true, true);
+                }
+                catch(Exception $e)
+                {
+                    // In some cases we can't retrieve an object from a linkedset, eg. when the extkey to remote is 0 due to a database corruption.
+                    // Rather than crashing we rather just skip the object like in the administration console
+                    IssueLog::Error('Could not retrieve object of linkedset in form #'.$this->oField->GetFormPath().' for field #'.$this->oField->GetId().'. Message: '.$e->getMessage());
+                    continue;
+                }
 			}
 			else
 			{