Merge branch 4.6 into master
[civicrm-core.git] / CRM / Utils / Migrate / ExportJSON.php
index 539f8a311e5b97806aad067f74764918e234cf01..7e682b2b326a2c2476ba13a143ba7623f0e7572c 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -60,7 +60,7 @@ class CRM_Utils_Migrate_ExportJSON {
   }
 
   /**
-   * Split a large array of contactIDs into more manageable smaller chunks
+   * Split a large array of contactIDs into more manageable smaller chunks.
    */
   public function &splitContactIDs(&$contactIDs) {
     // contactIDs could be a real large array, so we split it up into
@@ -89,7 +89,7 @@ class CRM_Utils_Migrate_ExportJSON {
   }
 
   /**
-   * Given a set of contact IDs get the values
+   * Given a set of contact IDs get the values.
    */
   public function getValues(&$contactIDs, &$additionalContactIDs) {
 
@@ -142,7 +142,7 @@ class CRM_Utils_Migrate_ExportJSON {
    */
   public function auxTable($tables) {
     foreach ($tables as $tableName => $daoName) {
-      $fields = & $this->dbFields($daoName, TRUE);
+      $fields = &$this->dbFields($daoName, TRUE);
 
       $sql = "SELECT * from $tableName";
       $this->sql($sql, $tableName, $fields);
@@ -165,7 +165,7 @@ SELECT *
 FROM   civicrm_option_group
 WHERE  name IN ( $nameString )
 ";
-    $fields = & $this->dbFields('CRM_Core_DAO_OptionGroup', TRUE);
+    $fields = &$this->dbFields('CRM_Core_DAO_OptionGroup', TRUE);
     $this->sql($sql, 'civicrm_option_group', $fields);
 
     $sql = "
@@ -174,7 +174,7 @@ FROM       civicrm_option_value v
 INNER JOIN civicrm_option_group g ON v.option_group_id = g.id
 WHERE      g.name IN ( $nameString )
 ";
-    $fields = & $this->dbFields('CRM_Core_DAO_OptionValue', TRUE);
+    $fields = &$this->dbFields('CRM_Core_DAO_OptionValue', TRUE);
     $this->sql($sql, 'civicrm_option_value', $fields);
   }
 
@@ -185,11 +185,12 @@ WHERE      g.name IN ( $nameString )
    * @param $whereField
    * @param null $additionalWhereCond
    */
-  function table(&$ids,
-                 $tableName,
-                 &$fields,
-                 $whereField,
-                 $additionalWhereCond = NULL
+  public function table(
+    &$ids,
+    $tableName,
+    &$fields,
+    $whereField,
+    $additionalWhereCond = NULL
   ) {
     if (empty($ids)) {
       return;
@@ -216,7 +217,7 @@ SELECT *
    * @param $fields
    */
   public function sql($sql, $tableName, &$fields) {
-    $dao = & CRM_Core_DAO::executeQuery($sql);
+    $dao = &CRM_Core_DAO::executeQuery($sql);
 
     while ($dao->fetch()) {
       $value = array();
@@ -237,7 +238,7 @@ SELECT *
    * @param $contactIDs
    */
   public function contact(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Contact_DAO_Contact', TRUE);
+    $fields = &$this->dbFields('CRM_Contact_DAO_Contact', TRUE);
     $this->table($contactIDs, 'civicrm_contact', $fields, 'id', NULL);
   }
 
@@ -245,7 +246,7 @@ SELECT *
    * @param $contactIDs
    */
   public function note(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_Note', TRUE);
+    $fields = &$this->dbFields('CRM_Core_DAO_Note', TRUE);
     $this->table($contactIDs, 'civicrm_note', $fields, 'entity_id', "entity_table = 'civicrm_contact'");
   }
 
@@ -253,7 +254,7 @@ SELECT *
    * @param $contactIDs
    */
   public function phone(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_Phone', TRUE);
+    $fields = &$this->dbFields('CRM_Core_DAO_Phone', TRUE);
     $this->table($contactIDs, 'civicrm_phone', $fields, 'contact_id', NULL);
   }
 
@@ -261,7 +262,7 @@ SELECT *
    * @param $contactIDs
    */
   public function email(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_Email', TRUE);
+    $fields = &$this->dbFields('CRM_Core_DAO_Email', TRUE);
     $this->table($contactIDs, 'civicrm_email', $fields, 'contact_id', NULL);
   }
 
@@ -269,7 +270,7 @@ SELECT *
    * @param $contactIDs
    */
   public function im(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_IM', TRUE);
+    $fields = &$this->dbFields('CRM_Core_DAO_IM', TRUE);
     $this->table($contactIDs, 'civicrm_im', $fields, 'contact_id', NULL);
   }
 
@@ -277,7 +278,7 @@ SELECT *
    * @param $contactIDs
    */
   public function website(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_Website', TRUE);
+    $fields = &$this->dbFields('CRM_Core_DAO_Website', TRUE);
     $this->table($contactIDs, 'civicrm_website', $fields, 'contact_id', NULL);
   }
 
@@ -285,7 +286,7 @@ SELECT *
    * @param $contactIDs
    */
   public function address(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_Email', TRUE);
+    $fields = &$this->dbFields('CRM_Core_DAO_Email', TRUE);
     $this->table($contactIDs, 'civicrm_address', $fields, 'contact_id', NULL);
   }
 
@@ -293,13 +294,13 @@ SELECT *
    * @param $contactIDs
    */
   public function groupContact(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Contact_DAO_GroupContact', TRUE);
+    $fields = &$this->dbFields('CRM_Contact_DAO_GroupContact', TRUE);
     $this->table($contactIDs, 'civicrm_group_contact', $fields, 'contact_id', NULL);
   }
 
-  // TODO - support group inheritance
-  // Parent child group ids are encoded in a text string
   /**
+   * TODO - support group inheritance
+   * Parent child group ids are encoded in a text string
    * @param $contactIDs
    */
   public function group(&$contactIDs) {
@@ -322,14 +323,14 @@ WHERE  contact_id IN ( $ids )
       }
     }
 
-    $fields = & $this->dbFields('CRM_Contact_DAO_Group', TRUE);
+    $fields = &$this->dbFields('CRM_Contact_DAO_Group', TRUE);
     $this->table($groupIDs, 'civicrm_group', $fields, 'id');
 
     $this->savedSearch($groupIDs);
   }
 
-  // TODO - support search builder and custom saved searches
   /**
+   * TODO - support search builder and custom saved searches
    * @param $groupIDs
    */
   public function savedSearch(&$groupIDs) {
@@ -345,7 +346,7 @@ INNER JOIN civicrm_group g on g.saved_search_id = s.id
 WHERE      g.id IN ( $idString )
 ";
 
-    $fields = & $this->dbFields('CRM_Contact_DAO_SavedSearch', TRUE);
+    $fields = &$this->dbFields('CRM_Contact_DAO_SavedSearch', TRUE);
     $this->sql($sql, 'civicrm_saved_search', $fields);
   }
 
@@ -353,7 +354,7 @@ WHERE      g.id IN ( $idString )
    * @param $contactIDs
    */
   public function entityTag(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_EntityTag', TRUE);
+    $fields = &$this->dbFields('CRM_Core_DAO_EntityTag', TRUE);
     $this->table($contactIDs, 'civicrm_entity_tag', $fields, 'entity_id', "entity_table = 'civicrm_contact'");
   }
 
@@ -381,7 +382,7 @@ AND    entity_table = 'civicrm_contact'
       }
     }
 
-    $fields = & $this->dbFields('CRM_Core_DAO_Tag', TRUE);
+    $fields = &$this->dbFields('CRM_Core_DAO_Tag', TRUE);
     $this->table($tagIDs, 'civicrm_tag', $fields, 'id');
   }
 
@@ -407,7 +408,7 @@ AND    entity_table = 'civicrm_contact'
 ";
 
     $fields = $this->dbFields('CRM_Contact_DAO_Relationship', TRUE);
-    $dao = & CRM_Core_DAO::executeQuery($sql);
+    $dao = &CRM_Core_DAO::executeQuery($sql);
     while ($dao->fetch()) {
       if (isset($_relationshipsHandled[$dao->id])) {
         continue;
@@ -455,9 +456,9 @@ WHERE ac.contact_id IN ( $ids )
   AND (a.activity_type_id != 3 AND a.activity_type_id != 20)
 ";
 
-    $fields = & $this->dbFields('CRM_Activity_DAO_Activity', TRUE);
+    $fields = &$this->dbFields('CRM_Activity_DAO_Activity', TRUE);
 
-    $dao = & CRM_Core_DAO::executeQuery($sql);
+    $dao = &CRM_Core_DAO::executeQuery($sql);
     while ($dao->fetch()) {
       // adding source, target and assignee contacts in additional contacts array
       $this->addAdditionalContacts(array($dao->contact_id),
@@ -469,7 +470,7 @@ WHERE ac.contact_id IN ( $ids )
         'id' => $dao->acID,
         'contact_id' => $dao->contact_id,
         'activity_id' => $dao->activity_id,
-        'record_type_id' => $dao->record_type_id
+        'record_type_id' => $dao->record_type_id,
       );
       $this->appendValue($dao->acID, 'civicrm_activity_contact', $activityContacts);
 
@@ -523,12 +524,12 @@ WHERE ac.contact_id IN ( $ids )
     if (!isset($_fieldsRetrieved[$daoName])) {
       $_fieldsRetrieved[$daoName] = array();
       $daoFile = str_replace('_',
-        DIRECTORY_SEPARATOR,
-        $daoName
-      ) . '.php';
-      include_once ($daoFile);
+          DIRECTORY_SEPARATOR,
+          $daoName
+        ) . '.php';
+      include_once $daoFile;
 
-      $daoFields = & $daoName::fields();
+      $daoFields = &$daoName::fields();
 
       foreach ($daoFields as $key => & $value) {
         $_fieldsRetrieved[$daoName][$value['name']] = array(
@@ -570,7 +571,7 @@ WHERE ac.contact_id IN ( $ids )
    * @param $contactIDs
    */
   public function export(&$contactIDs) {
-    $chunks = & $this->splitContactIDs($contactIDs);
+    $chunks = &$this->splitContactIDs($contactIDs);
 
     $additionalContactIDs = array();
 
@@ -589,9 +590,10 @@ WHERE ac.contact_id IN ( $ids )
    * @param null $lastExportTime
    * @param bool $discoverContacts
    */
-  function run($fileName,
-               $lastExportTime = NULL,
-               $discoverContacts = FALSE
+  public function run(
+    $fileName,
+    $lastExportTime = NULL,
+    $discoverContacts = FALSE
   ) {
     $this->_discoverContacts = $discoverContacts;
 
@@ -615,8 +617,7 @@ WHERE  date >= $lastExportTime
 ";
     }
 
-
-    $dao = & CRM_Core_DAO::executeQuery($sql);
+    $dao = &CRM_Core_DAO::executeQuery($sql);
 
     $contactIDs = array();
     while ($dao->fetch()) {
@@ -637,4 +638,5 @@ WHERE  date >= $lastExportTime
 
     // print_r( json_decode( $json ) );
   }
+
 }