X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=Civi.php;h=86e72ee847e75d959623c1e297267b3c9c55c3e7;hb=cf6806c375f8d8deb9262f11467323082c8bbc43;hp=a11c38b5a1be8d6ec294c61ac0cc78cd8f78e6f9;hpb=88d932658885d5027684eab2bf47802a297ad946;p=civicrm-core.git diff --git a/Civi.php b/Civi.php index a11c38b5a1..86e72ee847 100644 --- a/Civi.php +++ b/Civi.php @@ -105,6 +105,30 @@ class Civi { return \Civi\Core\Container::getBootService('paths'); } + /** + * Fetch a queue object. + * + * Note: Historically, `CRM_Queue_Queue` objects were not persistently-registered. Persistence + * is now encouraged. This facade has a bias towards persistently-registered queues. + * + * @param string $name + * The name of a persistent/registered queue (stored in `civicrm_queue`) + * @param array{type: string, is_autorun: bool, reset: bool, is_persistent: bool} $params + * Specification for a queue. + * This is not required for accessing an existing queue. + * Specify this if you wish to auto-create the queue or to include advanced options (eg `reset`). + * Example: ['type' => 'Sql', 'error' => 'abort'] + * Example: ['type' => 'SqlParallel', 'error' => 'delete'] + * Defaults: ['reset'=>FALSE, 'is_persistent'=>TRUE, 'is_autorun'=>FALSE] + * @return \CRM_Queue_Queue + * @see \CRM_Queue_Service + */ + public static function queue(string $name, array $params = []): CRM_Queue_Queue { + $defaults = ['reset' => FALSE, 'is_persistent' => TRUE, 'status' => 'active']; + $params = array_merge($defaults, $params, ['name' => $name]); + return CRM_Queue_Service::singleton()->create($params); + } + /** * Obtain the formatting object. * @@ -124,9 +148,14 @@ class Civi { * - 'l': Report on login support in connection header. * - 't': Trusted session. Logins do not require credentials. API calls may execute with or without permission-checks. * - 'u': Untrusted session. Logins require credentials. API calls may only execute with permission-checks. - * Note: The `Civi::pipe()` entry-point is designed to be amenable to shell orchestration (SSH/cv/drush/wp-cli/etc). + * + * The `Civi::pipe()` entry-point is designed to be amenable to shell orchestration (SSH/cv/drush/wp-cli/etc). * The negotiation flags are therefore condensed to individual characters. - * Note: Future flags may be added to the default list. But be careful about removing flags from the default list. + * + * It is possible to preserve compatibility while adding new default-flags. However, removing default-flags + * is more likely to be a breaking-change. + * + * When adding a new flag, consider whether mutable `option()`s may be more appropriate. * @see \Civi\Pipe\PipeSession */ public static function pipe(string $negotiationFlags = 'vtl'): void {