Merge pull request #4375 from totten/master-mysqli-compat
[civicrm-core.git] / CRM / Utils / Migrate / ImportJSON.php
index 40cc321cd8d05ca7950223b4dbf1e90fb7d8d8aa..2de4dced64eb0ad381fd735f9754d573fd532293 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -38,11 +38,17 @@ class CRM_Utils_Migrate_ImportJSON {
 
   protected $_saveMapping;
 
+  /**
+   *
+   */
   function __construct() {
     $this->_lookupCache = array();
     $this->_saveMapping = array();
   }
 
+  /**
+   * @param $file
+   */
   function run($file) {
     $json = file_get_contents($file);
 
@@ -56,8 +62,7 @@ class CRM_Utils_Migrate_ImportJSON {
     $this->note($decodedContacts->civicrm_note);
     $this->relationship($decodedContacts->civicrm_relationship);
     $this->activity($decodedContacts->civicrm_activity,
-      $decodedContacts->civicrm_activity_target,
-      $decodedContacts->civicrm_activity_assignment
+      $decodedContacts->civicrm_activity_contact
     );
     $this->group($decodedContacts->civicrm_group,
       $decodedContacts->civicrm_group_contact
@@ -70,13 +75,20 @@ class CRM_Utils_Migrate_ImportJSON {
     CRM_Core_Config::clearDBCache();
   }
 
+  /**
+   * @param $contact
+   */
   function contact(&$contact) {
     $this->restore($contact,
       'CRM_Contact_DAO_Contact',
-      array('id' => 'civicrm_contact')
+      array('id' => 'civicrm_contact'),
+      array('birth_date', 'deceased_date', 'created_date', 'modified_date')
     );
   }
 
+  /**
+   * @param $email
+   */
   function email(&$email) {
     $this->restore($email,
       'CRM_Core_DAO_Email',
@@ -84,6 +96,9 @@ class CRM_Utils_Migrate_ImportJSON {
     );
   }
 
+  /**
+   * @param $phone
+   */
   function phone(&$phone) {
     $this->restore($phone,
       'CRM_Core_DAO_Phone',
@@ -91,6 +106,9 @@ class CRM_Utils_Migrate_ImportJSON {
     );
   }
 
+  /**
+   * @param $address
+   */
   function address(&$address) {
     $this->restore($address,
       'CRM_Core_DAO_Address',
@@ -98,13 +116,20 @@ class CRM_Utils_Migrate_ImportJSON {
     );
   }
 
+  /**
+   * @param $note
+   */
   function note(&$note) {
     $this->restore($note,
       'CRM_Core_DAO_Note',
-      array('contact_id' => 'civicrm_contact')
+      array('contact_id' => 'civicrm_contact'),
+      array('modified_date')
     );
   }
 
+  /**
+   * @param $relationship
+   */
   function relationship(&$relationship) {
     $this->restore($relationship,
       'CRM_Contact_DAO_Relationship',
@@ -115,32 +140,35 @@ class CRM_Utils_Migrate_ImportJSON {
     );
   }
 
-  function activity($activity, $activityTarget, $activityAssignment) {
+  /**
+   * @param $activity
+   * @param $activityContacts
+   */
+  function activity($activity, $activityContacts) {
     $this->restore($activity,
       'CRM_Activity_DAO_Activity',
-      array('source_contact_id' => 'civicrm_contact')
-    );
-
-    $this->restore($activityTarget,
-      'CRM_Activity_DAO_ActivityTarget',
-      array(
-        'target_contact_id' => 'civicrm_contact',
-        'activity_id' => 'civicrm_activity',
-      )
+      NULL,
+      array('activity_date_time')
     );
 
-    $this->restore($activityAssignment,
-      'CRM_Activity_DAO_ActivityAssignment',
+    $this->restore($activityContacts,
+      'CRM_Activity_DAO_ActivityContact',
       array(
-        'assignee_contact_id' => 'civicrm_contact',
+        'contact_id' => 'civicrm_contact',
         'activity_id' => 'civicrm_activity',
       )
     );
   }
 
+  /**
+   * @param $group
+   * @param $groupContact
+   */
   function group($group, $groupContact) {
     $this->restore($group,
-      'CRM_Contact_DAO_Group'
+      'CRM_Contact_DAO_Group',
+      NULL,
+      array('cache_date', 'refresh_date')
     );
 
     $this->restore($groupContact,
@@ -152,6 +180,10 @@ class CRM_Utils_Migrate_ImportJSON {
     );
   }
 
+  /**
+   * @param $tag
+   * @param $entityTag
+   */
   function tag($tag, $entityTag) {
     $this->restore($tag,
       'CRM_Core_DAO_Tag',
@@ -170,7 +202,13 @@ class CRM_Utils_Migrate_ImportJSON {
     );
   }
 
-  function restore(&$chunk, $daoName, $lookUpMapping = NULL) {
+  /**
+   * @param $chunk
+   * @param string $daoName
+   * @param null $lookUpMapping
+   * @param null $dateFields
+   */
+  function restore(&$chunk, $daoName, $lookUpMapping = NULL, $dateFields = NULL) {
     $object   = new $daoName();
     $tableName = $object->__table;
 
@@ -205,6 +243,9 @@ class CRM_Utils_Migrate_ImportJSON {
             if (array_key_exists($column, $lookUpMapping)) {
               $object->$column = $this->_lookupCache[$lookUpMapping[$column]][$value[$k]];
             }
+            elseif (!empty($dateFields) && in_array($column, $dateFields)) {
+              $object->$column = CRM_Utils_Date::isoToMysql($value[$k]);
+            }
             else {
               $object->$column = $value[$k];
             }
@@ -238,6 +279,9 @@ class CRM_Utils_Migrate_ImportJSON {
     }
   }
 
+  /**
+   * @param string $tableName
+   */
   function populateCache($tableName) {
     if (isset($this->_lookupCache[$tableName])) {
       return;