|
From: <gem...@li...> - 2012-02-29 15:17:44
|
Revision: 518
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=518&view=rev
Author: mennodekker
Date: 2012-02-29 15:17:37 +0000 (Wed, 29 Feb 2012)
Log Message:
-----------
Started on porting to upgrade system to be able to run tasks, CreateNewTables should still be split into smaller tasks
Modified Paths:
--------------
trunk/library/classes/Gems/Default/UpgradeAction.php
trunk/library/classes/Gems/Task/TaskRunnerBatch.php
trunk/library/classes/Gems/Upgrades.php
trunk/library/classes/Gems/UpgradesAbstract.php
Added Paths:
-----------
trunk/library/classes/Gems/Task/CleanCache.php
trunk/library/classes/Gems/Task/CreateNewTables.php
trunk/library/classes/Gems/Task/Echo.php
trunk/library/classes/Gems/Task/ExecutePatch.php
Modified: trunk/library/classes/Gems/Default/UpgradeAction.php
===================================================================
--- trunk/library/classes/Gems/Default/UpgradeAction.php 2012-02-29 09:56:41 UTC (rev 517)
+++ trunk/library/classes/Gems/Default/UpgradeAction.php 2012-02-29 15:17:37 UTC (rev 518)
@@ -84,16 +84,16 @@
$this->html->h3(sprintf($this->_('Upgrading %s'), $context));
- $this->_upgrades->execute($context, $to, $from);
- $messages = $this->_upgrades->getMessages();
- foreach($messages as $message) {
- $this->html->p($message);
+ $batch = $this->loader->getTaskRunnerBatch('upgrade' . $context);
+ $batch->minimalStepDurationMs = 0;
+
+ if (!$batch->isLoaded()) {
+ $this->_upgrades->setBatch($batch);
+ $this->_upgrades->execute($context, $to, $from);
}
- if ($menuItem = $this->menu->find(array('controller' => $this->_getParam('controller'), 'action' => 'show', 'allowed' => true))) {
- $this->html->br();
- $this->html[] = $menuItem->toActionLinkLower($this->getRequest(), array('id'=>$context), $this->_('Back'));
- }
+ $title = $this->_('Performing upgrade');
+ $this->_helper->BatchRunner($batch, $title);
}
/**
Added: trunk/library/classes/Gems/Task/CleanCache.php
===================================================================
--- trunk/library/classes/Gems/Task/CleanCache.php (rev 0)
+++ trunk/library/classes/Gems/Task/CleanCache.php 2012-02-29 15:17:37 UTC (rev 518)
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @package Gems
+ * @subpackage Task
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: CheckTokenCompletion.php 502 2012-02-20 14:13:20Z mennodekker $
+ */
+
+/**
+ * Cleans the cache during a batch job
+ *
+ * Normally when performing certain upgrades you need to clean the cache. When you use
+ * this task you can schedule this too. Normally using ->setTask('CleanCache', 'clean')
+ * will be sufficient as we only need to run the cache cleaning once. for immidiate cache
+ * cleaning, for example when the next task depends on it, perform the actions below
+ * in your own task.
+ *
+ * @package Gems
+ * @subpackage Task
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.6
+ */
+class Gems_Task_CleanCache extends Gems_Task_TaskAbstract
+{
+ public function execute($text = null)
+ {
+ $cache = GemsEscort::getInstance()->cache;
+
+ if ($cache instanceof Zend_Cache_Core) {
+ $cache->clean();
+ $this->_batch->addMessage($this->translate->_('Cache cleaned'));
+ }
+ }
+}
Added: trunk/library/classes/Gems/Task/CreateNewTables.php
===================================================================
--- trunk/library/classes/Gems/Task/CreateNewTables.php (rev 0)
+++ trunk/library/classes/Gems/Task/CreateNewTables.php 2012-02-29 15:17:37 UTC (rev 518)
@@ -0,0 +1,112 @@
+<?php
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @package Gems
+ * @subpackage Task
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: CheckTokenCompletion.php 502 2012-02-20 14:13:20Z mennodekker $
+ */
+
+/**
+ * Execute a certain patchlevel
+ *
+ * Cleans the cache when patches where executed
+ *
+ * @package Gems
+ * @subpackage Task
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.6
+ */
+class Gems_Task_CreateNewTables extends Gems_Task_TaskAbstract
+{
+ /**
+ * @var Zend_Db_Adapter_Abstract
+ */
+ public $db;
+
+ /**
+ * @var Gems_Model_DbaModel
+ */
+ public $dbaModel;
+
+ /**
+ * @var GemsEscort
+ */
+ public $escort;
+
+ /**
+ * @var Gems_Project_ProjectSettings
+ */
+ public $project;
+
+ public function execute()
+ {
+ //Now create all new tables
+ $todo = $this->dbaModel->load(array('state'=> Gems_Model_DbaModel::STATE_DEFINED));
+ $i = 1;
+ $oCount = count($todo);
+ $results = array();
+ foreach($todo as $tableData) {
+ $result = $this->dbaModel->runScript($tableData);
+ $results = array_merge($results, $result);
+ $results[] = sprintf($this->translate->_('Finished %s creation script for object %d of %d'), $this->translate->_(strtolower($tableData['type'])), $i, $oCount) . '<br/>';
+ $i++;
+ }
+
+ foreach ($results as $result)
+ {
+ $this->_batch->addMessage($result);
+ }
+
+ if (count($results)>0) {
+ //Perform a clean cache only when needed
+ $this->_batch->setTask('CleanCache', 'cleancache'); //If already scheduled, don't reschedule
+ }
+ }
+
+ /**
+ * Now we have the requests answered, add the DatabasePatcher as it needs the db object
+ *
+ * @return boolean
+ */
+ public function checkRegistryRequestsAnswers() {
+ $this->escort = GemsEscort::getInstance();
+
+ //Load the dbaModel
+ $paths = $this->escort->getDatabasePaths();
+ $model = new Gems_Model_DbaModel($this->db, array_values($paths));
+ $model->setLocations(array_keys($paths));
+ if ($this->project->databaseFileEncoding) {
+ $model->setFileEncoding($this->project->databaseFileEncoding);
+ }
+ $this->dbaModel = $model;
+
+ return true;
+ }
+}
\ No newline at end of file
Added: trunk/library/classes/Gems/Task/Echo.php
===================================================================
--- trunk/library/classes/Gems/Task/Echo.php (rev 0)
+++ trunk/library/classes/Gems/Task/Echo.php 2012-02-29 15:17:37 UTC (rev 518)
@@ -0,0 +1,50 @@
+<?php
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @package Gems
+ * @subpackage Task
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: CheckTokenCompletion.php 502 2012-02-20 14:13:20Z mennodekker $
+ */
+
+/**
+ * Just echo a string during a batch job
+ *
+ * @package Gems
+ * @subpackage Task
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.6
+ */
+class Gems_Task_Echo extends Gems_Task_TaskAbstract
+{
+ public function execute($text = null)
+ {
+ $this->_batch->addMessage($text);
+ }
+}
\ No newline at end of file
Added: trunk/library/classes/Gems/Task/ExecutePatch.php
===================================================================
--- trunk/library/classes/Gems/Task/ExecutePatch.php (rev 0)
+++ trunk/library/classes/Gems/Task/ExecutePatch.php 2012-02-29 15:17:37 UTC (rev 518)
@@ -0,0 +1,92 @@
+<?php
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @package Gems
+ * @subpackage Task
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: CheckTokenCompletion.php 502 2012-02-20 14:13:20Z mennodekker $
+ */
+
+/**
+ * Execute a certain patchlevel
+ *
+ * Cleans the cache when patches where executed
+ *
+ * @package Gems
+ * @subpackage Task
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.6
+ */
+class Gems_Task_ExecutePatch extends Gems_Task_TaskAbstract
+{
+ /**
+ * @var Zend_Db_Adapter_Abstract
+ */
+ public $db;
+
+ /**
+ * @var GemsEscort
+ */
+ public $escort;
+
+ /**
+ *
+ * @var Gems_Util_DatabasePatcher
+ */
+ public $patcher;
+
+ public function execute($patchLevel = null, $ignoreCompleted = true, $ignoreExecuted = false)
+ {
+ $this->_batch->addMessage(sprintf($this->translate->_('Executing patchlevel %d'), $patchLevel));
+ $result = $this->patcher->executePatch($patchLevel, $ignoreCompleted, $ignoreExecuted);
+ $this->_batch->addMessage($this->translate->_(sprintf('Executed %s patches', $result)));
+
+ if ($result>0) {
+ //Perform a clean cache only when needed
+ $this->_batch->setTask('CleanCache', 'cleancache'); //If already scheduled, don't reschedule
+ }
+ }
+
+ /**
+ * Now we have the requests answered, add the DatabasePatcher as it needs the db object
+ *
+ * @return boolean
+ */
+ public function checkRegistryRequestsAnswers() {
+ $this->escort = GemsEscort::getInstance();
+
+ //As an upgrade almost always includes executing db patches, make a DatabasePatcher object available
+ $this->patcher = new Gems_Util_DatabasePatcher($this->db, 'patches.sql', $this->escort->getDatabasePaths());
+
+ //Now load all patches, and save the resulting changed patches for later (not used yet)
+ $changed = $this->patcher->uploadPatches($this->loader->getVersions()->getBuild());
+
+ return true;
+ }
+}
\ No newline at end of file
Modified: trunk/library/classes/Gems/Task/TaskRunnerBatch.php
===================================================================
--- trunk/library/classes/Gems/Task/TaskRunnerBatch.php 2012-02-29 09:56:41 UTC (rev 517)
+++ trunk/library/classes/Gems/Task/TaskRunnerBatch.php 2012-02-29 15:17:37 UTC (rev 518)
@@ -103,8 +103,12 @@
{
$params = array_slice(func_get_args(), 1);
$taskClass = $this->loader->getTask($task);
- $taskClass->setBatch($this);
- call_user_func_array(array($taskClass, 'execute'), $params[0]);
+ if ($taskClass instanceof Gems_Task_TaskInterface) {
+ $taskClass->setBatch($this);
+ call_user_func_array(array($taskClass, 'execute'), $params[0]);
+ } else {
+ throw new Gems_Exception(sprintf('ERROR: Task by name %s not found', $task));
+ }
}
/**
Modified: trunk/library/classes/Gems/Upgrades.php
===================================================================
--- trunk/library/classes/Gems/Upgrades.php 2012-02-29 09:56:41 UTC (rev 517)
+++ trunk/library/classes/Gems/Upgrades.php 2012-02-29 15:17:37 UTC (rev 518)
@@ -67,18 +67,11 @@
*/
public function Upgrade143to15()
{
- $this->addMessage(sprintf($this->_('Executing patchlevel %d'),42));
- $this->patcher->executePatch(42);
- $this->addMessage(sprintf($this->_('Executing patchlevel %d'),43));
- $this->patcher->executePatch(43);
+ $this->_batch->addTask('ExecutePatch', 42);
+ $this->_batch->addTask('ExecutePatch', 43);
- $this->invalidateCache();
+ $this->_batch->addTask('CreateNewTables');
- $this->addMessage($this->_('Creating new tables'));
- $this->createNewTables();
-
- $this->invalidateCache();
-
$this->addMessage($this->_('Syncing surveys for all sources'));
//Now sync the db sources to allow limesurvey source to add a field to the tokentable
$model = new MUtil_Model_TableModel('gems__sources');
@@ -106,11 +99,8 @@
*/
public function Upgrade15to151()
{
- $this->addMessage(sprintf($this->_('Executing patchlevel %d'),44));
- $this->patcher->executePatch(44);
-
- $this->invalidateCache();
-
+ $this->_batch->addTask('ExecutePatch', 44);
+
return true;
}
}
\ No newline at end of file
Modified: trunk/library/classes/Gems/UpgradesAbstract.php
===================================================================
--- trunk/library/classes/Gems/UpgradesAbstract.php 2012-02-29 09:56:41 UTC (rev 517)
+++ trunk/library/classes/Gems/UpgradesAbstract.php 2012-02-29 15:17:37 UTC (rev 518)
@@ -54,6 +54,11 @@
protected $upgradeFile;
/**
+ * @var Gems_Task_TaskRunnerBatch
+ */
+ protected $_batch;
+
+ /**
* @var Zend_Config_Ini
*/
protected $_info;
@@ -426,6 +431,16 @@
}
/**
+ * Set the batch to use
+ *
+ * @param Gems_Task_TaskRunnerBatch $batch
+ */
+ public function setBatch($batch)
+ {
+ $this->_batch = $batch;
+ }
+
+ /**
* Change the active context
*
* Usefull when adding upgrades in the construct to save typing
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|