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
481e3493
Commit
481e3493
authored
11 years ago
by
Kurund Jalmi
Browse files
Options
Downloads
Plain Diff
Merge pull request #1348 from pratik-joshi/CRM-12689_fixes
Crm 12689 fixes
parents
7eba45dc
3874157e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CRM/Core/BAO/ActionSchedule.php
+101
-40
101 additions, 40 deletions
CRM/Core/BAO/ActionSchedule.php
with
101 additions
and
40 deletions
CRM/Core/BAO/ActionSchedule.php
+
101
−
40
View file @
481e3493
...
...
@@ -214,7 +214,6 @@ class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule {
}
}
return
array
(
'sel1'
=>
$sel1
,
'sel2'
=>
$sel2
,
...
...
@@ -583,7 +582,7 @@ WHERE cas.entity_value = $id AND
$session
=
CRM_Core_Session
::
singleton
();
while
(
$actionSchedule
->
fetch
())
{
$extraSelect
=
$extraJoin
=
$extraWhere
=
''
;
$extraSelect
=
$extraJoin
=
$extraWhere
=
$extraOn
=
''
;
if
(
$actionSchedule
->
record_activity
)
{
if
(
$mapping
->
entity
==
'civicrm_membership'
)
{
...
...
@@ -606,12 +605,11 @@ WHERE cas.entity_value = $id AND
$extraJoin
=
"
INNER JOIN civicrm_option_group og ON og.name = 'activity_type'
INNER JOIN civicrm_option_value ov ON e.activity_type_id = ov.value AND ov.option_group_id = og.id"
;
$extra
Where
=
'AND e.is_current_revision = 1 AND e.is_deleted = 0'
;
$extra
On
=
'
AND e.is_current_revision = 1 AND e.is_deleted = 0
'
;
if
(
$actionSchedule
->
limit_to
==
0
)
{
$extraJoin
=
"
LEFT JOIN civicrm_option_group og ON og.name = 'activity_type'
LEFT JOIN civicrm_option_value ov ON e.activity_type_id = ov.value AND ov.option_group_id = og.id"
;
$extraWhere
=
''
;
}
}
...
...
@@ -662,6 +660,7 @@ LEFT JOIN civicrm_phone phone ON phone.id = lb.phone_id
$entityJoinClause
=
"LEFT JOIN
{
$mapping
->
entity
}
e ON e.id = reminder.entity_id"
;
$extraWhere
.
=
" AND (e.id = reminder.entity_id OR reminder.entity_table = 'civicrm_contact')"
;
}
$entityJoinClause
.
=
$extraOn
;
$query
=
"
SELECT reminder.id as reminderID, reminder.contact_id as contactID, reminder.*, e.id as entityID, e.*
{
$extraSelect
}
...
...
@@ -765,7 +764,11 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL
$mapping
->
id
=
$mappingID
;
$mapping
->
find
(
TRUE
);
$select
=
$join
=
$where
=
array
();
// note: $where - this filtering applies for both
// 'limit to' and 'addition to' options
// $limitWhere - this filtering applies only for
// 'limit to' option
$select
=
$join
=
$where
=
$limitWhere
=
array
();
$limitTo
=
$actionSchedule
->
limit_to
;
$value
=
explode
(
CRM_Core_DAO
::
VALUE_SEPARATOR
,
trim
(
$actionSchedule
->
entity_value
,
CRM_Core_DAO
::
VALUE_SEPARATOR
)
...
...
@@ -790,20 +793,25 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL
$assigneeID
=
CRM_Utils_Array
::
key
(
'Activity Assignees'
,
$activityContacts
);
$targetID
=
CRM_Utils_Array
::
key
(
'Activity Targets'
,
$activityContacts
);
switch
(
CRM_Utils_Array
::
value
(
$actionSchedule
->
recipient
,
$recipientOptions
))
{
case
'Activity Assignees'
:
$join
[]
=
"INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id =
{
$assigneeID
}
"
;
break
;
case
'Activity Source'
:
$join
[]
=
"INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id =
{
$sourceID
}
"
;
break
;
if
(
$limitTo
==
0
)
{
// including the activity target contacts if 'in addition' is defined
$join
[]
=
"INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id =
{
$targetID
}
"
;
}
else
{
switch
(
CRM_Utils_Array
::
value
(
$actionSchedule
->
recipient
,
$recipientOptions
))
{
case
'Activity Assignees'
:
$join
[]
=
"INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id =
{
$assigneeID
}
"
;
break
;
default
:
case
'Activity Targets'
:
$join
[]
=
"INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id =
{
$targetID
}
"
;
break
;
case
'Activity Source'
:
$join
[]
=
"INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id =
{
$sourceID
}
"
;
break
;
default
:
case
'Activity Targets'
:
$join
[]
=
"INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id =
{
$targetID
}
"
;
break
;
}
}
// build where clause
if
(
!
empty
(
$value
))
{
...
...
@@ -825,7 +833,7 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL
$table
=
'civicrm_event r'
;
$contactField
=
'e.contact_id'
;
$join
[]
=
'INNER JOIN civicrm_event r ON e.event_id = r.id'
;
if
(
$actionSchedule
->
recipient_listing
)
{
if
(
$actionSchedule
->
recipient_listing
&&
$limitTo
)
{
$rList
=
explode
(
CRM_Core_DAO
::
VALUE_SEPARATOR
,
trim
(
$actionSchedule
->
recipient_listing
,
CRM_Core_DAO
::
VALUE_SEPARATOR
)
);
...
...
@@ -849,8 +857,10 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL
$where
[]
=
(
$mapping
->
entity_value
==
'event_type'
)
?
"r.event_type_id IS NULL"
:
"r.id IS NULL"
;
}
// participant status criteria not to be implemented
// for additional recipients
if
(
!
empty
(
$status
))
{
$
w
here
[]
=
"e.status_id IN (
{
$status
}
)"
;
$
limitW
here
[]
=
"e.status_id IN (
{
$status
}
)"
;
}
$where
[]
=
'r.is_active = 1'
;
...
...
@@ -886,8 +896,8 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL
$membershipStatus
=
CRM_Member_PseudoConstant
::
membershipStatus
(
NULL
,
"(is_current_member = 1 OR name = 'Expired')"
,
'id'
);
$mStatus
=
implode
(
','
,
$membershipStatus
);
$where
[]
=
"e.status_id IN (
{
$mStatus
}
)"
;
}
if
(
$limitTo
)
{
if
(
$actionSchedule
->
group_id
)
{
$join
[]
=
"INNER JOIN civicrm_group_contact grp ON
{
$contactField
}
= grp.contact_id AND grp.status = 'Added'"
;
...
...
@@ -909,6 +919,7 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL
$addWhere
=
"c.id IN (
{
$rList
}
)"
;
}
}
$select
[]
=
"
{
$contactField
}
as contact_id"
;
$select
[]
=
'e.id as entity_id'
;
$select
[]
=
"'
{
$mapping
->
entity
}
' as entity_table"
;
...
...
@@ -947,32 +958,51 @@ reminder.action_schedule_id = %1";
$fromClause
=
"FROM
$from
"
;
$joinClause
=
!
empty
(
$join
)
?
implode
(
' '
,
$join
)
:
''
;
$whereClause
=
'WHERE '
.
implode
(
' AND '
,
$where
);
$union
=
''
;
if
(
$limitTo
==
0
)
{
$union
=
"
UNION
SELECT c.id as contact_id, c.id as entity_id, 'civicrm_contact' as entity_table,
{
$actionSchedule
->
id
}
as action_schedule_id
FROM (civicrm_contact c,
{
$table
}
)
LEFT JOIN civicrm_action_log reminder ON reminder.contact_id = c.id AND
reminder.entity_id = c.id AND
reminder.entity_table = 'civicrm_contact' AND
reminder.action_schedule_id =
{
$actionSchedule
->
id
}
{
$addGroup
}
WHERE (reminder.id IS NULL AND c.is_deleted = 0 AND c.is_deceased = 0 AND
{
$addWhere
}
) AND
{
$dateClause
}
"
;
}
$limitWhereClause
=
''
;
if
(
!
empty
(
$limitWhere
))
{
$limitWhereClause
=
' AND '
.
implode
(
' AND '
,
$limitWhere
);
}
$query
=
"
INSERT INTO civicrm_action_log (contact_id, entity_id, entity_table, action_schedule_id)
{
$selectClause
}
{
$fromClause
}
{
$joinClause
}
LEFT JOIN
{
$reminderJoinClause
}
{
$whereClause
}
AND
{
$dateClause
}
{
$notINClause
}
{
$union
}
"
;
{
$whereClause
}
{
$limitWhereClause
}
AND
{
$dateClause
}
{
$notINClause
}
"
;
CRM_Core_DAO
::
executeQuery
(
$query
,
array
(
1
=>
array
(
$actionSchedule
->
id
,
'Integer'
)));
if
(
$limitTo
==
0
)
{
$additionWhere
=
' WHERE '
;
if
(
$actionSchedule
->
start_action_date
)
{
$additionWhere
=
$whereClause
.
' AND '
;
}
$contactTable
=
"civicrm_contact c"
;
$addSelect
=
"SELECT c.id as contact_id, c.id as entity_id, 'civicrm_contact' as entity_table,
{
$actionSchedule
->
id
}
as action_schedule_id"
;
$additionReminderClause
=
"civicrm_action_log reminder ON reminder.contact_id = c.id AND
reminder.entity_id = c.id AND
reminder.entity_table = 'civicrm_contact' AND
reminder.action_schedule_id =
{
$actionSchedule
->
id
}
"
;
$insertAdditionalSql
=
"
INSERT INTO civicrm_action_log (contact_id, entity_id, entity_table, action_schedule_id)
{
$addSelect
}
FROM (
{
$contactTable
}
,
{
$table
}
)
LEFT JOIN
{
$additionReminderClause
}
{
$addGroup
}
{
$additionWhere
}
c.is_deleted = 0 AND c.is_deceased = 0 AND
{
$addWhere
}
AND
{
$dateClause
}
AND c.id NOT IN (
SELECT rem.contact_id
FROM civicrm_action_log rem INNER JOIN
{
$mapping
->
entity
}
e ON rem.entity_id = e.id
WHERE rem.action_schedule_id =
{
$actionSchedule
->
id
}
AND rem.entity_table = '
{
$mapping
->
entity
}
'
)
GROUP BY c.id
"
;
CRM_Core_DAO
::
executeQuery
(
$insertAdditionalSql
);
}
// if repeat is turned ON:
if
(
$actionSchedule
->
is_repeat
)
{
$repeatEvent
=
(
$actionSchedule
->
end_action
==
'before'
?
'DATE_SUB'
:
'DATE_ADD'
)
.
"(
{
$dateField
}
, INTERVAL
{
$actionSchedule
->
end_frequency_interval
}
{
$actionSchedule
->
end_frequency_unit
}
)"
;
...
...
@@ -993,12 +1023,11 @@ LEFT JOIN {$reminderJoinClause}
$havingClause
=
"HAVING TIMEDIFF(
{
$now
}
, latest_log_time) >= TIME('
{
$hrs
}
:00:00')"
;
$groupByClause
=
'GROUP BY reminder.contact_id, reminder.entity_id, reminder.entity_table'
;
$selectClause
.
=
', MAX(reminder.action_date_time) as latest_log_time'
;
$sqlInsertValues
=
"
{
$selectClause
}
{
$fromClause
}
{
$joinClause
}
INNER JOIN
{
$reminderJoinClause
}
{
$whereClause
}
AND
{
$repeatEventClause
}
{
$whereClause
}
{
$limitWhereClause
}
AND
{
$repeatEventClause
}
{
$groupByClause
}
{
$havingClause
}
"
;
...
...
@@ -1016,6 +1045,38 @@ INNER JOIN {$reminderJoinClause}
INSERT INTO civicrm_action_log (contact_id, entity_id, entity_table, action_schedule_id) VALUES '
.
$valString
;
CRM_Core_DAO
::
executeQuery
(
$query
,
array
(
1
=>
array
(
$actionSchedule
->
id
,
'Integer'
)));
}
if
(
$limitTo
==
0
)
{
$addSelect
.
=
', MAX(reminder.action_date_time) as latest_log_time'
;
$sqlEndEventCheck
=
"
SELECT * FROM
{
$table
}
{
$whereClause
}
AND
{
$repeatEventClause
}
LIMIT 1"
;
$daoCheck
=
CRM_Core_DAO
::
executeQuery
(
$sqlEndEventCheck
);
if
(
$daoCheck
->
fetch
())
{
$valSqlAdditionInsert
=
"
{
$addSelect
}
FROM
{
$contactTable
}
{
$addGroup
}
INNER JOIN
{
$additionReminderClause
}
WHERE
{
$addWhere
}
AND c.is_deleted = 0 AND c.is_deceased = 0
GROUP BY reminder.contact_id
{
$havingClause
}
"
;
$daoForVals
=
CRM_Core_DAO
::
executeQuery
(
$valSqlAdditionInsert
);
$addValues
=
array
();
while
(
$daoForVals
->
fetch
())
{
$addValues
[]
=
"(
{
$daoForVals
->
contact_id
}
,
{
$daoForVals
->
entity_id
}
, '
{
$daoForVals
->
entity_table
}
',
{
$daoForVals
->
action_schedule_id
}
)"
;
}
$valString
=
implode
(
','
,
$addValues
);
if
(
$valString
)
{
$query
=
'
INSERT INTO civicrm_action_log (contact_id, entity_id, entity_table, action_schedule_id) VALUES '
.
$valString
;
CRM_Core_DAO
::
executeQuery
(
$query
);
}
}
}
}
}
}
...
...
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