Merge pull request #11999 from totten/master-header
[civicrm-core.git] / CRM / Core / DAO.php
index d5eab412c1ea9775066b6ce247afbd1969dd4a82..cab84ffeb0ee3720ee91810ef5ed0ca91b2bc8f2 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
   +--------------------------------------------------------------------+
-  | CiviCRM version 4.7                                                |
+  | CiviCRM version 5                                                  |
   +--------------------------------------------------------------------+
-  | Copyright CiviCRM LLC (c) 2004-2017                                |
+  | Copyright CiviCRM LLC (c) 2004-2018                                |
   +--------------------------------------------------------------------+
   | This file is a part of CiviCRM.                                    |
   |                                                                    |
@@ -31,7 +31,7 @@
  * All DAO classes should inherit from this class.
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2017
+ * @copyright CiviCRM LLC (c) 2004-2018
  */
 
 if (!defined('DB_DSN_MODE')) {
@@ -610,11 +610,17 @@ class CRM_Core_DAO extends DB_DataObject {
    *
    * @param array $params
    *   (reference ) associative array of name/value pairs.
+   * @param bool $serializeArrays
+   *   Should arrays that are passed in be serialised according to the metadata.
+   *   Eventually this should be always true / gone, but in the interests of caution
+   *   it is being grandfathered in. In general an array is not valid on the DAO
+   *   but there may be instances where this function is called & then some handling
+   *   takes place on the would-be array.
    *
    * @return bool
    *   Did we copy all null values into the object
    */
-  public function copyValues(&$params) {
+  public function copyValues(&$params, $serializeArrays = FALSE) {
     $fields = $this->fields();
     $allNull = TRUE;
     foreach ($fields as $name => $value) {
@@ -636,7 +642,14 @@ class CRM_Core_DAO extends DB_DataObject {
         if ($pValue === '') {
           $this->$dbName = 'null';
         }
+        elseif ($serializeArrays && is_array($pValue) && !empty($value['serialize'])) {
+          $this->$dbName = CRM_Core_DAO::serializeField($pValue, $value['serialize']);
+          $allNull = FALSE;
+        }
         else {
+          if (!$serializeArrays && is_array($pValue) && !empty($value['serialize'])) {
+            Civi::log()->warning(ts('use copyParams to serialize arrays (' . __CLASS__ . '.' . $name . ')'), ['civi.tag' => 'deprecated']);
+          }
           $this->$dbName = $pValue;
           $allNull = FALSE;
         }
@@ -1649,10 +1662,10 @@ FROM   civicrm_domain
    *
    * @param $componentIDs
    * @param string $tableName
-   *
+   * @param string $idField
    * @return array
    */
-  public static function &getContactIDsFromComponent(&$componentIDs, $tableName) {
+  public static function getContactIDsFromComponent($componentIDs, $tableName, $idField = 'id') {
     $contactIDs = array();
 
     if (empty($componentIDs)) {
@@ -1663,7 +1676,7 @@ FROM   civicrm_domain
     $query = "
 SELECT contact_id
   FROM $tableName
- WHERE id IN ( $IDs )
+ WHERE $idField IN ( $IDs )
 ";
 
     $dao = CRM_Core_DAO::executeQuery($query);