From f828381ac407472bce69afb51fef8ee2f50d540a Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 27 Dec 2021 00:24:21 -0800 Subject: [PATCH] Queue XML/DAO - Add table to track persistent queues (5.47 variant) See also: https://docs.civicrm.org/dev/en/latest/framework/queues/ Before: * SQL-backed queues are created implicitly - by inserting items in `civicrm_queue_item` * Non-SQL queues are not visible/discoverable After: * Any kind of queue (SQL or non-SQL) can be registered and discovered via `civicrm_queue` Comments: * This will make it possible for the standard/generic/default background-worker to discover what queues it should monitor. --- CRM/Core/DAO/AllCoreTables.data.php | 5 + CRM/Queue/DAO/Queue.php | 236 ++++++++++++++++++++++++++++ xml/schema/Queue/Queue.xml | 68 ++++++++ xml/schema/Queue/files.xml | 1 + 4 files changed, 310 insertions(+) create mode 100644 CRM/Queue/DAO/Queue.php create mode 100644 xml/schema/Queue/Queue.xml diff --git a/CRM/Core/DAO/AllCoreTables.data.php b/CRM/Core/DAO/AllCoreTables.data.php index 12b46189d6..5dd43a0831 100644 --- a/CRM/Core/DAO/AllCoreTables.data.php +++ b/CRM/Core/DAO/AllCoreTables.data.php @@ -242,6 +242,11 @@ return [ 'class' => 'CRM_Pledge_DAO_PledgeBlock', 'table' => 'civicrm_pledge_block', ], + 'CRM_Queue_DAO_Queue' => [ + 'name' => 'Queue', + 'class' => 'CRM_Queue_DAO_Queue', + 'table' => 'civicrm_queue', + ], 'CRM_Queue_DAO_QueueItem' => [ 'name' => 'QueueItem', 'class' => 'CRM_Queue_DAO_QueueItem', diff --git a/CRM/Queue/DAO/Queue.php b/CRM/Queue/DAO/Queue.php new file mode 100644 index 0000000000..6f7c837561 --- /dev/null +++ b/CRM/Queue/DAO/Queue.php @@ -0,0 +1,236 @@ +__table = 'civicrm_queue'; + parent::__construct(); + } + + /** + * Returns localized title of this entity. + * + * @param bool $plural + * Whether to return the plural version of the title. + */ + public static function getEntityTitle($plural = FALSE) { + return $plural ? ts('Queues') : ts('Queue'); + } + + /** + * Returns all the column names of this table + * + * @return array + */ + public static function &fields() { + if (!isset(Civi::$statics[__CLASS__]['fields'])) { + Civi::$statics[__CLASS__]['fields'] = [ + 'id' => [ + 'name' => 'id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('System Queue ID'), + 'required' => TRUE, + 'where' => 'civicrm_queue.id', + 'table_name' => 'civicrm_queue', + 'entity' => 'Queue', + 'bao' => 'CRM_Queue_DAO_Queue', + 'localizable' => 0, + 'html' => [ + 'type' => 'Number', + ], + 'readonly' => TRUE, + 'add' => '5.46', + ], + 'name' => [ + 'name' => 'name', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Name'), + 'description' => ts('Name of the queue'), + 'required' => TRUE, + 'maxlength' => 64, + 'size' => CRM_Utils_Type::BIG, + 'where' => 'civicrm_queue.name', + 'table_name' => 'civicrm_queue', + 'entity' => 'Queue', + 'bao' => 'CRM_Queue_DAO_Queue', + 'localizable' => 0, + 'html' => [ + 'type' => 'Text', + ], + 'add' => '5.46', + ], + 'type' => [ + 'name' => 'type', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Type'), + 'description' => ts('Type of the queue'), + 'required' => TRUE, + 'maxlength' => 64, + 'size' => CRM_Utils_Type::BIG, + 'where' => 'civicrm_queue.type', + 'table_name' => 'civicrm_queue', + 'entity' => 'Queue', + 'bao' => 'CRM_Queue_DAO_Queue', + 'localizable' => 0, + 'html' => [ + 'type' => 'Text', + ], + 'add' => '5.46', + ], + 'is_autorun' => [ + 'name' => 'is_autorun', + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'title' => ts('Enable Autorun'), + 'description' => ts('Should the standard background attempt to autorun tasks in this queue?'), + 'where' => 'civicrm_queue.is_autorun', + 'table_name' => 'civicrm_queue', + 'entity' => 'Queue', + 'bao' => 'CRM_Queue_DAO_Queue', + 'localizable' => 0, + 'html' => [ + 'type' => 'CheckBox', + 'label' => ts("Auto Run"), + ], + 'add' => NULL, + ], + ]; + CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); + } + return Civi::$statics[__CLASS__]['fields']; + } + + /** + * Return a mapping from field-name to the corresponding key (as used in fields()). + * + * @return array + * Array(string $name => string $uniqueName). + */ + public static function &fieldKeys() { + if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) { + Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields())); + } + return Civi::$statics[__CLASS__]['fieldKeys']; + } + + /** + * Returns the names of this table + * + * @return string + */ + public static function getTableName() { + return self::$_tableName; + } + + /** + * Returns if this table needs to be logged + * + * @return bool + */ + public function getLog() { + return self::$_log; + } + + /** + * Returns the list of fields that can be imported + * + * @param bool $prefix + * + * @return array + */ + public static function &import($prefix = FALSE) { + $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'queue', $prefix, []); + return $r; + } + + /** + * Returns the list of fields that can be exported + * + * @param bool $prefix + * + * @return array + */ + public static function &export($prefix = FALSE) { + $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'queue', $prefix, []); + return $r; + } + + /** + * Returns the list of indices + * + * @param bool $localize + * + * @return array + */ + public static function indices($localize = TRUE) { + $indices = [ + 'UI_name' => [ + 'name' => 'UI_name', + 'field' => [ + 0 => 'name', + ], + 'localizable' => FALSE, + 'unique' => TRUE, + 'sig' => 'civicrm_queue::1::name', + ], + ]; + return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; + } + +} diff --git a/xml/schema/Queue/Queue.xml b/xml/schema/Queue/Queue.xml new file mode 100644 index 0000000000..e23c129b94 --- /dev/null +++ b/xml/schema/Queue/Queue.xml @@ -0,0 +1,68 @@ + + + + + CRM/Queue + Queue + civicrm_queue + Stores a list of persistent queues + 5.47 + + id + System Queue ID + int unsigned + true + + Number + + 5.47 + + + id + true + + + name + Name + varchar + 64 + Name of the queue + true + + Text + + 5.47 + + + UI_name + name + true + 5.47 + + + type + Type + varchar + 64 + Type of the queue + true + + Text + + 5.47 + + + is_autorun + Enable Autorun + boolean + Should the standard background attempt to autorun tasks in this queue? + + CheckBox + + + + +
diff --git a/xml/schema/Queue/files.xml b/xml/schema/Queue/files.xml index 50b023f899..940e6b275d 100644 --- a/xml/schema/Queue/files.xml +++ b/xml/schema/Queue/files.xml @@ -1,5 +1,6 @@ + -- 2.25.1