Skip to content

Commit

Permalink
CRM-16860 - CRM_Upgrade_Steps - Identify *.mysql.tpl files
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Dec 14, 2015
1 parent 6158210 commit 5767b11
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 25 deletions.
77 changes: 77 additions & 0 deletions CRM/Upgrade/Incremental/SqlStep.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* Class CRM_Upgrade_Incremental_SqlStep
*
* This classes requests any *.mysql.tpl steps.
*/
class CRM_Upgrade_Incremental_SqlStep implements CRM_Upgrade_Incremental_Interface {

private $file;

private $name;

/**
* CRM_Upgrade_Incremental_SqlStep constructor.
* @param $file
* @param $name
*/
public function __construct($file, $name) {
$this->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));
}

}
45 changes: 20 additions & 25 deletions CRM/Upgrade/Steps.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -62,48 +63,42 @@ 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))
);
}
}
}
ksort($result);
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;
Expand Down

0 comments on commit 5767b11

Please sign in to comment.