From 5767b113e32a3c1637b9d4032bf5be1bf077117d Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sun, 13 Dec 2015 20:45:04 -0800 Subject: [PATCH] CRM-16860 - CRM_Upgrade_Steps - Identify *.mysql.tpl files --- CRM/Upgrade/Incremental/SqlStep.php | 77 +++++++++++++++++++++++++++++ CRM/Upgrade/Steps.php | 45 ++++++++--------- 2 files changed, 97 insertions(+), 25 deletions(-) create mode 100644 CRM/Upgrade/Incremental/SqlStep.php diff --git a/CRM/Upgrade/Incremental/SqlStep.php b/CRM/Upgrade/Incremental/SqlStep.php new file mode 100644 index 000000000000..d2f7c4b487ff --- /dev/null +++ b/CRM/Upgrade/Incremental/SqlStep.php @@ -0,0 +1,77 @@ +file = $file; + $this->name = $name; + } + + public function createPreUpgradeMessage($startVer, $endVer) { + return NULL; + } + + public function getName() { + return $this->name; + } + + public function buildQueue(CRM_Queue_Queue $queue, $postUpgradeMessageFile, $startVer, $endVer) { + $task = new CRM_Queue_Task( + array('CRM_Upgrade_Incremental_SqlStep', 'doSqlFile'), + array($this->file), + ts('Execute SQL: %1', array( + 1 => $this->file, + )) + ); + $queue->createItem($task); + } + + public static function doSqlFile(CRM_Queue_TaskContext $ctx, $sqlFile) { + $upgrade = new CRM_Upgrade_Form(); + // FIXME: Multilingual and $rev + // $upgrade->setSchemaStructureTables($rev); + // $upgrade->processLocales($sqlFile, $rev); + // return TRUE; + throw new RuntimeException(sprintf("Not implemented: %s::%s for %s", __CLASS__, __FUNCTION__, $sqlFile)); + } + +} \ No newline at end of file diff --git a/CRM/Upgrade/Steps.php b/CRM/Upgrade/Steps.php index d31617c31a96..6eede0608123 100644 --- a/CRM/Upgrade/Steps.php +++ b/CRM/Upgrade/Steps.php @@ -30,8 +30,9 @@ * @copyright CiviCRM LLC (c) 2004-2015 * $Id$ * - * The `CRM_Upgrade_Steps` class tracks upgrade files (eg `CRM/Upgrade/Steps/*.up.php`). - * It can report a list of pending upgrade steps and toggle the "pending" flag. + * The `CRM_Upgrade_Steps` class tracks upgrade files (eg `CRM/Upgrade/Steps/*.up.php` + * or `CRM/Upgrade/Steps/*.mysql.tpl`). It can report a list of pending upgrade steps + * and toggle the "executed" flag. */ class CRM_Upgrade_Steps { @@ -62,18 +63,25 @@ public function __construct($module, $paths = array()) { } /** - * Get a list of all upgrade steps (as class names). + * Get a list of all upgrade steps (as objects/instances). * * @return array - * Array(string $file => string $className). + * Array(CRM_Upgrade_Incremental_Interface). */ - public function getAllClasses() { + public function getAllObjects() { $result = array(); foreach ($this->paths as $path => $classPrefix) { if (is_dir($path)) { - $files = CRM_Utils_File::findFiles($path, '*.up.php'); - foreach ($files as $file) { - $result[$file] = $this->toClassName($path, $classPrefix, $file); + $phpFiles = CRM_Utils_File::findFiles($path, '*.up.php'); + foreach ($phpFiles as $phpFile) { + $className = $this->toClassName($path, $classPrefix, $phpFile); + $result[$phpFile] = new $className(); + } + $sqlFiles = CRM_Utils_File::findFiles($path, '*.mysql.tpl'); + foreach ($sqlFiles as $sqlFile) { + $result[$sqlFile] = new CRM_Upgrade_Incremental_SqlStep($sqlFile, + 'SqlStep:' . CRM_Utils_File::relativize($sqlFile, CRM_Utils_File::addTrailingSlash($path)) + ); } } } @@ -81,29 +89,16 @@ public function getAllClasses() { return $result; } - /** - * Get a list of all upgrade steps (as objects/instances). - * - * @return array - * Array(CRM_Upgrade_Incremental_Interface). - */ - public function getAllObjects() { - $result = array(); - foreach ($this->getAllClasses() as $file => $className) { - $result[$className] = new $className(); - } - return $result; - } - /** * @return array * Array(CRM_Upgrade_Incremental_Interface). */ public function getPendingObjects() { $result = array(); - foreach ($this->getAllClasses() as $file => $className) { - if (!$this->isExecuted($className)) { - $result[] = new $className(); + foreach ($this->getAllObjects() as $upgrade) { + /** @var CRM_Upgrade_Incremental_Interface $upgrade */ + if (!$this->isExecuted($upgrade->getName())) { + $result[] = $upgrade; } } return $result;