Skip wrapping v4 api requests in a transaction
authorColeman Watts <coleman@civicrm.org>
Fri, 24 May 2019 18:27:52 +0000 (14:27 -0400)
committerColeman Watts <coleman@civicrm.org>
Mon, 27 May 2019 16:33:18 +0000 (12:33 -0400)
Transactions aren't a bad thing and we probably want to revisit this but
for now I'm disabling it becuase it's broken, as seen in api_v3_ActivityTest.
I think the problem is with the onApiException event not being dispatched
because api4 doesn't go through Kernel->runSafe, so transactions aren't
being rolled back when they should.

Civi/API/Subscriber/TransactionSubscriber.php

index 4f7b0c64d870de2e302f80aef0ca460c5f2cbcec..5f784320ca7f32cb09a2fca60fb12aa5e0bc0b8b 100644 (file)
@@ -79,6 +79,9 @@ class TransactionSubscriber implements EventSubscriberInterface {
    * @return bool
    */
   public function isTransactional($apiProvider, $apiRequest) {
+    if ($apiRequest['version'] == 4) {
+      return FALSE;
+    }
     if ($this->isForceRollback($apiProvider, $apiRequest)) {
       return TRUE;
     }
@@ -98,6 +101,9 @@ class TransactionSubscriber implements EventSubscriberInterface {
    * @return bool
    */
   public function isForceRollback($apiProvider, $apiRequest) {
+    if ($apiRequest['version'] == 4) {
+      return FALSE;
+    }
     // FIXME: When APIv3 uses better parsing, only one check will be needed.
     if (isset($apiRequest['params']['options']['force_rollback'])) {
       return \CRM_Utils_String::strtobool($apiRequest['params']['options']['force_rollback']);