$queue->createItem($task, ['weight' => -1]);
}
+ /**
+ * Add a task to store a snapshot of some data (if upgrade-snapshots are supported).
+ *
+ * If there is a large amount of data, this may actually add multiple tasks.
+ *
+ * Ex :$this->addSnapshotTask('event_dates', CRM_Utils_SQL_Select::from('civicrm_event')
+ * ->select('id, start_date, end_date'));
+ *
+ * @param string $name
+ * Logical name for the snapshot. This will become part of the table.
+ * @param \CRM_Utils_SQL_Select $select
+ * @throws \CRM_Core_Exception
+ */
+ protected function addSnapshotTask(string $name, CRM_Utils_SQL_Select $select): void {
+ CRM_Upgrade_Snapshot::createTableName('civicrm', $this->getMajorMinor(), $name);
+ // ^^ To simplify QA -- we should always throw an exception for bad snapshot names, even if the local policy doesn't use snapshots.
+
+ if (!empty(CRM_Upgrade_Snapshot::getActivationIssues())) {
+ return;
+ }
+
+ $queue = CRM_Queue_Service::singleton()->load([
+ 'type' => 'Sql',
+ 'name' => CRM_Upgrade_Form::QUEUE_NAME,
+ ]);
+ foreach (CRM_Upgrade_Snapshot::createTasks('civicrm', $this->getMajorMinor(), $name, $select) as $task) {
+ $queue->createItem($task, ['weight' => -1]);
+ }
+ }
+
/**
* Add a task to activate an extension. This task will run post-upgrade (after all
* changes to core DB are settled).