Skip to content
Snippets Groups Projects
Unverified Commit bc38b6d0 authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #23679 from totten/master-queue-tpl-inclusive

Civi::queue() - Add support for 'template' queues
parents aaddba54 77b7441a
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/UserJob.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:58e6fcaa028d157bfa074a073111239d)
* (GenCodeChecksum:fc2efbbf7b26018fe3dff0cda44ffa28)
*/
/**
......@@ -125,6 +125,15 @@ class CRM_Core_DAO_UserJob extends CRM_Core_DAO {
*/
public $metadata;
/**
* Is this a template configuration (for use by other/future jobs)?
*
* @var bool|string
* (SQL type: tinyint)
* Note that values will be retrieved from the database as a string.
*/
public $is_template;
/**
* Class constructor.
*/
......@@ -350,6 +359,24 @@ class CRM_Core_DAO_UserJob extends CRM_Core_DAO {
'serialize' => self::SERIALIZE_JSON,
'add' => '5.50',
],
'is_template' => [
'name' => 'is_template',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Is Template'),
'description' => ts('Is this a template configuration (for use by other/future jobs)?'),
'required' => TRUE,
'where' => 'civicrm_user_job.is_template',
'default' => '0',
'table_name' => 'civicrm_user_job',
'entity' => 'UserJob',
'bao' => 'CRM_Core_BAO_UserJob',
'localizable' => 0,
'html' => [
'type' => 'CheckBox',
'label' => ts("Is Template"),
],
'add' => '5.51',
],
];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
......
......@@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Queue/Queue.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:0b068d0a6ba5d6348f11706b3854feb1)
* (GenCodeChecksum:85012d3cc88cad6b1c868665e0b490c3)
*/
/**
......@@ -118,6 +118,15 @@ class CRM_Queue_DAO_Queue extends CRM_Core_DAO {
*/
public $error;
/**
* Is this a template configuration (for use by other/future queues)?
*
* @var bool|string
* (SQL type: tinyint)
* Note that values will be retrieved from the database as a string.
*/
public $is_template;
/**
* Class constructor.
*/
......@@ -327,6 +336,24 @@ class CRM_Queue_DAO_Queue extends CRM_Core_DAO {
],
'add' => '5.51',
],
'is_template' => [
'name' => 'is_template',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Is Template'),
'description' => ts('Is this a template configuration (for use by other/future queues)?'),
'required' => TRUE,
'where' => 'civicrm_queue.is_template',
'default' => '0',
'table_name' => 'civicrm_queue',
'entity' => 'Queue',
'bao' => 'CRM_Queue_BAO_Queue',
'localizable' => 0,
'html' => [
'type' => 'CheckBox',
'label' => ts("Is Template"),
],
'add' => '5.51',
],
];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
......
......@@ -142,6 +142,12 @@ class CRM_Queue_Service {
return $loaded;
}
if (isset($queueSpec['template'])) {
$base = $this->findQueueSpec(['name' => $queueSpec['template']]);
$reset = ['is_template' => 0];
$queueSpec = array_merge($base, $reset, $queueSpec);
}
$this->validateQueueSpec($queueSpec);
$dao = new CRM_Queue_DAO_Queue();
......
......@@ -36,6 +36,10 @@ class CRM_Upgrade_Incremental_php_FiveFiftyOne extends CRM_Upgrade_Incremental_B
'status', "varchar(16) NULL DEFAULT 'active' COMMENT 'Execution status'");
$this->addTask('Add column "civicrm_queue.error"', 'addColumn', 'civicrm_queue',
'error', "varchar(16) NULL COMMENT 'Fallback behavior for unhandled errors'");
$this->addTask('Add column "civicrm_queue.is_template"', 'addColumn', 'civicrm_queue',
'is_template', "tinyint NOT NULL DEFAULT 0 COMMENT 'Is this a template configuration (for use by other/future queues)?'");
$this->addTask('Add column "civicrm_user_job.is_template"', 'addColumn', 'civicrm_user_job',
'is_template', "tinyint NOT NULL DEFAULT 0 COMMENT 'Is this a template configuration (for use by other/future jobs)?'");
$this->addTask('Backfill "civicrm_queue.status" and "civicrm_queue.error")', 'fillQueueColumns');
}
......
......@@ -107,6 +107,38 @@ class CRM_Queue_QueueTest extends CiviUnitTestCase {
}
}
public function testTemplating() {
\Civi\Api4\Queue::create()->setValues([
'is_template' => TRUE,
'name' => 'test/template',
'type' => 'SqlParallel',
'runner' => 'task',
'error' => 'delete',
])->execute();
$this->assertDBQuery(1, "SELECT is_template FROM civicrm_queue WHERE name = 'test/template'");
$qActive = Civi::queue('test/my-active', [
'template' => 'test/template',
]);
$this->assertEquals('test/my-active', $qActive->getName());
$this->assertEquals('SqlParallel', $qActive->getSpec('type'));
$this->assertEquals('task', $qActive->getSpec('runner'));
$this->assertEquals('delete', $qActive->getSpec('error'));
$this->assertDBQuery('active', "SELECT status FROM civicrm_queue WHERE name = 'test/my-active'");
$this->assertDBQuery(0, "SELECT is_template FROM civicrm_queue WHERE name = 'test/my-active'");
$qDraft = Civi::queue('test/my-draft', [
'template' => 'test/template',
'status' => 'draft',
]);
$this->assertEquals('test/my-draft', $qDraft->getName());
$this->assertEquals('SqlParallel', $qDraft->getSpec('type'));
$this->assertEquals('task', $qDraft->getSpec('runner'));
$this->assertEquals('delete', $qDraft->getSpec('error'));
$this->assertDBQuery('draft', "SELECT status FROM civicrm_queue WHERE name = 'test/my-draft'");
$this->assertDBQuery(0, "SELECT is_template FROM civicrm_queue WHERE name = 'test/my-active'");
}
/**
* Create a few queue items; alternately enqueue and dequeue various
*
......
......@@ -153,4 +153,17 @@
<serialize>JSON</serialize>
<add>5.50</add>
</field>
<field>
<name>is_template</name>
<title>Is Template</title>
<type>boolean</type>
<required>true</required>
<default>0</default>
<comment>Is this a template configuration (for use by other/future jobs)?</comment>
<html>
<type>CheckBox</type>
<label>Is Template</label>
</html>
<add>5.51</add>
</field>
</table>
......@@ -154,4 +154,17 @@
<callback>CRM_Queue_BAO_Queue::getErrorModes</callback>
</pseudoconstant>
</field>
<field>
<name>is_template</name>
<title>Is Template</title>
<type>boolean</type>
<required>true</required>
<default>0</default>
<comment>Is this a template configuration (for use by other/future queues)?</comment>
<html>
<type>CheckBox</type>
<label>Is Template</label>
</html>
<add>5.51</add>
</field>
</table>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment