Merge pull request #23995 from colemanw/custom_custom
[civicrm-core.git] / Civi / Api4 / Queue.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11 namespace Civi\Api4;
12
13 use Civi\Api4\Action\Queue\ClaimItems;
14 use Civi\Api4\Action\Queue\RunItems;
15
16 /**
17 * Track a list of durable/scannable queues.
18 *
19 * Registering a queue in this table (and setting `is_auto=1`) can
20 * allow it to execute tasks automatically in the background.
21 *
22 * @searchable none
23 * @since 5.47
24 * @package Civi\Api4
25 */
26 class Queue extends \Civi\Api4\Generic\DAOEntity {
27
28 use Generic\Traits\ManagedEntity;
29
30 /**
31 * @return array
32 */
33 public static function permissions() {
34 return [
35 'meta' => ['access CiviCRM'],
36 'default' => ['administer queues'],
37 'get' => ['access CiviCRM'],
38 'runItem' => [\CRM_Core_Permission::ALWAYS_DENY_PERMISSION],
39 ];
40 }
41
42 /**
43 * Claim an item from the queue. Returns zero or one items.
44 *
45 * Note: This is appropriate for persistent, auto-run queues.
46 *
47 * @param bool $checkPermissions
48 * @return \Civi\Api4\Action\Queue\ClaimItems
49 */
50 public static function claimItems($checkPermissions = TRUE) {
51 return (new ClaimItems(static::getEntityName(), __FUNCTION__))
52 ->setCheckPermissions($checkPermissions);
53 }
54
55 /**
56 * Run an item from the queue.
57 *
58 * Note: This is appropriate for persistent, auto-run queues.
59 *
60 * @param bool $checkPermissions
61 * @return \Civi\Api4\Action\Queue\RunItems
62 */
63 public static function runItems($checkPermissions = TRUE) {
64 return (new RunItems(static::getEntityName(), __FUNCTION__))
65 ->setCheckPermissions($checkPermissions);
66 }
67
68 }