return \Civi\Core\Container::getBootService('paths');
}
+ /**
+ * Fetch a queue object.
+ *
+ * @param string $name
+ * Name of the queue.
+ * The queue must be persistent (stored in `civicrm_queue`).
+ * @return \CRM_Queue_Queue
+ * @see \CRM_Queue_Service
+ */
+ public static function queue(string $name): CRM_Queue_Queue {
+ return CRM_Queue_Service::singleton()->create([
+ 'name' => $name,
+ 'reset' => FALSE,
+ 'is_persistent' => TRUE,
+ ]);
+ }
+
/**
* Obtain the formatting object.
*
$this->assertEquals(0, $this->queue->numberOfItems());
}
+ /**
+ * Create a persistent queue via CRM_Queue_Service. Get a queue object with Civi::queue().
+ *
+ * @dataProvider getQueueSpecs
+ * @param $queueSpec
+ */
+ public function testPersistentUsage_service($queueSpec) {
+ $this->assertTrue(!empty($queueSpec['name']));
+ $this->assertTrue(!empty($queueSpec['type']));
+
+ $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_queue');
+ $q1 = CRM_Queue_Service::singleton()->create($queueSpec + [
+ 'is_persistent' => TRUE,
+ ]);
+ $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_queue');
+
+ $q2 = Civi::queue($queueSpec['name']);
+ $this->assertInstanceOf('CRM_Queue_Queue_' . $queueSpec['type'], $q2);
+ $this->assertTrue($q1 === $q2);
+ }
+
+ /**
+ * Create a persistent queue via APIv4. Get a queue object with Civi::queue().
+ *
+ * @dataProvider getQueueSpecs
+ * @param $queueSpec
+ */
+ public function testPersistentUsage_api4($queueSpec) {
+ $this->assertTrue(!empty($queueSpec['name']));
+ $this->assertTrue(!empty($queueSpec['type']));
+
+ \Civi\Api4\Queue::create(0)
+ ->setValues($queueSpec)
+ ->execute();
+
+ $q1 = Civi::queue($queueSpec['name']);
+ $this->assertInstanceOf('CRM_Queue_Queue_' . $queueSpec['type'], $q1);
+
+ if ($queueSpec['type'] !== 'Memory') {
+ CRM_Queue_Service::singleton(TRUE);
+ $q2 = CRM_Queue_Service::singleton()->load([
+ 'name' => $queueSpec['name'],
+ 'is_persistent' => TRUE,
+ ]);
+ $this->assertInstanceOf('CRM_Queue_Queue_' . $queueSpec['type'], $q1);
+ }
+ }
+
/**
* Test that queue content is reset when reset=>TRUE
*