From a925bc06232a1f6f3c061087833da3ed467da8bf Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 3 Aug 2023 01:29:09 -0700 Subject: [PATCH] CRM_Upgrade_Snapshot - Add helper `createSingleTask()` This is an alternative to `createTasks()`. It's suitable for the kinds of small/mid-sized queries that appear in `*.mysql.tpl` files. --- CRM/Upgrade/Snapshot.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CRM/Upgrade/Snapshot.php b/CRM/Upgrade/Snapshot.php index 90b66e418b..4e1addf2fa 100644 --- a/CRM/Upgrade/Snapshot.php +++ b/CRM/Upgrade/Snapshot.php @@ -165,6 +165,37 @@ class CRM_Upgrade_Snapshot { } } + /** + * Generate the query/queries for storing a snapshot (if the local policy supports snapshotting). + * + * This method does all updates in one go. It is suitable for small/moderate data-sets. If you need to support + * larger data-sets, use createTasks() instead. + * + * @param string $owner + * Name of the component/module/extension that owns the snapshot. + * Ex: 'civicrm' + * @param string $version + * Ex: '5.50' + * @param string $name + * @param string $select + * Raw SQL SELECT for finding data. + * @throws \CRM_Core_Exception + * @return string[] + * SQL statements to execute. + * May be array if there no statements to execute. + */ + public static function createSingleTask(string $owner, string $version, string $name, string $select): array { + $destTable = static::createTableName($owner, $version, $name); + if (!empty(CRM_Upgrade_Snapshot::getActivationIssues())) { + return []; + } + + $result = []; + $result[] = "DROP TABLE IF EXISTS `{$destTable}`"; + $result[] = "CREATE TABLE `{$destTable}` ROW_FORMAT=COMPRESSED AS {$select}"; + return $result; + } + /** * @param \CRM_Queue_TaskContext $ctx * @param string $sql -- 2.25.1