Pārlūkot izejas kodu

Silently discard unknown attributes in object templates (in case some modules have not been installed)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2733 a333f486-631f-4898-b8df-5754b55c2be0
romainq 12 gadi atpakaļ
vecāks
revīzija
eaaa98e6ab
1 mainītis faili ar 22 papildinājumiem un 2 dzēšanām
  1. 22 2
      application/template.class.inc.php

+ 22 - 2
application/template.class.inc.php

@@ -283,9 +283,29 @@ class ObjectDetailsTemplate extends DisplayTemplate
 		$sStateAttCode = MetaModel :: GetStateAttributeCode(get_class($this->m_oObj));
 		$aTemplateFields = array();
 		preg_match_all('/\\$this->([a-z0-9_]+)\\$/', $this->m_sTemplate, $aMatches);
-		$aTemplateFields = $aMatches[1];
+		foreach ($aMatches[1] as $sAttCode)
+		{
+			if (MetaModel::IsValidAttCode(get_class($this->m_oObj), $sAttCode))
+			{
+				$aTemplateFields[] = $sAttCode;
+			}
+			else
+			{
+				$aParams['this->'.$sAttCode] = "<!--Unknown attribute: $sAttCode-->";					
+			}
+		}
 		preg_match_all('/\\$this->field\\(([a-z0-9_]+)\\)\\$/', $this->m_sTemplate, $aMatches);
-		$aTemplateFields = array_merge($aTemplateFields, $aMatches[1]);
+		foreach ($aMatches[1] as $sAttCode)
+		{
+			if (MetaModel::IsValidAttCode(get_class($this->m_oObj), $sAttCode))
+			{
+				$aTemplateFields[] = $sAttCode;
+			}
+			else
+			{
+				$aParams['this->field('.$sAttCode.')'] = "<!--Unknown attribute: $sAttCode-->";
+			}
+		}
 		$aFieldsComments = (isset($aParams['fieldsComments'])) ? $aParams['fieldsComments'] : array();
 		$aFieldsMap = array();