OAuth token refresh broken
Overview
OAuthSysToken.Refresh api action seems to be broken by recent change to BasicBatchAction Api4 class 29ab318b
Reproduction steps
- Enable OAuth module
- Setup client (Gmail)
- Add a mail account using that client
- Click Save & Test
Current behaviour
MailStore lookup fails with message 'Expected to find one OAuthClient record, but there were zero. (See log for more details.)'
Error in the log is:
[warning] MailSettings: Failed to establish test connection
Array
(
[exception] => API_Exception: "Expected to find one OAuthClient record, but there were zero."
#0 .../sites/all/modules/civicrm/ext/oauth-client/Civi/Api4/Action/OAuthSysToken/Refresh.php(79): Civi\Api4\Generic\Result->single()
#1 .../sites/all/modules/civicrm/ext/oauth-client/Civi/Api4/Action/OAuthSysToken/Refresh.php(54): Civi\Api4\Action\OAuthSysToken\Refresh->getProvider(NULL)
#2 .../sites/all/modules/civicrm/Civi/Api4/Generic/BasicBatchAction.php(72): Civi\Api4\Action\OAuthSysToken\Refresh->doTask((Array:1))
#3 .../sites/all/modules/civicrm/Civi/Api4/Provider/ActionObjectProvider.php(68): Civi\Api4\Generic\BasicBatchAction->_run(Object(Civi\Api4\Generic\Result))
#4 .../sites/all/modules/civicrm/Civi/API/Kernel.php(149): Civi\Api4\Provider\ActionObjectProvider->invoke(Object(Civi\Api4\Action\OAuthSysToken\Refresh))
#5 .../sites/all/modules/civicrm/Civi/Api4/Generic/AbstractAction.php(232): Civi\API\Kernel->runRequest(Object(Civi\Api4\Action\OAuthSysToken\Refresh))
#6 .../sites/all/modules/civicrm/api/api.php(85): Civi\Api4\Generic\AbstractAction->execute()
#7 .../sites/all/modules/civicrm/ext/oauth-client/CRM/OAuth/MailSetup.php(155): civicrm_api4("OAuthSysToken", "refresh", (Array:3))
#8 .../sites/all/modules/civicrm/ext/oauth-client/oauth_client.php(207): CRM_OAuth_MailSetup::alterMailStore((Array:19))
#9 .../sites/all/modules/civicrm/CRM/Utils/Hook.php(271): oauth_client_civicrm_alterMailStore((Array:19))
#10 .../sites/all/modules/civicrm/CRM/Utils/Hook/DrupalBase.php(73): CRM_Utils_Hook->runHooks((Array:146), "civicrm_alterMailStore", 1, (Array:19), NULL, NULL, NULL, NULL, NULL)
#11 .../sites/all/modules/civicrm/Civi/Core/CiviEventDispatcher.php(237): CRM_Utils_Hook_DrupalBase->invokeViaUF(1, (Array:19), NULL, NULL, NULL, NULL, NULL, "civicrm_alterMailStore")
#12 .../sites/all/modules/civicrm/vendor/symfony/event-dispatcher/EventDispatcher.php(214): Civi\Core\CiviEventDispatcher::delegateToUF(Object(Civi\Core\Event\GenericHookEvent), "hook_civicrm_alterMailStore", Object(Civi\Core\CiviEventDispatcher))
#13 .../sites/all/modules/civicrm/vendor/symfony/event-dispatcher/EventDispatcher.php(44): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch((Array:1), "hook_civicrm_alterMailStore", Object(Civi\Core\Event\GenericHookEvent))
#14 .../sites/all/modules/civicrm/Civi/Core/CiviEventDispatcher.php(198): Symfony\Component\EventDispatcher\EventDispatcher->dispatch("hook_civicrm_alterMailStore", Object(Civi\Core\Event\GenericHookEvent))
#15 .../sites/all/modules/civicrm/CRM/Utils/Hook.php(167): Civi\Core\CiviEventDispatcher->dispatch("hook_civicrm_alterMailStore", Object(Civi\Core\Event\GenericHookEvent))
#16 .../sites/all/modules/civicrm/CRM/Utils/Hook.php(1245): CRM_Utils_Hook->invoke((Array:1), (Array:19), NULL, NULL, NULL, NULL, NULL, "civicrm_alterMailStore")
#17 .../sites/all/modules/civicrm/CRM/Mailing/MailStore.php(50): CRM_Utils_Hook::alterMailStore((Array:19))
#18 .../sites/all/modules/civicrm/Civi/Api4/Action/MailSettings/TestConnection.php(28): CRM_Mailing_MailStore::getStore(NULL)
#19 .../sites/all/modules/civicrm/Civi/Api4/Generic/BasicBatchAction.php(72): Civi\Api4\Action\MailSettings\TestConnection->doTask((Array:1))
#20 .../sites/all/modules/civicrm/Civi/Api4/Provider/ActionObjectProvider.php(68): Civi\Api4\Generic\BasicBatchAction->_run(Object(Civi\Api4\Generic\Result))
#21 .../sites/all/modules/civicrm/Civi/API/Kernel.php(149): Civi\Api4\Provider\ActionObjectProvider->invoke(Object(Civi\Api4\Action\MailSettings\TestConnection))
#22 .../sites/all/modules/civicrm/Civi/Api4/Generic/AbstractAction.php(232): Civi\API\Kernel->runRequest(Object(Civi\Api4\Action\MailSettings\TestConnection))
#23 .../sites/all/modules/civicrm/api/api.php(85): Civi\Api4\Generic\AbstractAction->execute()
#24 .../sites/all/modules/civicrm/CRM/Admin/Form/MailSettings.php(214): civicrm_api4("MailSettings", "testConnection", (Array:1))
#25 .../sites/all/modules/civicrm/CRM/Core/Form.php(526): CRM_Admin_Form_MailSettings->postProcess()
#26 .../sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Upload.php(152): CRM_Core_Form->mainProcess()
#27 .../sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Upload.php(119): CRM_Core_QuickForm_Action_Upload->realPerform(Object(CRM_Admin_Form_MailSettings), "upload")
#28 .../sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php(203): CRM_Core_QuickForm_Action_Upload->perform(Object(CRM_Admin_Form_MailSettings), "upload")
#29 .../sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php(103): HTML_QuickForm_Controller->handle(Object(CRM_Admin_Form_MailSettings), "upload")
#30 .../sites/all/modules/civicrm/CRM/Core/Controller.php(352): HTML_QuickForm_Page->handle("upload")
#31 .../sites/all/modules/civicrm/CRM/Core/Page/Basic.php(395): CRM_Core_Controller->run()
#32 .../sites/all/modules/civicrm/CRM/Core/Page/Basic.php(140): CRM_Core_Page_Basic->edit(2, 1)
#33 .../sites/all/modules/civicrm/CRM/Core/Invoke.php(313): CRM_Core_Page_Basic->run((Array:3), NULL)
#34 .../sites/all/modules/civicrm/CRM/Core/Invoke.php(69): CRM_Core_Invoke::runItem((Array:15))
#35 .../sites/all/modules/civicrm/CRM/Core/Invoke.php(36): CRM_Core_Invoke::_invoke((Array:3))
#36 .../sites/all/modules/civicrm/drupal/civicrm.module(458): CRM_Core_Invoke::invoke((Array:3))
#37 .../includes/menu.inc(527): civicrm_invoke("admin", "mailSettings")
#38 .../index.php(21): menu_execute_active_handler()
#39 {main}
)
Expected behaviour
It should successfully connect to the IMAP mail store using OAuth authentication.
Environment information
- CiviCRM: 5.40.2
- PHP: 7.3
Comments
I think this fixes it: ufundo/core@19a31b65