Project

General

Profile

Bug #15250 ยป 1960-usergroup_cached.patch

Administrator Admin, 2010-03-05 22:41

View differences:

typo3/sysext/cms/ext_localconf.php (working copy)
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][] = 'EXT:cms/tslib/hooks/class.tx_cms_treelistcacheupdate.php:&tx_cms_treelistCacheUpdate';
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['moveRecordClass'][] = 'EXT:cms/tslib/hooks/class.tx_cms_treelistcacheupdate.php:&tx_cms_treelistCacheUpdate';
// registering hook to update usergroup list for be_users
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'EXT:cms/tslib/hooks/class.tx_cms_updateusergroups.php:&tx_cms_updateUsergroups';
?>
typo3/sysext/cms/tslib/hooks/class.tx_cms_updateusergroups.php (revision 0)
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Georg Ringer (typo3@ringerge.org)
* 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
/**
* Class that hooks into TCEmain and listens for updates to users and usergroups
* to update the cached usergroup l8ist
*
* @author Georg Ringer <typo@ringerge.org3>
* @package TYPO3
* @subpackage tslib
*/
class tx_cms_updateUsergroups {
/**
* waits for TCEmain commands and looks for changed pages, if found further
* changes take place to determine whether the cache needs to be updated
*
* @param string TCEmain operation status, either 'new' or 'update'
* @param string the DB table the operation was carried out on
* @param mixed the record's uid for update records, a string to look the record's uid up after it has been created
* @param array array of changed fiels and their new values
* @param t3lib_TCEmain TCEmain parent object
*/
public function processDatamap_afterDatabaseOperations($status, $table, $recordId, array $updatedFields, t3lib_TCEmain $tceMain) {
if ($table == 'be_users') {
$this->processUpdateUsers($recordId);
} elseif ($table == 'be_groups') {
$this->processUpdateUsergroups();
}
}
/**
* waits for TCEmain commands and looks for deleted usergroups, if found
* the usergroup list is updated
*
* @param string the TCE command
* @param string the record's table
* @param integer the record's uid
* @param array the commands value, typically an array with more detailed command information
* @param t3lib_TCEmain the TCEmain parent object
*/
public function processCmdmap_postProcess($command, $table, $recordId, $commandValue, t3lib_TCEmain $tceMain) {
if ($table == 'be_groups' && $command == 'delete') {
$this->processUpdateUsergroups();
}
}
/**
* Update the cached usergroup list of all users
*
* @return void
*/
protected function processUpdateUsergroups() {
$userAuthGroupObj = t3lib_div::makeInstance('t3lib_userAuthGroup');
$userAuthGroupObj->user_table = 'be_users';
$users = t3lib_BEfunc::getUserNames();
foreach($users as $user) {
$userAuthGroupObj->setBeUserByUid($user['uid']);
$userAuthGroupObj->fetchGroupData();
}
}
/**
* Update the cached usergroup list of a given user
*
* @param int Id of the user
* @return void
*/
protected function processUpdateUsers($userId) {
$userAuthGroupObj = t3lib_div::makeInstance('t3lib_userAuthGroup');
$userAuthGroupObj->user_table = 'be_users';
$userAuthGroupObj->setBeUserByUid(intval($userId));
$userAuthGroupObj->fetchGroupData();
}
}
?>
    (1-1/1)