CRM_Core_DAO - Cleanup in createTestObject
authorTim Otten <totten@civicrm.org>
Fri, 22 Aug 2014 08:05:49 +0000 (01:05 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 27 Aug 2014 00:47:22 +0000 (17:47 -0700)
CRM/Core/DAO.php

index 7e4a6e930ca79bba465dea4ccc27068821848b70..28948d83e624b2e2d5e8f5f27aa1c73599a1f4e5 100644 (file)
@@ -1516,40 +1516,44 @@ SELECT contact_id
       /** @var CRM_Core_DAO $object */
       $object = new $daoName();
 
-      $fields = &$object->fields();
+      $fields = & $object->fields();
       foreach ($fields as $fieldName => $fieldDef) {
         $dbName = $fieldDef['name'];
+        $FKClassName = CRM_Utils_Array::value('FKClassName', $fieldDef);
         $required = CRM_Utils_Array::value('required', $fieldDef);
+
         if (CRM_Utils_Array::value($dbName, $params) !== NULL && !is_array($params[$dbName])) {
           $object->$dbName = $params[$dbName];
         }
 
         elseif ($dbName != 'id') {
-          if (CRM_Utils_Array::value('FKClassName', $fieldDef) != NULL) {
+          if ($FKClassName != NULL) {
             $object->assignTestFK($fieldName, $fieldDef, $params);
             continue;
+          } else {
+            $object->assignTestValue($fieldName, $fieldDef, $counter);
           }
-
-          $object->assignTestValue($fieldName, $fieldDef, $counter);
         }
       }
       $object->save();
 
       if (!$createOnly) {
-
         $objects[$i] = $object;
-
       }
-      else unset($object);
+      else {
+        unset($object);
+      }
     }
 
     if ($createOnly) {
-
       return;
-
     }
-    elseif ($numObjects == 1) {  return $objects[0];}
-    else return $objects;
+    elseif ($numObjects == 1) {
+      return $objects[0];
+    }
+    else {
+      return $objects;
+    }
   }
 
   /**