Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) CRM-16860 - Schema-upgrader should be merge-friendly #7440

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ CRM/Core/DAO/UFField.php
CRM/Core/DAO/UFGroup.php
CRM/Core/DAO/UFJoin.php
CRM/Core/DAO/UFMatch.php
CRM/Core/DAO/Upgrade.php
CRM/Core/DAO/Website.php
CRM/Core/DAO/WordReplacement.php
CRM/Core/DAO/Worldregion.php
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact {
* @see self::triggerInfo()
*
* Note that this is also used by the 4.3 upgrade script.
* @see CRM_Upgrade_Incremental_php_FourThree
* @see CRM_Upgrade_Steps_43_All
*/
const DROP_STRIP_FUNCTION_43 = "DROP FUNCTION IF EXISTS civicrm_strip_non_numeric";
const CREATE_STRIP_FUNCTION_43 = "
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/BAO/WordReplacement.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public static function rebuild($clearCaches = TRUE) {
* and convert them to params for the WordReplacement.create API.
*
* Note: This function is duplicated in CRM_Core_BAO_WordReplacement and
* CRM_Upgrade_Incremental_php_FourFour to ensure that the incremental upgrade
* CRM_Upgrade_Steps_44_All to ensure that the incremental upgrade
* step behaves consistently even as the BAO evolves in future versions.
* However, if there's a bug in here prior to 4.4.0, we should apply the
* bug-fix in both places.
Expand Down Expand Up @@ -265,7 +265,7 @@ public static function getConfigArraysAsAPIParams($rebuildEach) {
* and write them out as records in civicrm_word_replacement.
*
* Note: This function is duplicated in CRM_Core_BAO_WordReplacement and
* CRM_Upgrade_Incremental_php_FourFour to ensure that the incremental upgrade
* CRM_Upgrade_Steps_44_All to ensure that the incremental upgrade
* step behaves consistently even as the BAO evolves in future versions.
* However, if there's a bug in here prior to 4.4.0, we should apply the
* bug-fix in both places.
Expand Down
11 changes: 11 additions & 0 deletions CRM/Core/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ public function loadClass($class) {
// intelligible errors.
if (FALSE != stream_resolve_include_path($file)) {
require_once $file;
return;
}

// CRM/Upgrade/Steps/{NUM}_{TextName}.up.php
// CRM/Upgrade/Steps/{NUM}/{NUM}_{TextName}.up.php
if (preg_match('/_[0-9]+_/', $class)) {
$file = preg_replace('/\/([0-9]+)\/([A-Z][a-zA-Z0-9]+)$/', '/\1_\2', strtr($class, '_', '/')) . '.up.php';
if (FALSE != stream_resolve_include_path($file)) {
require_once $file;
return;
}
}
}
}
Expand Down
147 changes: 147 additions & 0 deletions CRM/Queue/MultiTasker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?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 |
+--------------------------------------------------------------------+
*/

/**
* A multitasker is a helper for defining several inter-related tasks
* (e.g. where one task fires off others tasks).
*
* @code
* class Foo extends CRM_Queue_MultiTasker {
* public function foo() {
* $this->addTask('Do the bar thing', 'bar', 123);
* $this->addTask('Do the bar thing', 'bar', 456);
* }
* public function bar($x) {
* $this->ctx->log->info("Got value $x");
* }
* }
* @endCode
*/
class CRM_Queue_MultiTasker {

/**
* @var CRM_Queue_TaskContext
*/
protected $ctx;

/**
* @var array
* Quasi-persistent data that's serialized and restored whenever we
* run a task for this class.
*/
protected $stickyData;

/**
* CRM_Upgrade_Incremental_SimpleBase constructor.
*
* @param CRM_Queue_TaskContext|NULL $ctx
* @param array|NULL $stickyData
*/
public function __construct($ctx = NULL, $stickyData = array()) {
$this->ctx = $ctx;
$this->stickyData = $stickyData;
if (!isset($this->stickyData['class'])) {
$this->stickyData['class'] = get_class($this);
}
if ($ctx && !isset($this->stickyData['queue'])) {
$this->stickyData['queue'] = $ctx->queue->getName();
}
}

/**
* Syntactic sugar for adding a task.
*
* Task is (a) in this class and (b) has a very high priority.
*
* After passing the $funcName, you can also pass parameters that will go to
* the function. Note that all params must be serializable.
*
* Given the very high priority, this is intended for last-minute additions to the start
* of the queue. It should *not* be used for initializing the queue.
*
* @param string $title
* @param string $funcName
*/
public function addTask($title, $funcName) {
$task = call_user_func_array(array($this, 'createTask'), func_get_args());
$this->getQueue()->createItem($task, array('weight' => -1));
}

public function addInitialTask($title, $funcName) {
$task = call_user_func_array(array($this, 'createTask'), func_get_args());
$this->getQueue()->createItem($task, array('weight' => 0));
}

/**
* Create a task which points to local function (in this class).
*
* After passing the $funcName, you can also pass parameters that will go to
* the function. Note that all params must be serializable.
*
* Note: The task is *not* enqueued.
*
* @param $title
* @param $funcName
* @return \CRM_Queue_Task
*/
protected function createTask($title, $funcName) {
$funcArgs = func_get_args();
$title = array_shift($funcArgs);
$funcName = array_shift($funcArgs);
$task = new CRM_Queue_Task(
array(get_class($this), 'doTask'),
array($this->stickyData, $funcName, $funcArgs),
$title
);
return $task;
}

/**
* @return \CRM_Queue_Queue
*/
protected function getQueue() {
$queue = CRM_Queue_Service::singleton()->load(array(
'type' => 'Sql',
'name' => $this->stickyData['queue'],
));
return $queue;
}

public static function doTask(CRM_Queue_TaskContext $ctx, $stickyData, $funcName, $funcArgs) {
// FIXME
// $upgrade = new CRM_Upgrade_Form();
// $upgrade->setSchemaStructureTables($rev);

/** @var self $obj */
$className = $stickyData['class'];
$obj = new $className($ctx, $stickyData);
call_user_func_array(array($obj, $funcName), $funcArgs);

return TRUE;
}

}
Loading