diff --git a/mjwshared.php b/mjwshared.php index 85c37f9bcc462372fb8d5da0b791510e265a9221..6fc911163fbbcad64eebd14bdbf99c54b12de35e 100644 --- a/mjwshared.php +++ b/mjwshared.php @@ -28,6 +28,9 @@ function mjwshared_civicrm_config(&$config) { Civi::dispatcher()->addListener('hook_civicrm_buildAsset', 'mjwshared_symfony_civicrm_buildAsset', -990); // This should run before (almost) anything else as we're loading shared libraries Civi::dispatcher()->addListener('hook_civicrm_coreResourceList', 'mjwshared_symfony_civicrm_coreResourceList', 1000); + + \Civi::dispatcher()->addListener('civi.dao.preUpdate', 'mjwshared_symfony_preUpdateInsert'); + \Civi::dispatcher()->addListener('civi.dao.preInsert', 'mjwshared_symfony_preUpdateInsert'); } /** @@ -264,3 +267,24 @@ function mjwshared_civicrm_buildForm($formName, &$form) { \Civi::resources()->addVars('payment', $jsVars); } + +/** + * @param \Civi\Core\DAO\Event\PreUpdate $event + */ +function mjwshared_symfony_preUpdateInsert(\Civi\Core\DAO\Event\PreUpdate $event) { + if ($event->object instanceof CRM_Contribute_BAO_ContributionRecur) { + // Handle deprecated civicrm_contribution_recur.trxn_id and set it to match processor_id if empty + if (!empty($event->object->processor_id) && empty($event->object->trxn_id)) { + // We set trxn_id to match processor_id as it is still used in some places + $event->object->trxn_id = $event->object->processor_id; + } + elseif (!empty($event->object->trxn_id) && empty($event->object->processor_id)) { + // warn old set + CRM_Core_Error::deprecatedFunctionWarning('civicrm_contribution_recur.processor_id', 'civicrm_contribution_recur.trxn_id'); + } + if (!empty($event->object->trxn_id) && !empty($event->object->processor_id) && ($event->object->trxn_id !== $event->object->processor_id)) { + // Warn set to different values + CRM_Core_Error::deprecatedWarning("Recur ID: {$event->object->id}; civicrm_contribution_recur processor_id is different to trxn_id. trxn_id is deprecated and should be empty or match processor_id"); + } + } +}