Commit 740263ac authored by Jerome Mariette's avatar Jerome Mariette
Browse files

add upgrade facilities to facilitate version upgrades

parent d1a02287
<?php
/***************************************************************
* Copyright notice
*
* (c) 2009 PF bioinformatique de Toulouse <>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script 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 General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
require_once(PATH_tslib.'class.tslib_pibase.php');
/**
* Class_nG6_db' for the 'nG6' extension.
* Allows to migrate usergroups system to (users) rights system.
*
* @author PF bioinformatique de Toulouse <>
*/
class tx_nG6_upgrade {
/**
* Main function for upgrade.
*
* @param string $version the version
*/
function upgrade($version){
// version 1.2 : users rights' system
if($version == '1.2'){
tx_nG6_upgrade::upgrade_1_2();
return "Upgrade successfuly ended to version 1.2!";
} else {
return "Upgrading to version " . $version . " not suported!";
}
}
/*
* version 1.2
*------------------------------------------------------------*/
/**
* Main function to upgrade to version 1.2.
*/
function upgrade_1_2(){
$queryParts = array(
'SELECT' => 'uid, fe_group',
'FROM' => 'tx_nG6_project',
'WHERE' => '',
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$project_id = $row['uid'];
$current_group = $row['fe_group'];
// users in the current group
$group_users = tx_nG6_upgrade::get_all_users_in_group($current_group);
// set current group users' right to "visitor"
foreach($group_users as $id => $user_id){
tx_nG6_upgrade::assign_right($user_id, $project_id, 0);
}
//assign rights to the super groups users for the specified project id
tx_nG6_upgrade::assign_super_groups_rights($current_group, $project_id);
}
}
/**
* Assign the 'administrator' right to all users found in the supergroups of 'basegroup'.
*
* @param int $base_group the base group id
* @param int $project_id the project id
*/
function assign_super_groups_rights($base_group, $project_id){
$super_groups_ids = tx_nG6_upgrade::get_all_super_groups_of($base_group);
foreach($super_groups_ids as $id => $group_id){
$group_users = tx_nG6_upgrade::get_all_users_in_group($group_id);
// super users = admin
foreach($group_users as $id => $user_id){
tx_nG6_upgrade::assign_right($user_id, $project_id, 2);
}
}
}
/**
* Assign a user right to a specific project.
*
* @param int $user_id the user id
* @param int $project_id the project id
* @param int $right the right id (0=visitor, 1=manager, 2=admininistrator)
*/
function assign_right($user_id, $project_id, $right){
$assign_right = Array(
'fe_user_id' => $user_id,
'project_id' => $project_id,
'right_id' => $right
);
$GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_rights', $assign_right);
}
/**
* Return all users id from a usergroup.
*
* @param int $group_id the usergroup
*/
function get_all_users_in_group($group_id){
$users = array();
$queryParts = array(
'SELECT' => 'uid',
'FROM' => 'fe_users',
'WHERE' => 'usergroup='.$group_id,
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$users[] = $row['uid'];
}
return $users;
}
/**
* Return the supergroups list of the specified group.
*
* @param string $group the group
* @return array
*/
function get_super_groups_of ($group) {
// First get the super group of the given group
$queryParts = array(
'SELECT' => 'uid, subgroup',
'FROM' => 'fe_groups',
'WHERE' => '',
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$reslist = array();
$i = 0;
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
if (in_array($group, t3lib_div::intExplode(',',$row['subgroup']))) {
$reslist[$i] = $row['uid'];
$i++;
}
}
return $reslist;
}
/**
* Return the recursive supergroups list of the specified group
*
* @param string $group the group id
* @return array
*/
function get_all_super_groups_of ($group) {
// return the recursive list of all $group super groups
$first_list = tx_nG6_upgrade::get_super_groups_of($group);
$super_list = $first_list;
foreach ($first_list as $first_list_group_id) {
$next_list = tx_nG6_upgrade::get_all_super_groups_of($first_list_group_id, $level);
$super_list = array_merge($super_list,$next_list);
}
return $super_list;
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/class.tx_nG6_upgrade.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/class.tx_nG6_upgrade.php']);
}
?>
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
require_once(PATH_tslib.'class.tslib_pibase.php'); require_once(PATH_tslib.'class.tslib_pibase.php');
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_db.php'); require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_db.php');
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_utils.php'); require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_utils.php');
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_upgrade.php');
require_once(t3lib_extMgm::extPath('nG6').'/res/smarty/libs/Smarty.class.php'); require_once(t3lib_extMgm::extPath('nG6').'/res/smarty/libs/Smarty.class.php');
class tx_nG6_pi1 extends tslib_pibase { class tx_nG6_pi1 extends tslib_pibase {
...@@ -93,38 +94,42 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -93,38 +94,42 @@ class tx_nG6_pi1 extends tslib_pibase {
<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.theme.css"/> <link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.theme.css"/>
<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.dialog.css"/> <link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.dialog.css"/>
<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.resizable.css"/>'; <link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.resizable.css"/>';
tx_nG6_db::check_db_rights_level();
// If the user is authorized to access the specified project/run, display the page // if asked to upgrade to version 1.3
if (tx_nG6_db::user_is_authorized($GLOBALS['TSFE']->fe_user->user['uid'], $this->piVars['project_id'], $this->piVars['run_id'])) { if($this->piVars['upgrade']){
switch((string)$this->conf['view']) { $content = tx_nG6_upgrade::upgrade($this->piVars['upgrade']);
// If the plugin is configured to display results by project } else {
case 'project':
if ($this->piVars['analyze_id']) { // If the user is authorized to access the specified project/run, display the page
$content .= $this->pi_analyze_view(); if (tx_nG6_db::user_is_authorized($GLOBALS['TSFE']->fe_user->user['uid'], $this->piVars['project_id'], $this->piVars['run_id'])) {
} elseif ($this->piVars['project_id'] && $this->piVars['run_id']) { switch((string)$this->conf['view']) {
$content .= $this->pi_run_view(); // If the plugin is configured to display results by project
} else { case 'project':
if ($this->piVars['analyze_id']) {
$content .= $this->pi_analyze_view();
} elseif ($this->piVars['project_id'] && $this->piVars['run_id']) {
$content .= $this->pi_run_view();
} else {
$content .= $this->pi_project_view();
}
break;
// If the plugin is configured to display results by run
case 'run':
if ($this->piVars['analyze_id']) {
$content .= $this->pi_analyze_view();
} else {
$content .= $this->pi_run_view();
}
break;
// If the plugin is not configured, display by project is default
default:
$content .= $this->pi_project_view(); $content .= $this->pi_project_view();
} break;
break; }
// If the plugin is configured to display results by run // If the user is not authorized
case 'run': } else {
if ($this->piVars['analyze_id']) { $content .= $this->pi_getLL('not_authorized','[not_authorized]');
$content .= $this->pi_analyze_view();
} else {
$content .= $this->pi_run_view();
}
break;
// If the plugin is not configured, display by project is default
default:
$content .= $this->pi_project_view();
break;
} }
// If the user is not authorized
} else {
$content .= $this->pi_getLL('not_authorized','[not_authorized]');
} }
return $this->pi_wrapInBaseClass($content); return $this->pi_wrapInBaseClass($content);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment