dev/core#4554 Delete related Queue when user job deleted
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 8 Nov 2023 01:37:44 +0000 (14:37 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 8 Nov 2023 01:38:13 +0000 (14:38 +1300)
CRM/Core/BAO/UserJob.php
CRM/Import/Forms.php
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php

index a6ba558f8391f30e250b85d0afb29a9a695ee83f..c21691befcabfddb6903ede1db496cd65fa91cc5 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 use Civi\Api4\Mapping;
+use Civi\Api4\Queue;
 use Civi\Api4\UserJob;
 use Civi\Core\ClassScanner;
 use Civi\Core\Event\PreEvent;
@@ -102,6 +103,9 @@ class CRM_Core_BAO_UserJob extends CRM_Core_DAO_UserJob implements HookInterface
       $mappingName = Mapping::get(FALSE)->addWhere('id', '=', $event->id)->addSelect('name')->execute()->first()['name'];
       UserJob::delete(FALSE)->addWhere('name', '=', 'import_' . $mappingName)->execute();
     }
+    if ($event->entity === 'UserJob' && $event->action === 'delete') {
+      Queue::delete(FALSE)->addWhere('name', '=', 'user_job_' . $event->id)->execute();
+    }
   }
 
   /**
index f1b84b984e85a589c3fa76c175e78bf4bf2c8345..4535fd2121a02b62635f3ffe48791f775cad9ca6 100644 (file)
@@ -638,6 +638,7 @@ class CRM_Import_Forms extends CRM_Core_Form {
 
   /**
    * Outputs and downloads the csv of outcomes from an import job.
+   * Function is accessed from civicrm/import/outcome path.
    *
    * This gets the rows from the temp table that match the relevant status
    * and output them as a csv.
index dea5fbd02bcf344d16cb738a1276ee19317805e0..9382766383e9d483f800dc88a2c74d6c833c32f5 100644 (file)
@@ -26,6 +26,7 @@ use Civi\Api4\IM;
 use Civi\Api4\LocationType;
 use Civi\Api4\OpenID;
 use Civi\Api4\Phone;
+use Civi\Api4\Queue;
 use Civi\Api4\Relationship;
 use Civi\Api4\RelationshipType;
 use Civi\Api4\UserJob;
@@ -1238,6 +1239,10 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
       CRM_Import_Forms::outputCSV();
     }
     catch (CRM_Core_Exception_PrematureExitException $e) {
+      UserJob::delete()->addWhere('id', '=', $dataSource->getUserJobID())->execute();
+      $this->assertCount(0, Queue::get()
+        ->addWhere('name', '=', 'user_job_' . $dataSource->getUserJobID())
+        ->execute());
       // For now just check it got this far without error.
       ob_end_clean();
       return;