From: <gem...@li...> - 2011-11-04 14:01:24
|
Revision: 185 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=185&view=rev Author: mennodekker Date: 2011-11-04 14:01:18 +0000 (Fri, 04 Nov 2011) Log Message: ----------- Minor fixes for #34 Modified Paths: -------------- trunk/library/classes/Gems/UpgradesAbstract.php Modified: trunk/library/classes/Gems/UpgradesAbstract.php =================================================================== --- trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-04 12:49:12 UTC (rev 184) +++ trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-04 14:01:18 UTC (rev 185) @@ -145,7 +145,7 @@ public function execute($context, $to = null, $from = null) { if(is_null($to)) { - $to = count($this->_upgradeStack[$context]); + $to = $this->getMaxLevel($context); } if(is_null($from)) { $from = $this->getLevel($context); @@ -214,7 +214,24 @@ return $this->_messages; } - public function getUpgrades($requestedContext = null) + /** + * Retrieve the upgrades for a certain context, will return an empty array when nothing present. + * + * @param string $context + * @return array + */ + public function getUpgrades($context = null) { + if (! $context) { + $context = $this->getContext(); + } + + if (isset($this->_upgradeStack[$context])) { + return $this->_upgradeStack[$context]; + } + return array(); + } + + public function getUpgradesInfo($requestedContext = null) { $result = array(); foreach($this->_upgradeStack as $context => $content) { @@ -237,7 +254,7 @@ public function register($callback, $index = null, $context = null) { if (is_string($callback)) { - $callback = array($this, $callback); + $callback = array(get_class($this), $callback); } if (is_callable($callback)) { if (! $context) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-08 10:42:08
|
Revision: 192 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=192&view=rev Author: mennodekker Date: 2011-11-08 10:42:02 +0000 (Tue, 08 Nov 2011) Log Message: ----------- A little more documentation Modified Paths: -------------- trunk/library/classes/Gems/UpgradesAbstract.php Modified: trunk/library/classes/Gems/UpgradesAbstract.php =================================================================== --- trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-08 10:32:48 UTC (rev 191) +++ trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-08 10:42:02 UTC (rev 192) @@ -25,8 +25,6 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * Short description of file - * * @package Gems * @subpackage Upgrades * @copyright Copyright (c) 2011 Erasmus MC @@ -35,10 +33,10 @@ */ /** - * Short description for Upgrades + * This class can take care of handling upgrades that can not be achieved by a + * simple db patch. For example adding an extra attribute to all token tables + * in LimeSurvey needs a simple loop. * - * Long description for class Upgrades (if any)... - * * @package Gems * @subpackage Upgrades * @copyright Copyright (c) 2011 Erasmus MC @@ -142,6 +140,18 @@ $this->_messages = array(); } + /** + * Execute upgrades for the given $context + * + * When no $to or $from are given, the given $context will be upgraded from the current level + * to the max level. Otherwise the $from and/or $to will be used to determine what upgrades + * to execute. + * + * @param string $context The context to execute the upgrades for + * @param int|null $to The level to upgrade to + * @param int|null $from The level to start the upgrade on + * @return false|int The achieved upgrade level or false on failure + */ public function execute($context, $to = null, $from = null) { if(is_null($to)) { @@ -182,21 +192,32 @@ return $success; } + /** + * Retrieve the current context + * + * @return string + */ public function getContext() { return $this->_context; } + /** + * Get the current upgrade level for the given $context + * + * @param string $context + * @return int + */ public function getLevel($context) { if(isset($this->_info->$context)) { - return $this->_info->$context; + return intval($this->_info->$context); } else { return 0; } } /** - * Get the highest level for the given context + * Get the highest level for the given $context * * @param string|null $context * @return int @@ -251,6 +272,11 @@ return ++$level; } + /** + * Get all messages that were recorded during the upgrade process + * + * @return array + */ public function getMessages() { return $this->_messages; @@ -273,6 +299,12 @@ return array(); } + /** + * Retrieve info about the $requestedContext or all contexts when omitted + * + * @param string $requestedContext + * @return array + */ public function getUpgradesInfo($requestedContext = null) { $result = array(); @@ -293,6 +325,19 @@ } } + /** + * Register an upgrade in the stack, it can be executed by using $this->execute + * + * Index and context are optional and will be generated when omitted. For the + * user interface to be clear $info should provide a good description of what + * the upgrade does. + * + * @param array|string $callback A valid callback, either string for a method of the current class or array otherwise + * @param string $info A descriptive message about what this upgrade does + * @param int $index The number of the upgrade + * @param string $context The context to which this upgrade applies + * @return boolean + */ public function register($callback, $info = null, $index = null, $context = null) { if (is_string($callback)) { @@ -325,10 +370,27 @@ return false; } + /** + * Change the active context + * + * Usefull when adding upgrades in the construct to save typing + * + * @param string $context + */ public function setContext($context) { $this->_context = $context; } + /** + * Set the upgrade level for the given $context to a certain level + * + * Will only update when the $level is higher than the achieved level, unless + * when $force = true when it will always update. + * + * @param string $context + * @param int $level + * @param boolean $force + */ protected function setLevel($context, $level = null, $force = false) { if (!is_null($level) && This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-07-30 14:47:49
|
Revision: 886 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=886&view=rev Author: mennodekker Date: 2012-07-30 14:47:40 +0000 (Mon, 30 Jul 2012) Log Message: ----------- Allow upgrades to run in each environment Modified Paths: -------------- trunk/library/classes/Gems/UpgradesAbstract.php Modified: trunk/library/classes/Gems/UpgradesAbstract.php =================================================================== --- trunk/library/classes/Gems/UpgradesAbstract.php 2012-07-30 08:43:21 UTC (rev 885) +++ trunk/library/classes/Gems/UpgradesAbstract.php 2012-07-30 14:47:40 UTC (rev 886) @@ -51,6 +51,18 @@ protected $_messages = array(); + /** + * Holds the inital config file + * + * @var Zend_Config + */ + protected $originalFile; + + /** + * Holds the config file specific to this environment + * + * @var Zend_Config + */ protected $upgradeFile; /** @@ -93,11 +105,17 @@ //First get a GemsEscort instance, as we might need that a lot (and it can not be injected) $this->escort = GemsEscort::getInstance(); - $this->upgradeFile = GEMS_ROOT_DIR . str_replace('/', DIRECTORY_SEPARATOR , '/var/settings/upgrades.ini'); + $this->originalFile = GEMS_ROOT_DIR . str_replace('/', DIRECTORY_SEPARATOR , '/var/settings/upgrades.ini'); + $this->upgradeFile = GEMS_ROOT_DIR . str_replace('/', DIRECTORY_SEPARATOR , '/var/settings/upgrades_' . APPLICATION_ENV . '.ini'); + if(!file_exists($this->originalFile)) { + touch($this->originalFile); + } if(!file_exists($this->upgradeFile)) { touch($this->upgradeFile); } - $this->_info = new Zend_Config_Ini($this->upgradeFile, null, array('allowModifications' => true)); + $this->_info = new Zend_Config_Ini($this->originalFile, null, array('allowModifications' => true)); + // Merge the environment config file + $this->_info->merge(new Zend_Config_Ini($this->upgradeFile, null, array('allowModifications' => true))); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |