Group Contact trigger causes crash
On CiviRules 3.4, when I make an API call to add a GroupContact record, I get a crash. Backtrace is below.
I tried this also on 3.1 and there's an error, but I think it's caught by an exception handler.
The issue is that CRM_CivirulesPostTrigger_GroupContact::triggerTrigger()
has special handling and makes a SQL call to get the info that would normally be in an API3 $objectRef
object. However, there is no id
field specified, so when CRM_Civirules_Engine::triggerRule()
runs this line:
$triggerData->setEntityId($triggerData->getEntityData($triggerData->getEntity())['id']);
setEntityId
is passed NULL
which causes the error.
#0 /home/jon/local/mysite/web/sites/all/civicrm-custom/extensions/civirules/CRM/Civirules/Engine.php(28): CRM_Civirules_TriggerData_TriggerData->setEntityId(NULL)
#1 /home/jon/local/mysite/web/sites/all/civicrm-custom/extensions/civirules/CRM/CivirulesPostTrigger/GroupContact.php(67): CRM_Civirules_Engine::triggerRule(Object(CRM_CivirulesPostTrigger_GroupContact), Object(CRM_Civirules_TriggerData_Edit))
#2 /home/jon/local/mysite/web/sites/all/civicrm-custom/extensions/civirules/CRM/Civirules/Trigger/Post.php(107): CRM_CivirulesPostTrigger_GroupContact->triggerTrigger('create', 'GroupContact', '136', Array, 1)
#3 /home/jon/local/mysite/web/sites/all/civicrm-custom/extensions/civirules/civirules.php(350): CRM_Civirules_Trigger_Post::post('create', 'GroupContact', '136', Array, 1)
#4 [internal function]: civirules_call_post_trigger('create', 'GroupContact', '136', Array, 1)
#5 /home/jon/local/mysite/vendor/civicrm/civicrm-core/Civi/Core/Transaction/Frame.php(198): call_user_func_array('civirules_call_...', Array)
#6 /home/jon/local/mysite/vendor/civicrm/civicrm-core/Civi/Core/Transaction/Frame.php(148): Civi\Core\Transaction\Frame->invokeCallbacks(2)
#7 /home/jon/local/mysite/vendor/civicrm/civicrm-core/Civi/Core/Transaction/Manager.php(103): Civi\Core\Transaction\Frame->finish()
#8 /home/jon/local/mysite/vendor/civicrm/civicrm-core/CRM/Core/Transaction.php(126): Civi\Core\Transaction\Manager->dec()
#9 /home/jon/local/mysite/vendor/civicrm/civicrm-core/CRM/Core/Transaction.php(113): CRM_Core_Transaction->commit()
#10 /home/jon/local/mysite/vendor/civicrm/civicrm-core/Civi/API/Subscriber/TransactionSubscriber.php(155): CRM_Core_Transaction->__destruct()
#11 /home/jon/local/mysite/vendor/symfony/event-dispatcher/EventDispatcher.php(220): Civi\API\Subscriber\TransactionSubscriber->onApiRespond(Object(Civi\API\Event\RespondEvent), 'civi.api.respon...', Object(Civi\Core\UnoptimizedEventDispatcher))
#12 /home/jon/local/mysite/vendor/symfony/event-dispatcher/EventDispatcher.php(56): Symfony\Component\EventDispatcher\EventDispatcher->callListeners(Array, 'civi.api.respon...', Object(Civi\API\Event\RespondEvent))
#13 /home/jon/local/mysite/vendor/civicrm/civicrm-core/Civi/Core/CiviEventDispatcher.php(263): Symfony\Component\EventDispatcher\EventDispatcher->dispatch(Object(Civi\API\Event\RespondEvent), 'civi.api.respon...')
#14 /home/jon/local/mysite/vendor/civicrm/civicrm-core/Civi/API/Kernel.php(265): Civi\Core\CiviEventDispatcher->dispatch('civi.api.respon...', Object(Civi\API\Event\RespondEvent))
#15 /home/jon/local/mysite/vendor/civicrm/civicrm-core/Civi/API/Kernel.php(158): Civi\API\Kernel->respond(Object(Civi\API\Provider\MagicFunctionProvider), Array, Array)
#16 /home/jon/local/mysite/vendor/civicrm/civicrm-core/Civi/API/Kernel.php(79): Civi\API\Kernel->runRequest(Array)
#17 /home/jon/local/mysite/vendor/civicrm/civicrm-core/api/api.php(136): Civi\API\Kernel->runSafe('group_contact', 'create', Array)
#18 /home/jon/local/mysite/web/modules/contrib/webform_civicrm/src/Utils.php(727): civicrm_api3('group_contact', 'create', Array)
#19 /home/jon/local/mysite/web/modules/contrib/webform_civicrm/src/WebformCivicrmPostProcess.php(1026): Drupal\webform_civicrm\Utils->wf_civicrm_api('group_contact', 'create', Array)
#20 /home/jon/local/mysite/web/modules/contrib/webform_civicrm/src/WebformCivicrmPostProcess.php(933): Drupal\webform_civicrm\WebformCivicrmPostProcess->addOrRemoveMultivaluedData('group', 'contact', '33927', Array, Array)
#21 /home/jon/local/mysite/web/modules/contrib/webform_civicrm/src/WebformCivicrmPostProcess.php(265): Drupal\webform_civicrm\WebformCivicrmPostProcess->saveGroupsAndTags(Array, '33927', 1)
#22 /home/jon/local/mysite/web/modules/contrib/webform_civicrm/src/Plugin/WebformHandler/CivicrmWebformHandler.php(144): Drupal\webform_civicrm\WebformCivicrmPostProcess->preSave(Object(Drupal\webform\Entity\WebformSubmission))
#23 /home/jon/local/mysite/web/modules/contrib/webform/src/Entity/Webform.php(2765): Drupal\webform_civicrm\Plugin\WebformHandler\CivicrmWebformHandler->preSave(Object(Drupal\webform\Entity\WebformSubmission), NULL, NULL)
#24 /home/jon/local/mysite/web/modules/contrib/webform/src/WebformSubmissionStorage.php(1212): Drupal\webform\Entity\Webform->invokeHandlers('preSave', Object(Drupal\webform\Entity\WebformSubmission), NULL, NULL)
#25 /home/jon/local/mysite/web/modules/contrib/webform/src/WebformSubmissionStorage.php(968): Drupal\webform\WebformSubmissionStorage->invokeWebformHandlers('preSave', Object(Drupal\webform\Entity\WebformSubmission))
#26 /home/jon/local/mysite/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(483): Drupal\webform\WebformSubmissionStorage->doPreSave(Object(Drupal\webform\Entity\WebformSubmission))
#27 /home/jon/local/mysite/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(806): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\webform\Entity\WebformSubmission))
#28 /home/jon/local/mysite/web/modules/contrib/webform/src/WebformSubmissionStorage.php(983): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\webform\Entity\WebformSubmission))
#29 /home/jon/local/mysite/web/core/lib/Drupal/Core/Entity/EntityBase.php(354): Drupal\webform\WebformSubmissionStorage->save(Object(Drupal\webform\Entity\WebformSubmission))
#30 /home/jon/local/mysite/web/modules/contrib/webform/src/Entity/WebformSubmission.php(913): Drupal\Core\Entity\EntityBase->save()
#31 /home/jon/local/mysite/web/modules/contrib/webform/src/WebformSubmissionForm.php(2017): Drupal\webform\Entity\WebformSubmission->save()
#32 /home/jon/local/mysite/web/modules/contrib/webform/src/WebformSubmissionForm.php(1712): Drupal\webform\WebformSubmissionForm->save(Array, Object(Drupal\Core\Form\FormState))
#33 /home/jon/local/mysite/web/modules/contrib/webform/src/WebformSubmissionForm.php(1673): Drupal\webform\WebformSubmissionForm->wizardSubmit(Array, Object(Drupal\Core\Form\FormState))
#34 /home/jon/local/mysite/web/modules/contrib/webform/src/WebformSubmissionForm.php(1633): Drupal\webform\WebformSubmissionForm->next(Array, Object(Drupal\Core\Form\FormState), true)
#35 [internal function]: Drupal\webform\WebformSubmissionForm->submit(Array, Object(Drupal\Core\Form\FormState))
#36 /home/jon/local/mysite/web/core/lib/Drupal/Core/Form/FormSubmitter.php(129): call_user_func_array(Array, Array)
#37 /home/jon/local/mysite/web/core/lib/Drupal/Core/Form/FormSubmitter.php(67): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#38 /home/jon/local/mysite/web/core/lib/Drupal/Core/Form/FormBuilder.php(597): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#39 /home/jon/local/mysite/web/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm('webform_submiss...', Array, Object(Drupal\Core\Form\FormState))
#40 /home/jon/local/mysite/web/core/lib/Drupal/Core/Entity/EntityFormBuilder.php(48): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\webform\WebformSubmissionForm), Object(Drupal\Core\Form\FormState))
#41 /home/jon/local/mysite/web/modules/contrib/webform/src/Entity/Webform.php(1257): Drupal\Core\Entity\EntityFormBuilder->getForm(Object(Drupal\webform\Entity\WebformSubmission), 'add')
#42 /home/jon/local/mysite/web/modules/contrib/webform/src/Controller/WebformEntityController.php(77): Drupal\webform\Entity\Webform->getSubmissionForm()
#43 [internal function]: Drupal\webform\Controller\WebformEntityController->addForm(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\webform\Entity\Webform))
#44 /home/jon/local/mysite/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#45 /home/jon/local/mysite/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#46 /home/jon/local/mysite/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#47 /home/jon/local/mysite/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#48 /home/jon/local/mysite/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#49 /home/jon/local/mysite/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#50 /home/jon/local/mysite/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#51 /home/jon/local/mysite/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#52 /home/jon/local/mysite/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#53 /home/jon/local/mysite/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#54 /home/jon/local/mysite/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#55 /home/jon/local/mysite/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#56 /home/jon/local/mysite/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#57 /home/jon/local/mysite/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#58 /home/jon/local/mysite/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#59 /home/jon/local/mysite/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#60 /home/jon/local/mysite/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#61 /home/jon/local/mysite/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#62 {main}