|
From: <gem...@li...> - 2011-11-08 10:32:56
|
Revision: 191
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=191&view=rev
Author: matijsdejong
Date: 2011-11-08 10:32:48 +0000 (Tue, 08 Nov 2011)
Log Message:
-----------
Merged 177-190
Modified Paths:
--------------
branches/newUser2/classes/Gems/Default/AskAction.php
branches/newUser2/classes/Gems/Default/DatabaseAction.php
branches/newUser2/classes/Gems/Default/RespondentAction.php
branches/newUser2/classes/Gems/Default/StaffAction.php
branches/newUser2/classes/Gems/Default/TrackActionAbstract.php
branches/newUser2/classes/Gems/Loader.php
branches/newUser2/classes/Gems/Menu/SubMenuItem.php
branches/newUser2/classes/Gems/Menu.php
branches/newUser2/classes/Gems/Util/DatabasePatcher.php
branches/newUser2/classes/GemsEscort.php
branches/newUser2/classes/MUtil/Model/FormBridge.php
branches/newUser2/configs/db/tables/gems__user_logins.10.sql
branches/newUser2/pre_bootstrap.php
Added Paths:
-----------
branches/newUser2/classes/Gems/Default/UpgradeAction.php
branches/newUser2/classes/Gems/Upgrades.php
branches/newUser2/classes/Gems/UpgradesAbstract.php
branches/newUser2/controllers/UpgradeController.php
Property Changed:
----------------
branches/newUser2/
Property changes on: branches/newUser2
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/newUser:113-150
+ /branches/newUser:113-150
/trunk/library:177-190
Modified: branches/newUser2/classes/Gems/Default/AskAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/AskAction.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Default/AskAction.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -186,6 +186,9 @@
public function indexAction()
{
+ // Make sure to return to ask screen
+ $this->session->return_controller = $this->getRequest()->getControllerName();
+
$tracker = $this->loader->getTracker();
$max_length = $tracker->getTokenLibrary()->getLength();
@@ -242,11 +245,40 @@
public function returnAction()
{
- if (isset($this->session->user_id)) {
+ if (isset($this->session->user_id) && $this->session->user_id) {
$tracker = $this->loader->getTracker();
$token = $tracker->getToken($tracker->filterToken($this->_getParam(MUtil_Model::REQUEST_ID)));
- $this->_reroute(array('controller' => 'respondent', 'action' => 'show', MUtil_Model::REQUEST_ID => $token->getPatientNumber()), true);
+ // Check for completed tokens
+ $this->loader->getTracker()->processCompletedTokens($token->getRespondentId(), $this->session->user_id);
+
+ if (isset($this->session->return_controller) && $this->session->return_controller) {
+ $return = $this->session->return_controller;
+ } else {
+ $return = 'respondent';
+ }
+
+ $parameters['controller'] = $return;
+ $parameters['action'] = 'show';
+ $parameters[MUtil_Model::REQUEST_ID] = $token->getPatientNumber();
+ switch ($return) {
+ case 'track':
+ $parameters['action'] = 'show-track';
+ $parameters[Gems_Model::RESPONDENT_TRACK] = $token->getRespondentTrackId();
+ break;
+
+ case 'survey':
+ $parameters[MUtil_Model::REQUEST_ID] = $token->getTokenId();
+ break;
+
+ case 'ask':
+ $this->_forward('forward');
+ return;
+
+ default:
+ $parameters['controller'] = 'respondent';
+ }
+ $this->_reroute($parameters, true);
} else {
$this->_forward('forward');
}
Modified: branches/newUser2/classes/Gems/Default/DatabaseAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/DatabaseAction.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Default/DatabaseAction.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -351,8 +351,6 @@
$data['db_level'] = $data['level'];
$form->getElement('db_level')->setValue($data['db_level']);
- $this->db->query('INSERT IGNORE INTO gems__patch_levels (gpl_level, gpl_created) VALUES (?, CURRENT_TIMESTAMP)', $data['level']);
-
$this->addMessage(sprintf($this->_('%d patch(es) executed.'), $changed));
}
Modified: branches/newUser2/classes/Gems/Default/RespondentAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/RespondentAction.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Default/RespondentAction.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -360,6 +360,20 @@
return $this->_('Respondents');
}
+ /**
+ * Initialize translate and html objects
+ *
+ * Called from {@link __construct()} as final step of object instantiation.
+ *
+ * @return void
+ */
+ public function init()
+ {
+ parent::init();
+
+ $this->session->return_controller = $this->getRequest()->getControllerName();
+ }
+
protected function openedRespondent($patientId, $orgId = null, $userId = null)
{
if ($patientId) {
Modified: branches/newUser2/classes/Gems/Default/StaffAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/StaffAction.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Default/StaffAction.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -105,9 +105,9 @@
$bridge->addHidden( 'gus_id_user');
$bridge->addHidden( 'gsf_id_user'); // Needed for e-mail validation
- $bridge->addHidden( 'gus_user_class');
- $bridge->addText( 'gus_login', 'size', 15, 'minlength', 4,
- 'validator', $model->createUniqueValidator('gus_login'));
+ $bridge->addHidden( 'gsu_user_class');
+ $bridge->addText( 'gsu_login', 'size', 15, 'minlength', 4,
+ 'validator', $model->createUniqueValidator('gsu_login', array('gsu_id_user')));
// Can the organization be changed?
if ($this->escort->hasPrivilege('pr.staff.edit.all')) {
Modified: branches/newUser2/classes/Gems/Default/TrackActionAbstract.php
===================================================================
--- branches/newUser2/classes/Gems/Default/TrackActionAbstract.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Default/TrackActionAbstract.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -352,6 +352,20 @@
parent::indexAction();
}
+ /**
+ * Initialize translate and html objects
+ *
+ * Called from {@link __construct()} as final step of object instantiation.
+ *
+ * @return void
+ */
+ public function init()
+ {
+ parent::init();
+
+ $this->session->return_controller = $this->getRequest()->getControllerName();
+ }
+
public function initFilter()
{
// FROM REQUEST
Copied: branches/newUser2/classes/Gems/Default/UpgradeAction.php (from rev 190, trunk/library/classes/Gems/Default/UpgradeAction.php)
===================================================================
--- branches/newUser2/classes/Gems/Default/UpgradeAction.php (rev 0)
+++ branches/newUser2/classes/Gems/Default/UpgradeAction.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -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: branches/newUser2/classes/Gems/Loader.php
===================================================================
--- branches/newUser2/classes/Gems/Loader.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Loader.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -1,6 +1,4 @@
<?php
-
-
/**
* Copyright (c) 2011, Erasmus MC
* All rights reserved.
@@ -90,6 +88,12 @@
/**
*
+ * @var Gems_Upgrades
+ */
+ protected $upgrades;
+
+ /**
+ *
* @var Gems_User_UserLoader
*/
protected $userLoader;
@@ -194,6 +198,15 @@
/**
*
+ * @return Gems_Upgrades
+ */
+ public function getUpgrades()
+ {
+ return $this->_getClass('upgrades');
+ }
+
+ /**
+ *
* @param string $login_name
* @param int $organization
* @return Gems_User_User
Modified: branches/newUser2/classes/Gems/Menu/SubMenuItem.php
===================================================================
--- branches/newUser2/classes/Gems/Menu/SubMenuItem.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Menu/SubMenuItem.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -127,8 +127,8 @@
private function _applyParameterSource($source, $paramFunction, array &$parameters)
{
// Fill in required parameters
- if ($this->_requiredParameters) {
- foreach ($this->_requiredParameters as $param => $name) {
+ if ($this->_parameters && is_array($this->_parameters)) {
+ foreach ($this->_parameters as $param => $name) {
$default = isset($parameters[$param]) ? $parameters[$param] : null;
@@ -491,18 +491,35 @@
$params = MUtil_Ra::pairs(func_get_args());
if (true === $this->_parameters) {
- $this->_parameters = new MUtil_Lazy_ArrayWrap();
+ $this->_parameters = array();
}
foreach ($params as $param => $name) {
if (is_int($param)) {
$param = $name;
}
$this->_requiredParameters[$param] = $name;
- $this->_parameters[$param] = MUtil_Lazy::L($name);
+ $this->_parameters[$param] = $name;
}
return $this;
}
+ public function addOptionalParameters($arrayOrKey1 = null, $altName1 = null)
+ {
+ $params = MUtil_Ra::pairs(func_get_args());
+
+ if (true === $this->_parameters) {
+ $this->_parameters = array();
+ }
+ foreach ($params as $param => $name) {
+ if (is_int($param)) {
+ $param = $name;
+ }
+ //$this->_requiredParameters[$param] = $name;
+ $this->_parameters[$param] = $name;
+ }
+ return $this;
+ }
+
public function addParameters($arrayOrKey1 = null, $key2 = null)
{
$param = MUtil_Ra::args(func_get_args());
Modified: branches/newUser2/classes/Gems/Menu.php
===================================================================
--- branches/newUser2/classes/Gems/Menu.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Menu.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -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;
}
Copied: branches/newUser2/classes/Gems/Upgrades.php (from rev 190, trunk/library/classes/Gems/Upgrades.php)
===================================================================
--- branches/newUser2/classes/Gems/Upgrades.php (rev 0)
+++ branches/newUser2/classes/Gems/Upgrades.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -0,0 +1,71 @@
+<?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.
+ *
+ * Short description of file
+ *
+ * @package Gems
+ * @subpackage Upgrades
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $
+ */
+
+/**
+ * Short description for Upgrades
+ *
+ * Long description for class Upgrades (if any)...
+ *
+ * @package Gems
+ * @subpackage Upgrades
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+class Gems_Upgrades extends Gems_UpgradesAbstract
+{
+ public function __construct()
+ {
+ //Important, ALWAYS run the contruct of our parent object
+ parent::__construct();
+
+ //Now set the context
+ $this->setContext('gems');
+ //And add our patches
+ $this->register('Upgrade143to15', 'Upgrade from 1.43 to 1.5');
+ }
+
+
+ /**
+ * To upgrade from 143 to 15 we need to do some work:
+ * 1. execute db patches
+ */
+ public function Upgrade143to15()
+ {
+ $this->patcher->executePatch(42);
+ return true;
+ }
+}
\ No newline at end of file
Copied: branches/newUser2/classes/Gems/UpgradesAbstract.php (from rev 190, trunk/library/classes/Gems/UpgradesAbstract.php)
===================================================================
--- branches/newUser2/classes/Gems/UpgradesAbstract.php (rev 0)
+++ branches/newUser2/classes/Gems/UpgradesAbstract.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -0,0 +1,342 @@
+<?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.
+ *
+ * Short description of file
+ *
+ * @package Gems
+ * @subpackage Upgrades
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $
+ */
+
+/**
+ * Short description for Upgrades
+ *
+ * Long description for class Upgrades (if any)...
+ *
+ * @package Gems
+ * @subpackage Upgrades
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+class Gems_UpgradesAbstract extends Gems_Loader_TargetLoaderAbstract
+{
+ protected $_context = null;
+
+ protected $_upgradeStack = array();
+
+ protected $_messages = array();
+
+ protected $upgradeFile;
+
+ /**
+ * @var Zend_Config_Ini
+ */
+ protected $_info;
+
+ /**
+ * @var Zend_Db_Adapter_Abstract
+ */
+ public $db;
+
+ /**
+ * @var GemsEscort
+ */
+ public $escort;
+
+ /**
+ * @var Gems_Loader
+ */
+ public $loader;
+
+ /**
+ *
+ * @var Gems_Util_DatabasePatcher
+ */
+ public $patcher;
+
+ /**
+ * @var Zend_Translate_Adapter
+ */
+ public $translate;
+
+ public function __construct()
+ {
+ //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');
+ if(!file_exists($this->upgradeFile)) {
+ touch($this->upgradeFile);
+ }
+ $this->_info = new Zend_Config_Ini($this->upgradeFile, null, array('allowModifications' => true));
+ }
+
+ /**
+ * Proxy to the translate object
+ *
+ * @param string $messageId
+ * @param type $locale
+ * @return string
+ */
+ protected function _($messageId, $locale = null)
+ {
+ return $this->translate->_($messageId, $locale);
+ }
+
+ /**
+ * Add a message to the stack
+ *
+ * @param string $message
+ */
+ protected function addMessage($message)
+ {
+ $this->_messages[] = $message;
+ }
+
+ /**
+ * Now we have the requests answered, add the DatabasePatcher as it needs the db object
+ *
+ * @return boolean
+ */
+ public function checkRegistryRequestsAnswers() {
+ //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());
+ //No load all patches, and save the resulting changed patches for later (not used yet)
+ $changed = $this->patcher->uploadPatches($this->loader->getVersions()->getBuild());
+
+ return true;
+ }
+
+ /**
+ * Reset the message stack
+ */
+ protected function clearMessages()
+ {
+ $this->_messages = array();
+ }
+
+ public function execute($context, $to = null, $from = null)
+ {
+ if(is_null($to)) {
+ $to = $this->getMaxLevel($context);
+ }
+ if(is_null($from)) {
+ $from = $this->getNextLevel($context);
+
+ if ($from > $to) {
+ $this->addMessage($this->_('Already at max. level.'));
+ return $to;
+ }
+ }
+ $from = max(1, intval($from));
+ $to = intval($to);
+
+ $this->addMessage(sprintf($this->_('Trying upgrade for %s from level %s to level %s'), $context, $from, $to));
+
+ $success = false;
+ $upgrades = $this->_upgradeStack[$context];
+ ksort($upgrades);
+ $this->_upgradeStack[$context] = $upgrades;
+ foreach($this->_upgradeStack[$context] as $level => $upgrade) {
+ 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;
+ $this->addMessage('OK');
+ } else {
+ $this->addMessage('FAILED');
+ break;
+ }
+ }
+ }
+ if ($success) {
+ $this->setLevel($context, $success);
+ }
+ return $success;
+ }
+
+ public function getContext() {
+ return $this->_context;
+ }
+
+ public function getLevel($context)
+ {
+ if(isset($this->_info->$context)) {
+ return $this->_info->$context;
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * Get the highest level for the given context
+ *
+ * @param string|null $context
+ * @return int
+ */
+ public function getMaxLevel($context = null)
+ {
+ if (! $context) {
+ $context = $this->getContext();
+ }
+
+ if (isset($this->_upgradeStack[$context])) {
+ $values = array_keys($this->_upgradeStack[$context]);
+ $values[] = 0;
+ $index = intval(max($values));
+ return $index;
+ } else {
+ return 0;
+
+ }
+ }
+
+ /**
+ * Get the next level for a given level and context
+ *
+ * When context is null, it will get the current context
+ * When level is null, it will get the current level
+ *
+ * @param type $level
+ * @param type $context
+ * @return type
+ */
+ public function getNextLevel($context = null, $level = null) {
+ if (is_null($context)) {
+ $context = $this->getContext();
+ }
+ if (is_null($level)) {
+ $level = $this->getLevel($context);
+ }
+
+ //Get all the levels
+ $currentContext = $this->_upgradeStack[$context];
+ ksort($currentContext);
+ $levels = array_keys($this->_upgradeStack[$context]);
+ //Find the index of the current one
+ $current = array_search($level, $levels);
+
+ //And if it is present, return the next level
+ $current++;
+ if (isset($levels[$current])) return $levels[$current];
+
+ //Else return current level +1 (doesn't exist anyway)
+ return ++$level;
+ }
+
+ public function getMessages()
+ {
+ return $this->_messages;
+ }
+
+ /**
+ * 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) {
+ $row = array();
+ $row['context'] = $context;
+ $row['maxLevel'] = $this->getMaxLevel($context);
+ $row['level'] = $this->getLevel($context);
+ $result[$context] = $row;
+ }
+
+ if (is_null($requestedContext)) {
+ return $result;
+ } else {
+ if (isset($result[$requestedContext])) {
+ return $result[$requestedContext];
+ }
+ }
+ }
+
+ public function register($callback, $info = null, $index = null, $context = null)
+ {
+ if (is_string($callback)) {
+ $callback = array(get_class($this), $callback);
+ }
+ if (is_callable($callback)) {
+ if (! $context) {
+ $context = $this->getContext();
+ }
+
+ if (isset($this->_upgradeStack[$context])) {
+ $key = array_search($callback, $this->_upgradeStack[$context]);
+ if ($key !== false) {
+ $index = $key;
+ }
+ } else {
+ $this->_upgradeStack[$context] = array();
+ }
+
+ if (is_null($index)) {
+ $index = $this->getMaxLevel($context);
+ $index++;
+ }
+
+ $this->_upgradeStack[$context][$index]['upgrade'] = $callback;
+ $this->_upgradeStack[$context][$index]['info'] = $info;
+
+ return true;
+ }
+ return false;
+ }
+
+ public function setContext($context) {
+ $this->_context = $context;
+ }
+
+ protected function setLevel($context, $level = null, $force = false)
+ {
+ if (!is_null($level) &&
+ $this->_info->$context != $level &&
+ ($force || $this->_info->$context < $level)) {
+ $this->_info->$context = $level;
+ $writer = new Zend_Config_Writer_Ini();
+ $writer->write($this->upgradeFile, $this->_info);
+ }
+ }
+}
\ No newline at end of file
Modified: branches/newUser2/classes/Gems/Util/DatabasePatcher.php
===================================================================
--- branches/newUser2/classes/Gems/Util/DatabasePatcher.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Util/DatabasePatcher.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -130,14 +130,22 @@
'gpa_sql' => $statement
);
}
- }
+ }
}
}
}
}
- public function executePatch($patch, $ignoreCompleted = true, $ignoreExecuted = false)
+ /**
+ * Executes db patches for the given $patchLevel
+ *
+ * @param int $patchLevel Only execute patches for this patchlevel
+ * @param boolean $ignoreCompleted Set to yes to skip patches that where already completed
+ * @param boolean $ignoreExecuted Set to yes to skip patches that where already executed (this includes the ones that are executed but not completed)
+ * @return int The number of executed patches
+ */
+ public function executePatch($patchLevel, $ignoreCompleted = true, $ignoreExecuted = false)
{
$sql = 'SELECT gpa_id_patch, gpa_sql, gpa_completed FROM gems__patches WHERE gpa_level = ?';
if ($ignoreCompleted) {
@@ -151,7 +159,7 @@
$current = new Zend_Db_Expr('CURRENT_TIMESTAMP');
$executed = 0;
- $patches = $this->db->fetchAll($sql, $patch);
+ $patches = $this->db->fetchAll($sql, $patchLevel);
foreach ($patches as $patch) {
$data = array();
@@ -176,6 +184,11 @@
$executed++;
}
+ //Update the patchlevel only when we have executed at least one patch
+ if ($executed>0) {
+ $this->db->query('INSERT IGNORE INTO gems__patch_levels (gpl_level, gpl_created) VALUES (?, CURRENT_TIMESTAMP)', $patchLevel);
+ }
+
return $executed;
}
Modified: branches/newUser2/classes/GemsEscort.php
===================================================================
--- branches/newUser2/classes/GemsEscort.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/GemsEscort.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -146,25 +146,37 @@
{
$cache = null;
$exists = false;
- $cacheDir = GEMS_ROOT_DIR . "/var/cache/";
- if (!file_exists($cacheDir)) {
- if (@mkdir($cacheDir, 0777, true)) {
+
+ // Check if APC extension is loaded
+ if( extension_loaded('apc') ) {
+ $cacheBackend = 'Apc';
+ $cacheBackendOptions = array();
+ $exists = true;
+ } else {
+ $cacheBackend = 'File';
+ $cacheDir = GEMS_ROOT_DIR . "/var/cache/";
+ $cacheBackendOptions = array('cache_dir' => $cacheDir);
+ if (!file_exists($cacheDir)) {
+ if (@mkdir($cacheDir, 0777, true)) {
+ $exists = true;
+ }
+ } else {
$exists = true;
}
- } else {
- $exists = true;
}
if ($exists) {
- $cacheFrontendOptions = array('automatic_serialization' => true);
- $cacheBackendOptions = array('cache_dir' => $cacheDir);
+ $cacheFrontendOptions = array('automatic_serialization' => true,
+ 'cache_id_prefix' => GEMS_PROJECT_NAME . '_');
- $cache = Zend_Cache::factory('Core', 'File', $cacheFrontendOptions, $cacheBackendOptions);
-
- Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
- Zend_Translate::setCache($cache);
+ $cache = Zend_Cache::factory('Core', $cacheBackend, $cacheFrontendOptions, $cacheBackendOptions);
+ } else {
+ $cache = Zend_Cache::factory('Core', 'Static', array('caching' => false), array('disable_caching' => true));
}
+ Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
+ Zend_Translate::setCache($cache);
+
return $cache;
}
Modified: branches/newUser2/classes/MUtil/Model/FormBridge.php
===================================================================
--- branches/newUser2/classes/MUtil/Model/FormBridge.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/MUtil/Model/FormBridge.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -112,31 +112,6 @@
return $element;
}
- public static function applyFixedOptions($type, array &$options)
- {
- static $typeOptions;
-
- if (! $typeOptions) {
- $typeOptions = Zend_Registry::get('MUtil_Model_FormBridge');
- }
-
- if (substr($type, 0, 3) == 'add') {
- $type = strtolower(substr($type, 3));
- }
- // MUtil_Echo::rs($type, $options);
-
- if (isset($typeOptions[$type])) {
- foreach ($typeOptions[$type] as $key => $value) {
- if (is_array($value) && isset($options[$key])) {
- $options[$key] = $value + $options[$key];
- } else {
- $options[$key] = $value;
- }
- }
- }
- // MUtil_Echo::rs('After', $options, $typeOptions);
- }
-
protected function _applyValidators($name, Zend_Form_Element $element)
{
$validators = $this->model->get($name, 'validators');
@@ -656,6 +631,8 @@
self::DISPLAY_OPTIONS, self::TEXT_OPTIONS, self::TEXTAREA_OPTIONS);
$stringlength = $this->_getStringLength($options);
+ // Remove as size and maxlength are not used for textarea's
+ unset($options['size'], $options['maxlength']);
$element = new Zend_Form_Element_Textarea($name, $options);
@@ -682,6 +659,31 @@
return $this;
}
+ public static function applyFixedOptions($type, array &$options)
+ {
+ static $typeOptions;
+
+ if (! $typeOptions) {
+ $typeOptions = Zend_Registry::get('MUtil_Model_FormBridge');
+ }
+
+ if (substr($type, 0, 3) == 'add') {
+ $type = strtolower(substr($type, 3));
+ }
+ // MUtil_Echo::rs($type, $options);
+
+ if (isset($typeOptions[$type])) {
+ foreach ($typeOptions[$type] as $key => $value) {
+ if (is_array($value) && isset($options[$key])) {
+ $options[$key] = $value + $options[$key];
+ } else {
+ $options[$key] = $value;
+ }
+ }
+ }
+ // MUtil_Echo::rs('After', $options, $typeOptions);
+ }
+
/**
*
* @return Zend_Form
Modified: branches/newUser2/configs/db/tables/gems__user_logins.10.sql
===================================================================
--- branches/newUser2/configs/db/tables/gems__user_logins.10.sql 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/configs/db/tables/gems__user_logins.10.sql 2011-11-08 10:32:48 UTC (rev 191)
@@ -14,8 +14,8 @@
gul_created timestamp not null,
gul_created_by bigint unsigned not null,
- PRIMARY KEY (gsl_id_user),
- UNIQUE (gsl_login, gsl_id_organization)
+ PRIMARY KEY (gul_id_user),
+ UNIQUE (gul_login, gul_id_organization)
)
ENGINE=InnoDB
AUTO_INCREMENT = 10001
Copied: branches/newUser2/controllers/UpgradeController.php (from rev 190, trunk/library/controllers/UpgradeController.php)
===================================================================
--- branches/newUser2/controllers/UpgradeController.php (rev 0)
+++ branches/newUser2/controllers/UpgradeController.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -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
Modified: branches/newUser2/pre_bootstrap.php
===================================================================
--- branches/newUser2/pre_bootstrap.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/pre_bootstrap.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -1,34 +1,34 @@
<?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.
- */
-
+
/**
+ * 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.
+ */
+
+/**
* This files contains general project code that loads the
* Zend_Application - and does whatever else has to be done.
*
@@ -66,10 +66,11 @@
* then to Gems application directory
*/
set_include_path(
- GEMS_ROOT_DIR . '/library' . PATH_SEPARATOR .
GEMS_LIBRARY_DIR . '/classes' . PATH_SEPARATOR .
APPLICATION_PATH . '/classes' . PATH_SEPARATOR .
- get_include_path());
+ get_include_path()
+ //. PATH_SEPARATOR . GEMS_ROOT_DIR . '/library' //Shouldn't be needed, uncomment when neccessary
+ );
$GEMS_DIRS = array(
GEMS_PROJECT_NAME_UC => APPLICATION_PATH . '/classes',
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|