Bug #15250 ยป 1960-usergroup_cached.patch

Administrator Admin, 2010-03-05 22:41

View differences:

typo3/sysext/cms/ext_localconf.php (working copy)
193 193
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][]  = 'EXT:cms/tslib/hooks/class.tx_cms_treelistcacheupdate.php:&tx_cms_treelistCacheUpdate';
194 194
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['moveRecordClass'][]     = 'EXT:cms/tslib/hooks/class.tx_cms_treelistcacheupdate.php:&tx_cms_treelistCacheUpdate';
195 195

  
196
	// registering hook to update usergroup list for be_users
197
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'EXT:cms/tslib/hooks/class.tx_cms_updateusergroups.php:&tx_cms_updateUsergroups';
196 198

  
197 199
?>
typo3/sysext/cms/tslib/hooks/class.tx_cms_updateusergroups.php (revision 0)
1
<?php
2
/***************************************************************
3
*  Copyright notice
4
*
5
*  (c) 2010 Georg Ringer (typo3@ringerge.org)
6
*  All rights reserved
7
*
8
*  This script is part of the TYPO3 project. The TYPO3 project is
9
*  free software; you can redistribute it and/or modify
10
*  it under the terms of the GNU General Public License as published by
11
*  the Free Software Foundation; either version 2 of the License, or
12
*  (at your option) any later version.
13
*
14
*  The GNU General Public License can be found at
15
*  http://www.gnu.org/copyleft/gpl.html.
16
*  A copy is found in the textfile GPL.txt and important notices to the license
17
*  from the author is found in LICENSE.txt distributed with these scripts.
18
*
19
*
20
*  This script is distributed in the hope that it will be useful,
21
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
*  GNU General Public License for more details.
24
*
25
*  This copyright notice MUST APPEAR in all copies of the script!
26
***************************************************************/
27

  
28

  
29
/**
30
 * Class that hooks into TCEmain and listens for updates to users and usergroups
31
 * to update the cached usergroup l8ist
32
 *
33
 * @author	Georg Ringer <typo@ringerge.org3>
34
 * @package TYPO3
35
 * @subpackage tslib
36
 */
37
class tx_cms_updateUsergroups {
38

  
39
	/**
40
	 * waits for TCEmain commands and looks for changed pages, if found further
41
	 * changes take place to determine whether the cache needs to be updated
42
	 *
43
	 * @param	string	TCEmain operation status, either 'new' or 'update'
44
	 * @param	string	the DB table the operation was carried out on
45
	 * @param	mixed	the record's uid for update records, a string to look the record's uid up after it has been created
46
	 * @param	array	array of changed fiels and their new values
47
	 * @param	t3lib_TCEmain	TCEmain parent object
48
	 */
49
	public function processDatamap_afterDatabaseOperations($status, $table, $recordId, array $updatedFields, t3lib_TCEmain $tceMain) {
50
		if ($table == 'be_users') {
51
			$this->processUpdateUsers($recordId);
52
		} elseif ($table == 'be_groups') {
53
			$this->processUpdateUsergroups();
54
		}
55
	}
56

  
57
	/**
58
	 * waits for TCEmain commands and looks for deleted usergroups, if found
59
	 * the usergroup list is updated
60
	 *
61
	 * @param	string	the TCE command
62
	 * @param	string	the record's table
63
	 * @param	integer	the record's uid
64
	 * @param	array	the commands value, typically an array with more detailed command information
65
	 * @param	t3lib_TCEmain	the TCEmain parent object
66
	 */
67
	public function processCmdmap_postProcess($command, $table, $recordId, $commandValue, t3lib_TCEmain $tceMain) {
68

  
69
		if ($table == 'be_groups' && $command == 'delete') {
70
			$this->processUpdateUsergroups();
71
		}
72
	}
73

  
74
	/**
75
	 * Update the cached usergroup list of all users
76
	 *
77
	 * @return	void
78
	 */
79
	protected function processUpdateUsergroups() {
80
		$userAuthGroupObj = t3lib_div::makeInstance('t3lib_userAuthGroup');
81
		$userAuthGroupObj->user_table = 'be_users';
82

  
83
		$users = t3lib_BEfunc::getUserNames();
84
		foreach($users as $user) {
85
			$userAuthGroupObj->setBeUserByUid($user['uid']);
86
			$userAuthGroupObj->fetchGroupData();
87
		}
88
	}
89

  
90
	/**
91
	 * Update the cached usergroup list of a given user
92
	 *
93
	 * @param	int		Id of the user
94
	 * @return	void
95
	 */
96
	protected function processUpdateUsers($userId) {
97
		$userAuthGroupObj = t3lib_div::makeInstance('t3lib_userAuthGroup');
98
		$userAuthGroupObj->user_table = 'be_users';
99
		$userAuthGroupObj->setBeUserByUid(intval($userId));
100
		$userAuthGroupObj->fetchGroupData();
101
	}
102
}
103

  
104
?>
    (1-1/1)