浏览代码

N.689 throw Exception if querying without needed finalClass attribute, plus some PHPDoc

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@5050 a333f486-631f-4898-b8df-5754b55c2be0
pgoiffon 7 年之前
父节点
当前提交
f14ee58386
共有 1 个文件被更改,包括 24 次插入0 次删除
  1. 24 0
      core/metamodel.class.php

+ 24 - 0
core/metamodel.class.php

@@ -623,6 +623,11 @@ abstract class MetaModel
 		return self::$m_aClassParams[$sClass]["db_finalclass_field"];
 	}
 
+	/**
+	 * @param string $sClass
+	 *
+	 * @return boolean true if the class has no parent and no children
+	 */
 	final static public function IsStandaloneClass($sClass)
 	{
 		self::_check_subclass($sClass);
@@ -2772,6 +2777,11 @@ abstract class MetaModel
 		return $aRes;
 	}
 
+	/**
+	 * @param string $sClass
+	 *
+	 * @return bool
+	 */
 	public static function HasChildrenClasses($sClass)
 	{
 		return (count(self::$m_aChildClasses[$sClass]) > 0);
@@ -2831,6 +2841,11 @@ abstract class MetaModel
 		return true;
 	}
 
+	/**
+	 * @param string $sClass
+	 *
+	 * @return bool
+	 */
 	public static function IsAbstract($sClass)
 	{
 		$oReflection = new ReflectionClass($sClass);
@@ -5021,6 +5036,7 @@ abstract class MetaModel
 	 * @param array $aExtendedDataSpec
 	 *
 	 * @return DBObject
+	 * @throws CoreUnexpectedValue if finalClass attribute wasn't specified but is needed
 	 * @throws CoreException if finalClass cannot be found
 	 */
 	public static function GetObjectByRow($sClass, $aRow, $sClassAlias = '', $aAttToLoad = null, $aExtendedDataSpec = null)
@@ -5038,6 +5054,14 @@ abstract class MetaModel
 		{
 			// Either this is a bug (forgot to specify a root class with a finalclass field
 			// Or this is the expected behavior, because the object is not made of several tables
+			if (self::IsAbstract($sClass))
+			{
+				throw new CoreUnexpectedValue("Querying the abstract '$sClass' class without finalClass attribute");
+			}
+			if (self::HasChildrenClasses($sClass))
+			{
+				throw new CoreUnexpectedValue("Querying the '$sClass' class without the finalClass attribute, whereas this class has  children");
+			}
 		}
 		elseif (empty($aRow[$sClassAlias."finalclass"]))
 		{