An important nuance: Triggers may be setup during installation or upgrade, but they can also be setup at runtime – e.g. when an admin enables or disables logging, the triggers must be updated. When using hook_civicrm_triggerInfo, a Civi extension (or Drupal module, etal) can define its own triggers – these need to be manipulated whenever the extension is installed/upgraded/removed.
Specifically, triggers are rebuilt on these occasions:
- Enabling/disabling logging
- Enabling multilingual (but - maybe - this only happens if logging is active?)
- Adding/removing custom-data fields (but - maybe - this only happens if logging is active?)
- Performing a general system-flush/cache-clear, i.e.
+ Upgrading CiviCRM
+ Installing/upgrading/removing a Civi extension
+ Installing/upgrading/removing a CMS extension (Drupal module/Joomla extension/WP plugin)
+ Visiting /civicrm/cacheclear?triggerRebuild=1 or /civicrm/menu/rebuild?triggerRebuild=1
+ Executing the "System.flush" API (e.g. "drush cvapi system.flush triggers=1")
A minimal solution might be something like:
1. Add a new page, "/civicrm/admin/triggers.sql", which simply prints out the SQL for dropping & creating all triggers.
2. In CRM_Core_DAO::triggerRebuild(), add a call like:
if (! isPermittedToManageTriggers())
{
$url = CRM_Utils_System::url('civicrm/admin/triggers.sql');
CRM_Core_Session::setStatus(ts('Please update the SQL trigger configuration by downloading and executing the <a href="%1">the SQL trigger definitions</a>.', array(1 => $url)));
}
This will unfortunately produce false-positives. If the admin enables a typical Drupal module (which doesn't use hook_civicrm_triggerInfo), then there's no real need to reset the triggers, but it would never-the-less display the alert. The false-positives seem acceptable if we think that only a handful of professional sysadmins will be using this feature. If the false-positives are a problem, then we'd have to do a bit more work (eg call "SHOW TRIGGERS LIKE 'civicrm_%'" and compare with the expected triggers).
An important nuance: Triggers may be setup during installation or upgrade, but they can also be setup at runtime – e.g. when an admin enables or disables logging, the triggers must be updated. When using hook_civicrm_triggerInfo, a Civi extension (or Drupal module, etal) can define its own triggers – these need to be manipulated whenever the extension is installed/upgraded/removed.
Specifically, triggers are rebuilt on these occasions:
+ Upgrading CiviCRM
+ Installing/upgrading/removing a Civi extension
+ Installing/upgrading/removing a CMS extension (Drupal module/Joomla extension/WP plugin)
+ Visiting /civicrm/cacheclear?triggerRebuild=1 or /civicrm/menu/rebuild?triggerRebuild=1
+ Executing the "System.flush" API (e.g. "drush cvapi system.flush triggers=1")
A minimal solution might be something like:
1. Add a new page, "/civicrm/admin/triggers.sql", which simply prints out the SQL for dropping & creating all triggers.
2. In CRM_Core_DAO::triggerRebuild(), add a call like:
if (! isPermittedToManageTriggers())
{ $url = CRM_Utils_System::url('civicrm/admin/triggers.sql'); CRM_Core_Session::setStatus(ts('Please update the SQL trigger configuration by downloading and executing the <a href="%1">the SQL trigger definitions</a>.', array(1 => $url))); }This will unfortunately produce false-positives. If the admin enables a typical Drupal module (which doesn't use hook_civicrm_triggerInfo), then there's no real need to reset the triggers, but it would never-the-less display the alert. The false-positives seem acceptable if we think that only a handful of professional sysadmins will be using this feature. If the false-positives are a problem, then we'd have to do a bit more work (eg call "SHOW TRIGGERS LIKE 'civicrm_%'" and compare with the expected triggers).