From: <gem...@li...> - 2011-11-08 09:42:21
|
Revision: 189 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=189&view=rev Author: mennodekker Date: 2011-11-08 09:42:10 +0000 (Tue, 08 Nov 2011) Log Message: ----------- Added controller for #34, privileges not set by default at this time Modified Paths: -------------- trunk/library/classes/Gems/Menu.php trunk/library/classes/Gems/UpgradesAbstract.php Added Paths: ----------- trunk/library/classes/Gems/Default/UpgradeAction.php trunk/library/controllers/UpgradeController.php Added: trunk/library/classes/Gems/Default/UpgradeAction.php =================================================================== --- trunk/library/classes/Gems/Default/UpgradeAction.php (rev 0) +++ trunk/library/classes/Gems/Default/UpgradeAction.php 2011-11-08 09:42:10 UTC (rev 189) @@ -0,0 +1,193 @@ +<?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 Default + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $ + */ + +/** + * This controller handles applying upgrades to the project + * + * @package Gems + * @subpackage Default + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class Gems_Default_UpgradeAction extends Gems_Controller_Action +{ + public $useHtmlView = true; + + /** + * @var Gems_Menu + */ + public $menu; + + /** + * @var Gems_Upgrades + */ + protected $_upgrades; + + public function init() + { + parent::init(); + + $this->_upgrades = $this->loader->getUpgrades(); + + } + + /** + * + * @var Gems_Loader + */ + public $loader; + + /** + * Executes the upgrades for a certain context + * + * optional: give from and to levels + * + * usage: execute/context/<context>{/from/int/to/int} + */ + protected function executeAction() + { + $context = $this->getRequest()->getParam('id', 'gems'); + $from = $this->getRequest()->getParam('from'); + $to = $this->getRequest()->getParam('to'); + + $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); + } + + 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)); + } + } + + /** + * Proxy for the menu + */ + public function executeAllAction() { + $this->executeAction(); + } + + public function executeFromAction() { + $this->executeAction(); + } + + public function executeOneAction() { + $this->executeAction(); + } + + public function executeToAction() { + $this->executeAction(); + } + + /** + * Overview of available contexts, max upgrade level and achieved upgrade level + */ + public function indexAction() + { + $this->html->h3($this->getTopicTitle()); + + $displayColumns = array('link' => '', + 'context' => $this->_('Context'), + 'maxLevel' => $this->_('Max level'), + 'level' => $this->_('Level')); + + foreach($this->_upgrades->getUpgradesInfo() as $row) { + if ($menuItem = $this->menu->find(array('controller' => $this->_getParam('controller'), 'action' => 'show', 'allowed' => true))) { + $row['link'] = $menuItem->toActionLinkLower($this->getRequest(), $row); + } + $data[] = $row; + + } + $this->addSnippet('SelectiveTableSnippet', 'data', $data, 'class', 'browser', 'columns', $displayColumns); + } + + /** + * Show the upgrades and level for a certain context + * + * Usage: show/context/<context> + */ + public function showAction() + { + $this->html->h3($this->getTopicTitle()); + + $context = $this->_getParam('id', 'gems'); + $this->_upgrades->setContext($context); + if ($info = $this->_upgrades->getUpgradesInfo($context)) { + $this->html->table(array('class'=>'browser'))->tr() + ->th($this->_('Context'))->td($info['context']) + ->tr() + ->th($this->_('Level'))->td($info['level']); + $data = $this->_upgrades->getUpgrades(); + foreach($data as $level => $row) { + foreach($this->menu->getCurrent()->getChildren() as $menuItem) { + if ($menuItem->is('allowed', true)) { + $show = true; + if ($level <= $info['level'] && $menuItem->is('action','execute-to')) { + //When this level is < current level don't allow to execute from current level to this one + $show = false; + } + if ($level <= $info['level'] && $menuItem->is('action','execute-from')) { + //When this level is < current level don't allow to execute from current level to this one + $show = false; + } + if ($show) { + $row['action'][] = $menuItem->toActionLinkLower($this->getRequest(), $row, array('from'=>$level, 'to'=>$level)); + } + } + } + $row['level'] = $level; + $data[$level] = $row; + } + $displayColumns = array('level' => $this->_('Level'), + 'info' => $this->_('Description'), + 'action' => $this->_('Action')); + $this->addSnippet('SelectiveTableSnippet', 'data', $data, 'class', 'browser', 'columns', $displayColumns); + } else { + $this->html[] = sprintf($this->_('Context %s not found!'), $context); + } + } + + public function getTopicTitle() { + return $this->_('Upgrades'); + } + + public function getTopic($n = 1) { + return $this->_('Upgrades'); + } +} \ No newline at end of file Modified: trunk/library/classes/Gems/Menu.php =================================================================== --- trunk/library/classes/Gems/Menu.php 2011-11-07 15:30:23 UTC (rev 188) +++ trunk/library/classes/Gems/Menu.php 2011-11-08 09:42:10 UTC (rev 189) @@ -213,6 +213,14 @@ $logMaint = $page->addPage($this->_('Maintenance'), 'pr.log.maintenance', 'log-maintenance'); $logMaint->addAutofilterAction(); $logMaint->addEditAction('pr.log.maintenance'); + + //UPGRADES CONTROLLER + $page = $setup->addPage($this->_('Upgrade'), 'pr.upgrade', 'upgrade', 'index'); + $show = $page->addAction($this->_('Show'), null, 'show')->setNamedParameters('id','context'); + $page->addAction($this->_('Execute all'), 'pr.upgrade.all', 'execute-all')->setModelParameters(1); + $show->addActionButton($this->_('Execute this'), 'pr.upgrade.one', 'execute-one')->setModelParameters(1)->addNamedParameters('from','from','to','to'); + $show->addActionButton($this->_('Execute from here'), 'pr.upgrade.from', 'execute-from')->setModelParameters(1)->addNamedParameters('from','from'); + $show->addActionButton($this->_('Execute to here'), 'pr.upgrade.to', 'execute-to')->setModelParameters(1)->addNamedParameters('to','to'); return $setup; } Modified: trunk/library/classes/Gems/UpgradesAbstract.php =================================================================== --- trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-07 15:30:23 UTC (rev 188) +++ trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-08 09:42:10 UTC (rev 189) @@ -148,7 +148,7 @@ $to = $this->getMaxLevel($context); } if(is_null($from)) { - $from = $this->getNextLevel(); + $from = $this->getNextLevel($context); if ($from > $to) { $this->addMessage($this->_('Already at max. level.')); @@ -165,7 +165,7 @@ ksort($upgrades); $this->_upgradeStack[$context] = $upgrades; foreach($this->_upgradeStack[$context] as $level => $upgrade) { - if (($level > $from && $level <= $to)) { + if (($level >= $from && $level <= $to)) { $this->addMessage(sprintf($this->_('Trying upgrade for %s to level %s: %s'), $context, $level, $this->_upgradeStack[$context][$level]['info'])); if (call_user_func($upgrade['upgrade'])) { $success = $level; @@ -244,10 +244,11 @@ $current = array_search($level, $levels); //And if it is present, return the next level - if (isset($levels[$current++])) return $levels[$current++]; + $current++; + if (isset($levels[$current])) return $levels[$current]; //Else return current level +1 (doesn't exist anyway) - return $level++; + return ++$level; } public function getMessages() Added: trunk/library/controllers/UpgradeController.php =================================================================== --- trunk/library/controllers/UpgradeController.php (rev 0) +++ trunk/library/controllers/UpgradeController.php 2011-11-08 09:42:10 UTC (rev 189) @@ -0,0 +1,30 @@ +<?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. + */ +class UpgradeController extends Gems_Default_UpgradeAction +{ +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |