Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Developer Documentation
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
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
brienne
Developer Documentation
Commits
fc521dca
Commit
fc521dca
authored
8 years ago
by
Sean Madsen
Browse files
Options
Downloads
Patches
Plain Diff
hook_civicrm_trigger_info - clean up after content import to close #83
parent
5dee4a74
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/hooks/hook_civicrm_trigger_info.md
+82
-120
82 additions, 120 deletions
docs/hooks/hook_civicrm_trigger_info.md
with
82 additions
and
120 deletions
docs/hooks/hook_civicrm_trigger_info.md
+
82
−
120
View file @
fc521dca
# hook_civicrm_trigger_info
# hook_civicrm_trigger_info
## Description
Define MYSQL Triggers. Using the hooks causes them not to clash with
Define MYSQL Triggers. Using the hooks causes them not to clash with
core or other extension triggers. They are compiled into one trigger
core or other extension triggers. They are compiled into one trigger
with core triggers.
with core triggers.
Once the function is create, a trigger rebuild will have to be done to
!!! note
create the new trigger
Once the function is created, visit the following URL to rebuild triggers
and create to create the new trigger:
http//yoursite/civicrm/menu/rebuild&reset=1&triggerRebuild=1
`http://example.com/civicrm/menu/rebuild&reset=1&triggerRebuild=1`
/**
* hook_civicrm_triggerInfo()
## Definition
*
```
php
hook_civicrm_triggerInfo
(
&
$info
,
$tableName
)
* Add trigger to update custom region field based on postcode (using a lookup table)
```
*
## Parameters
* Note that we have hard-coded a prioritisation of location types into this (since it's customer specific code
*
array
`$info`
- array of triggers to be created
*
string
`$tableName`
- not sure how this bit works
* and unlikely to change)
*
## Returns
* @param array $info (reference) array of triggers to be created
-
??
* @param string $tableName - not sure how this bit works
*
## Example
**/
Add trigger to update custom region field based on postcode (using a lookup
table)
Note that this example uses hard-coded a prioritisation of location types
function regionfields_civicrm_triggerInfo(&$info, $tableName) {
(since it was customer specific code and unlikely to change).
$table_name = 'civicrm_value_region_13';
```
php
function
regionfields_civicrm_triggerInfo
(
&
$info
,
$tableName
)
{
$customFieldID = 45;
$table_name
=
'civicrm_value_region_13'
;
$customFieldID
=
45
;
$columnName = 'region_45';
$columnName
=
'region_45'
;
$sourceTable
=
'civicrm_address'
;
$sourceTable = 'civicrm_address';
$locationPriorityOrder
=
'1, 3, 5, 2, 4, 6'
;
// hard coded prioritisation of addresses
$zipTable
=
'CANYRegion'
;
$locationPriorityOrder = '1, 3, 5, 2, 4, 6'; // hard coded prioritisation of addresses
if
(
civicrm_api3
(
'custom_field'
,
'getcount'
,
array
(
'id'
=>
$customFieldID
,
'column_name'
=>
'region_45'
,
'is_active'
=>
1
))
==
0
)
{
return
;
$zipTable = 'CANYRegion';
}
if(civicrm_api3('custom_field', 'getcount', array('id' => $customFieldID, 'column_name' => 'region_45', 'is_active' => 1)) == 0) {
$sql
=
"
REPLACE INTO `
$table_name
` (entity_id,
$columnName
)
return;
SELECT * FROM (
SELECT contact_id, b.region
}
FROM
civicrm_address a INNER JOIN
$zipTable
b ON a.postal_code = b.zip
WHERE a.contact_id = NEW.contact_id
ORDER BY FIELD(location_type_id,
$locationPriorityOrder
)
$sql = "
) as regionlist
GROUP BY contact_id;
REPLACE INTO `$table_name` (entity_id, $columnName)
"
;
$sql_field_parts
=
array
();
SELECT * FROM (
$info
[]
=
array
(
SELECT contact_id, b.region
'table'
=>
$sourceTable
,
'when'
=>
'AFTER'
,
FROM
'event'
=>
'INSERT'
,
'sql'
=>
$sql
,
civicrm_address a INNER JOIN $zipTable b ON a.postal_code = b.zip
);
$info
[]
=
array
(
WHERE a.contact_id = NEW.contact_id
'table'
=>
$sourceTable
,
'when'
=>
'AFTER'
,
ORDER BY FIELD(location_type_id, $locationPriorityOrder )
'event'
=>
'UPDATE'
,
'sql'
=>
$sql
,
) as regionlist
);
// For delete, we reference OLD.contact_id instead of NEW.contact_id
GROUP BY contact_id;
$sql
=
str_replace
(
'NEW.contact_id'
,
'OLD.contact_id'
,
$sql
);
$info
[]
=
array
(
";
'table'
=>
$sourceTable
,
'when'
=>
'AFTER'
,
$sql_field_parts = array();
'event'
=>
'DELETE'
,
'sql'
=>
$sql
,
);
}
$info[] = array(
```
'table' => $sourceTable,
'when' => 'AFTER',
'event' => 'INSERT',
'sql' => $sql,
);
$info[] = array(
'table' => $sourceTable,
'when' => 'AFTER',
'event' => 'UPDATE',
'sql' => $sql,
);
// For delete, we reference OLD.contact_id instead of NEW.contact_id
$sql = str_replace('NEW.contact_id', 'OLD.contact_id', $sql);
$info[] = array(
'table' => $sourceTable,
'when' => 'AFTER',
'event' => 'DELETE',
'sql' => $sql,
);
}
\ 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