Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
justinfreeman (Agileware)
Core
Commits
42d58fac
Commit
42d58fac
authored
11 years ago
by
pratik.joshi
Browse files
Options
Downloads
Patches
Plain Diff
cRM-13718
parent
46c53d72
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Utils/Migrate/ExportJSON.php
+23
-58
23 additions, 58 deletions
CRM/Utils/Migrate/ExportJSON.php
CRM/Utils/Migrate/ImportJSON.php
+18
-19
18 additions, 19 deletions
CRM/Utils/Migrate/ImportJSON.php
with
41 additions
and
77 deletions
CRM/Utils/Migrate/ExportJSON.php
+
23
−
58
View file @
42d58fac
...
...
@@ -378,34 +378,39 @@ AND entity_table = 'civicrm_contact'
$activityContacts
=
CRM_Core_OptionGroup
::
values
(
'activity_contacts'
,
FALSE
,
FALSE
,
FALSE
,
NULL
,
'name'
);
$assigneeID
=
CRM_Utils_Array
::
key
(
'Activity Assignees'
,
$activityContacts
);
$targetID
=
CRM_Utils_Array
::
key
(
'Activity Targets'
,
$activityContacts
);
$ids
=
implode
(
','
,
$contactIDs
);
$sql
=
"(
SELECT a.*
FROM civicrm_activity a
INNER JOIN civicrm_activity_contact aa ON aa.activity_id = a.id AND aa.record_type_id =
$assigneeID
WHERE aa.contact_id IN (
$ids
)
AND ( a.activity_type_id != 3 AND a.activity_type_id != 20 )
) UNION (
SELECT a.*
FROM civicrm_activity a
INNER JOIN civicrm_activity_contact at ON at.activity_id = a.id AND at.record_type_id =
$targetID
WHERE at.contact_id IN (
$ids
)
AND ( a.activity_type_id != 3 AND a.activity_type_id != 20 )
)
// query framing returning all contacts in valid activity
$sql
=
"
SELECT a.*, ac.id as acID, ac.activity_id, ac.contact_id, ac.record_type_id
FROM civicrm_activity a
INNER JOIN civicrm_activity_contact ac ON ac.activity_id = a.id
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
);
$activityIDs
=
array
();
$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
),
$additionalContacts
);
// append values of activity contacts
$activityContacts
=
array
(
'id'
=>
$dao
->
acID
,
'contact_id'
=>
$dao
->
contact_id
,
'activity_id'
=>
$dao
->
activity_id
,
'record_type_id'
=>
$dao
->
record_type_id
);
$this
->
appendValue
(
$dao
->
acID
,
'civicrm_activity_contact'
,
$activityContacts
);
if
(
isset
(
$_activitiesHandled
[
$dao
->
id
]))
{
continue
;
}
$_activitiesHandled
[
$dao
->
id
]
=
$dao
->
id
;
$activityIDs
[]
=
$dao
->
id
;
$activity
=
array
();
foreach
(
$fields
as
$fld
)
{
...
...
@@ -417,50 +422,10 @@ AND entity_table = 'civicrm_contact'
}
}
// append activity value
$this
->
appendValue
(
$dao
->
id
,
'civicrm_activity'
,
$activity
);
$this
->
addAdditionalContacts
(
array
(
$dao
->
source_contact_id
),
$additionalContacts
);
}
$dao
->
free
();
if
(
empty
(
$activityIDs
))
{
return
;
}
$activityIDString
=
implode
(
","
,
$activityIDs
);
// now get all assignee contact ids and target contact ids for this activity
$sql
=
"SELECT * FROM civicrm_activity_contact WHERE activity_id IN (
$activityIDString
) AND record_type = 'Assignee'"
;
$aaDAO
=
&
CRM_Core_DAO
::
executeQuery
(
$sql
);
$activityContacts
=
array
();
while
(
$aaDAO
->
fetch
())
{
$activityAssignee
=
array
(
'id'
=>
$aaDAO
->
id
,
'assignee_contact_id'
=>
$aaDAO
->
assignee_contact_id
,
'activity_id'
=>
$aaDAO
->
activity_id
,
);
$this
->
appendValue
(
$aaDAO
->
id
,
'civicrm_activity_assignment'
,
$activityAssignee
);
$activityContacts
[]
=
$aaDAO
->
assignee_contact_id
;
}
$aaDAO
->
free
();
$sql
=
"SELECT * FROM civicrm_activity_contact WHERE activity_id IN (
$activityIDString
) AND record_type = 'Target'"
;
$atDAO
=
&
CRM_Core_DAO
::
executeQuery
(
$sql
);
while
(
$atDAO
->
fetch
())
{
$activityTarget
=
array
(
'id'
=>
$atDAO
->
id
,
'target_contact_id'
=>
$atDAO
->
target_contact_id
,
'activity_id'
=>
$atDAO
->
activity_id
,
);
$this
->
appendValue
(
$atDAO
->
id
,
'civicrm_activity_target'
,
$activityTarget
);
$activityContacts
[]
=
$atDAO
->
target_contact_id
;
}
$atDAO
->
free
();
$this
->
addAdditionalContacts
(
$activityContacts
,
$additionalContacts
);
}
function
appendValue
(
$id
,
$name
,
$value
)
{
...
...
@@ -581,7 +546,7 @@ WHERE date >= $lastExportTime
$json
);
//
print_r( json_decode( $json ) );
print_r
(
json_decode
(
$json
)
);
}
}
This diff is collapsed.
Click to expand it.
CRM/Utils/Migrate/ImportJSON.php
+
18
−
19
View file @
42d58fac
...
...
@@ -56,8 +56,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
...
...
@@ -73,7 +72,8 @@ class CRM_Utils_Migrate_ImportJSON {
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'
)
);
}
...
...
@@ -101,7 +101,8 @@ class CRM_Utils_Migrate_ImportJSON {
function
note
(
&
$note
)
{
$this
->
restore
(
$note
,
'CRM_Core_DAO_Note'
,
array
(
'contact_id'
=>
'civicrm_contact'
)
array
(
'contact_id'
=>
'civicrm_contact'
),
array
(
'modified_date'
)
);
}
...
...
@@ -115,24 +116,17 @@ class CRM_Utils_Migrate_ImportJSON {
);
}
function
activity
(
$activity
,
$activity
Target
,
$activityAssignment
)
{
function
activity
(
$activity
,
$activity
Contacts
)
{
$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
(
$activity
Assignment
,
'CRM_Activity_DAO_Activity
Assignmen
t'
,
$this
->
restore
(
$activity
Contacts
,
'CRM_Activity_DAO_Activity
Contac
t'
,
array
(
'
assignee_
contact_id'
=>
'civicrm_contact'
,
'contact_id'
=>
'civicrm_contact'
,
'activity_id'
=>
'civicrm_activity'
,
)
);
...
...
@@ -140,7 +134,9 @@ class CRM_Utils_Migrate_ImportJSON {
function
group
(
$group
,
$groupContact
)
{
$this
->
restore
(
$group
,
'CRM_Contact_DAO_Group'
'CRM_Contact_DAO_Group'
,
NULL
,
array
(
'cache_date'
,
'refresh_date'
)
);
$this
->
restore
(
$groupContact
,
...
...
@@ -170,7 +166,7 @@ class CRM_Utils_Migrate_ImportJSON {
);
}
function
restore
(
&
$chunk
,
$daoName
,
$lookUpMapping
=
NULL
)
{
function
restore
(
&
$chunk
,
$daoName
,
$lookUpMapping
=
NULL
,
$dateFields
=
NULL
)
{
$object
=
new
$daoName
();
$tableName
=
$object
->
__table
;
...
...
@@ -205,6 +201,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
];
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment