Cleanup CRM_Core_DAO
authorColeman Watts <coleman@civicrm.org>
Sat, 16 Dec 2017 07:52:50 +0000 (00:52 -0700)
committerdeb.monish <monish.deb@jmaconsulting.biz>
Wed, 27 Dec 2017 16:44:14 +0000 (22:14 +0530)
CRM/Core/DAO.php

index 11663af97eb41d9b6d1fc3cfd2c2a79fc66a2313..ef96f423289be231d992c1c07061e46a5077bce7 100644 (file)
@@ -26,7 +26,9 @@
  */
 
 /**
- * Our base DAO class. All DAO classes should inherit from this class.
+ * Base Database Access Object class.
+ *
+ * All DAO classes should inherit from this class.
  *
  * @package CRM
  * @copyright CiviCRM LLC (c) 2004-2017
@@ -403,6 +405,7 @@ class CRM_Core_DAO extends DB_DataObject {
    * Factory method to instantiate a new object from a table name.
    *
    * @param string $table
+   * @return \DataObject|\PEAR_Error
    */
   public function factory($table = '') {
     if (!isset(self::$_factory)) {
@@ -429,7 +432,6 @@ class CRM_Core_DAO extends DB_DataObject {
   /**
    * Defines the default key as 'id'.
    *
-   *
    * @return array
    */
   public function keys() {
@@ -484,7 +486,7 @@ class CRM_Core_DAO extends DB_DataObject {
    *   (associative)
    */
   public function table() {
-    $fields = &$this->fields();
+    $fields = $this->fields();
 
     $table = array();
     if ($fields) {
@@ -609,7 +611,7 @@ class CRM_Core_DAO extends DB_DataObject {
    *   Did we copy all null values into the object
    */
   public function copyValues(&$params) {
-    $fields = &$this->fields();
+    $fields = $this->fields();
     $allNull = TRUE;
     foreach ($fields as $name => $value) {
       $dbName = $value['name'];
@@ -650,7 +652,7 @@ class CRM_Core_DAO extends DB_DataObject {
    *   (reference ) associative array of name/value pairs.
    */
   public static function storeValues(&$object, &$values) {
-    $fields = &$object->fields();
+    $fields = $object->fields();
     foreach ($fields as $name => $value) {
       $dbName = $value['name'];
       if (isset($object->$dbName) && $object->$dbName !== 'null') {
@@ -726,7 +728,7 @@ class CRM_Core_DAO extends DB_DataObject {
    */
   public static function getAttribute($class, $fieldName = NULL) {
     $object = new $class();
-    $fields = &$object->fields();
+    $fields = $object->fields();
     if ($fieldName != NULL) {
       $field = CRM_Utils_Array::value($fieldName, $fields);
       return self::makeAttribute($field);
@@ -747,15 +749,6 @@ class CRM_Core_DAO extends DB_DataObject {
     return NULL;
   }
 
-  /**
-   * @param $type
-   *
-   * @throws Exception
-   */
-  public static function transaction($type) {
-    CRM_Core_Error::fatal('This function is obsolete, please use CRM_Core_Transaction');
-  }
-
   /**
    * Check if there is a record with the same name in the db.
    *
@@ -1031,8 +1024,10 @@ FROM   civicrm_domain
    * @param int $id
    *   Id of the DAO object being searched for.
    *
-   * @return object
+   * @return CRM_Core_DAO
    *   Object of the type of the class that called this function.
+   *
+   * @throws Exception
    */
   public static function findById($id) {
     $object = new static();
@@ -1181,7 +1176,6 @@ FROM   civicrm_domain
    *   Default sort value.
    *
    * @return string
-   *   sortString
    */
   public static function getSortString($sort, $default = NULL) {
     // check if sort is of type CRM_Utils_Sort
@@ -1189,6 +1183,8 @@ FROM   civicrm_domain
       return $sort->orderBy();
     }
 
+    $sortString = '';
+
     // is it an array specified as $field => $sortDirection ?
     if ($sort) {
       foreach ($sort as $k => $v) {
@@ -1506,23 +1502,21 @@ FROM   civicrm_domain
   }
 
   /**
-   * make a shallow copy of an object.
-   * and all the fields in the object
+   * Make a shallow copy of an object and all the fields in the object.
    *
    * @param string $daoName
    *   Name of the dao.
    * @param array $criteria
    *   Array of all the fields & values.
-   *                                        on which basis to copy
+   *   on which basis to copy
    * @param array $newData
    *   Array of all the fields & values.
-   *                                        to be copied besides the other fields
+   *   to be copied besides the other fields
    * @param string $fieldsFix
    *   Array of fields that you want to prefix/suffix/replace.
    * @param string $blockCopyOfDependencies
    *   Fields that you want to block from.
-   *                                        getting copied
-   *
+   *   getting copied
    *
    * @return CRM_Core_DAO
    *   the newly created copy of the object
@@ -1550,7 +1544,7 @@ FROM   civicrm_domain
 
       $newObject = new $daoName();
 
-      $fields = &$object->fields();
+      $fields = $object->fields();
       if (!is_array($fieldsFix)) {
         $fieldsToPrefix = array();
         $fieldsToSuffix = array();
@@ -1619,7 +1613,7 @@ FROM   civicrm_domain
       $newObject->id = $toId;
 
       if ($newObject->find(TRUE)) {
-        $fields = &$object->fields();
+        $fields = $object->fields();
         foreach ($fields as $name => $value) {
           if ($name == 'id' || $value['name'] == 'id') {
             // copy everything but the id!
@@ -1711,6 +1705,11 @@ SELECT contact_id
     return $details;
   }
 
+  /**
+   * Drop all CiviCRM tables.
+   *
+   * @throws \CRM_Exception
+   */
   public static function dropAllTables() {
 
     // first drop all the custom tables we've created
@@ -1843,7 +1842,7 @@ 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);
@@ -1904,7 +1903,7 @@ SELECT contact_id
     $deletions = array(); // array(array(0 => $daoName, 1 => $daoParams))
     if ($object->find(TRUE)) {
 
-      $fields = &$object->fields();
+      $fields = $object->fields();
       foreach ($fields as $name => $value) {
 
         $dbName = $value['name'];