Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CiviCRM Zapier Integration
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Extensions
CiviCRM Zapier Integration
Commits
8164001c
Commit
8164001c
authored
10 months ago
by
Jitendra Purohit
Browse files
Options
Downloads
Patches
Plain Diff
Fix entity to be triggerred without being the main entity in civirule
parent
c5e62a19
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/CivirulesActions/Zapier/Trigger.php
+12
-7
12 additions, 7 deletions
CRM/CivirulesActions/Zapier/Trigger.php
CRM/Zapier/Utils.php
+34
-33
34 additions, 33 deletions
CRM/Zapier/Utils.php
with
46 additions
and
40 deletions
CRM/CivirulesActions/Zapier/Trigger.php
+
12
−
7
View file @
8164001c
...
...
@@ -12,26 +12,31 @@ class CRM_CivirulesActions_Zapier_Trigger extends CRM_Civirules_Action {
*/
public
function
processAction
(
CRM_Civirules_TriggerData_TriggerData
$triggerData
)
{
$params
=
$this
->
getActionParameters
();
$entity
=
$triggerData
->
getEntity
();
$entityParams
=
[
'Contact'
=>
[
'*'
,
'custom.*'
,
'address_primary.*'
,
'email_primary.*'
,
'phone_primary.*'
],
'Membership'
=>
[
'*'
,
'custom.*'
,
'contact_id.*'
],
'Participant'
=>
[
'*'
,
'custom.*'
,
'contact_id.*'
,
'event_id.*'
],
];
if
(
isset
(
$entityParams
[
$entity
]))
{
$entityData
=
$triggerData
->
getEntityData
(
$entity
);
$actionEntity
=
CRM_Zapier_Utils
::
getZapActionEntity
(
$params
[
'zap_trigger'
]);
$apiValues
=
civicrm_api4
(
$entity
,
'get'
,
[
'select'
=>
$entityParams
[
$entity
],
if
(
isset
(
$entityParams
[
$actionEntity
]))
{
$entityData
=
$triggerData
->
getEntityData
(
$actionEntity
);
if
(
empty
(
$entityData
[
'id'
]))
{
return
;
}
$apiParams
=
[
'select'
=>
$entityParams
[
$actionEntity
],
'checkPermissions'
=>
FALSE
,
'where'
=>
[
[
'id'
,
'='
,
$entityData
[
'id'
]],
],
])
->
first
();
];
$apiValues
=
civicrm_api4
(
$actionEntity
,
'get'
,
$apiParams
)
->
first
();
$hookURL
=
CRM_Zapier_Utils
::
getZapHook
(
$params
[
'zap_trigger'
]);
if
(
!
empty
(
$hookURL
)
&&
!
empty
(
$apiValues
))
{
CRM_Zapier_Utils
::
triggerZap
(
'POST'
,
$hookURL
,
$apiValues
);
CRM_Zapier_Utils
::
triggerZap
(
$hookURL
,
$apiValues
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
CRM/Zapier/Utils.php
+
34
−
33
View file @
8164001c
...
...
@@ -6,16 +6,24 @@ class CRM_Zapier_Utils {
* Returns a list of zap options
*
* @return array
* @throws \CiviCRM_API3_Exception
*/
public
static
function
getZapOptions
()
{
return
[
'create_contact'
=>
'Create Contact'
,
'update_participant'
=>
'Update Participant'
,
'membership_created'
=>
'Create Membership'
,
'create_contact'
=>
ts
(
'Create Contact'
)
,
'update_participant'
=>
ts
(
'Update Participant'
)
,
'membership_created'
=>
ts
(
'Create Membership'
)
,
];
}
public
static
function
getZapActionEntity
(
$name
)
{
$actions
=
[
'create_contact'
=>
'Contact'
,
'update_participant'
=>
'Participant'
,
'membership_created'
=>
'Membership'
,
];
return
$actions
[
$name
]
??
NULL
;
}
/**
* Save hook URLs in the database.
*/
...
...
@@ -56,18 +64,26 @@ class CRM_Zapier_Utils {
}
public
static
function
unserialize_recursive
(
$val
)
{
//$pattern = "/.*\{(.*)\}/";
if
(
self
::
is_serialized
(
$val
)){
//
$pattern = "/.*\{(.*)\}/";
if
(
self
::
is_serialized
(
$val
)){
$val
=
trim
(
$val
);
$ret
=
unserialize
(
$val
);
if
(
is_array
(
$ret
))
{
foreach
(
$ret
as
&
$r
)
$r
=
self
::
unserialize_recursive
(
$r
);
foreach
(
$ret
as
&
$r
)
{
$r
=
self
::
unserialize_recursive
(
$r
);
}
}
return
$ret
;
}
elseif
(
is_array
(
$val
))
{
foreach
(
$val
as
&
$r
)
$r
=
self
::
unserialize_recursive
(
$r
);
}
elseif
(
is_array
(
$val
))
{
foreach
(
$val
as
&
$r
)
{
$r
=
self
::
unserialize_recursive
(
$r
);
}
return
$val
;
}
else
{
return
$val
;
}
else
{
return
$val
;
}
}
}
public
static
function
is_serialized
(
$val
)
{
...
...
@@ -78,34 +94,19 @@ class CRM_Zapier_Utils {
return
false
;
}
/**
*
* @param $method
* @param $url
* @param $data
*/
public
static
function
triggerZap
(
$method
,
$url
,
$data
=
[])
{
public
static
function
triggerZap
(
$url
,
$data
=
[])
{
$curl
=
curl_init
();
switch
(
$method
)
{
case
"POST"
:
curl_setopt
(
$curl
,
CURLOPT_POST
,
1
);
if
(
$data
)
{
if
(
is_array
(
$data
))
{
$data
=
http_build_query
(
$data
);
}
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
$data
);
}
break
;
case
"PUT"
:
curl_setopt
(
$curl
,
CURLOPT_PUT
,
1
);
break
;
default
:
if
(
$data
)
$url
=
sprintf
(
"%s?%s"
,
$url
,
http_build_query
(
$data
));
curl_setopt
(
$curl
,
CURLOPT_POST
,
1
);
if
(
$data
)
{
if
(
is_array
(
$data
))
{
$data
=
http_build_query
(
$data
);
}
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
$data
);
}
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
...
...
@@ -118,4 +119,4 @@ class CRM_Zapier_Utils {
return
json_decode
(
$result
);
}
}
\ No newline at end of file
}
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