resolved Bug #11154: Clear cache after database operations, raised version
authorsteffenk <steffenk@735d13b6-9817-0410-8766-e36946ffe9aa>
Tue, 30 Nov 2010 10:47:08 +0000 (10:47 +0000)
committersteffenk <steffenk@735d13b6-9817-0410-8766-e36946ffe9aa>
Tue, 30 Nov 2010 10:47:08 +0000 (10:47 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/be_acl/trunk@40673 735d13b6-9817-0410-8766-e36946ffe9aa

ext_emconf.php
ext_localconf.php
res/class.tx_beacl_userauthgroup.php

index 5d412c5..a573127 100644 (file)
@@ -1,13 +1,13 @@
 <?php
 
 ########################################################################
-# Extension Manager/Repository config file for ext: "be_acl"
+# Extension Manager/Repository config file for ext "be_acl".
 #
-# Auto generated 12-01-2009 16:57
+# Auto generated 30-11-2010 10:58
 #
 # Manual updates:
-# Only the data in the array - anything else is removed by next write.
-# "version" and "dependencies" must not be touched!
+# Only the data in the array - everything else is removed by next
+# writing. "version" and "dependencies" must not be touched!
 ########################################################################
 
 $EM_CONF[$_EXTKEY] = array(
@@ -15,8 +15,8 @@ $EM_CONF[$_EXTKEY] = array(
        'description' => 'Backend Access Control Lists',
        'category' => 'be',
        'shy' => 0,
-       'version' => '1.4.1',
-       'dependencies' => '',
+       'version' => '1.4.2',
+       'dependencies' => 'cms,lang',
        'conflicts' => '',
        'priority' => '',
        'loadOrder' => '',
@@ -44,7 +44,9 @@ $EM_CONF[$_EXTKEY] = array(
                'suggests' => array(
                ),
        ),
-       '_md5_values_when_last_written' => 'a:15:{s:21:"ext_conf_template.txt";s:4:"23d5";s:12:"ext_icon.gif";s:4:"1bea";s:17:"ext_localconf.php";s:4:"5cdf";s:14:"ext_tables.php";s:4:"aceb";s:14:"ext_tables.sql";s:4:"1076";s:21:"icon_tx_beacl_acl.gif";s:4:"1bea";s:16:"locallang_db.php";s:4:"0f61";s:7:"tca.php";s:4:"01cc";s:14:"doc/manual.sxw";s:4:"4db3";s:19:"doc/wizard_form.dat";s:4:"e68f";s:20:"doc/wizard_form.html";s:4:"4e9b";s:10:"res/acl.js";s:4:"80ec";s:36:"res/class.tx_beacl_userauthgroup.php";s:4:"3d8c";s:38:"res/class.ux_sc_mod_web_perm_index.php";s:4:"4bb6";s:22:"res/locallang_perm.php";s:4:"9a96";}',
+       '_md5_values_when_last_written' => 'a:16:{s:16:"ext_autoload.php";s:4:"001a";s:21:"ext_conf_template.txt";s:4:"23d5";s:12:"ext_icon.gif";s:4:"1bea";s:17:"ext_localconf.php";s:4:"5dcf";s:14:"ext_tables.php";s:4:"aceb";s:14:"ext_tables.sql";s:4:"1076";s:21:"icon_tx_beacl_acl.gif";s:4:"1bea";s:16:"locallang_db.php";s:4:"0f61";s:7:"tca.php";s:4:"01cc";s:14:"doc/manual.sxw";s:4:"4db3";s:19:"doc/wizard_form.dat";s:4:"e68f";s:20:"doc/wizard_form.html";s:4:"4e9b";s:10:"res/acl.js";s:4:"80ec";s:36:"res/class.tx_beacl_userauthgroup.php";s:4:"cd63";s:38:"res/class.ux_sc_mod_web_perm_index.php";s:4:"4bb6";s:22:"res/locallang_perm.php";s:4:"9a96";}',
+       'suggests' => array(
+       ),
 );
 
 ?>
\ No newline at end of file
index fb67b16..803eb25 100644 (file)
@@ -16,5 +16,8 @@ $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/web/perm/index.php'] = t3lib_e
 
 // Hook for clear cache
 $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'][$_EXTKEY] = 'EXT:be_acl/res/class.tx_beacl_userauthgroup.php:tx_beacl_userAuthGroup->clearCache';
+//TCEmain Hooks
+$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][$_EXTKEY] = 'EXT:be_acl/res/class.tx_beacl_userauthgroup.php:&tx_beacl_userAuthGroup';
+$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][$_EXTKEY] = 'EXT:be_acl/res/class.tx_beacl_userauthgroup.php:&tx_beacl_userAuthGroup';
 
 ?>
\ No newline at end of file
index b9d662a..7666af7 100644 (file)
@@ -2,27 +2,27 @@
 
 
 /***************************************************************
-*  Copyright notice
-*
-*  (c) 2005 Sebastian Kurfuerst (sebastian@garbage-group.de)
-*  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!
-***************************************************************/
+ *  Copyright notice
+ *
+ *  (c) 2005 Sebastian Kurfuerst (sebastian@garbage-group.de)
+ *  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!
+ ***************************************************************/
 /**
  * Backend ACL - Functions re-calculating permissions
  *
@@ -40,11 +40,11 @@ class tx_beacl_userAuthGroup {
         * @param       object          BE User Object
         * @return      integer         Bitwise representation of the users permissions in relation to input page row, $row
         */
-       public function calcPerms($params, $that)       {
+       public function calcPerms($params, $that) {
                $row = $params['row'];
 
                $beAclConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['be_acl']);
-               if(!$beAclConfig['disableOldPermissionSystem']) {
+               if (!$beAclConfig['disableOldPermissionSystem']) {
                        $out = $params['outputPermissions'];
                } else {
                        $out = 0;
@@ -55,41 +55,41 @@ class tx_beacl_userAuthGroup {
                $i = 0;
                $takeUserIntoAccount = 1;
                $groupIdsAlreadyUsed = Array();
-               foreach($rootLine as $level => $values) {
-                       if($i != 0) {
+               foreach ($rootLine as $level => $values) {
+                       if ($i != 0) {
                                $recursive = ' AND recursive=1';
                        } else {
                                $recursive = '';
                        }
-                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_beacl_acl', 'pid='.intval($values['uid']).$recursive, '', 'recursive ASC');
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_beacl_acl', 'pid=' . intval($values['uid']) . $recursive, '', 'recursive ASC');
 
                        while ($result = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                                if ($result['type'] == 0
                                        && ($that->user['uid'] == $result['object_id'])
                                        && $takeUserIntoAccount) { // user has to be taken into account
-                                       $out|=$result['permissions'];
+                                       $out |= $result['permissions'];
                                        $takeUserIntoAccount = 0;
 
                                } elseif ($result['type'] == 1
-                                       && $that->isMemberOfGroup($result['object_id'])
-                                       && !in_array($result['object_id'], $groupIdsAlreadyUsed)) {
-                                       $out|=$result['permissions'];
+                                                 && $that->isMemberOfGroup($result['object_id'])
+                                                 && !in_array($result['object_id'], $groupIdsAlreadyUsed)) {
+                                       $out |= $result['permissions'];
                                        $groupIdsAlreadyUsed[] = $result['object_id'];
                                }
                        }
                        $i++;
                }
-               
+
                return $out;
        }
 
        /**
         * Returns a WHERE-clause for the pages-table where user permissions according to input argument, $perms, is validated.
         * $perms is the 'mask' used to select. Fx. if $perms is 1 then you'll get all pages that a user can actually see!
-        *              2^0 = show (1)
-        *              2^1 = edit (2)
-        *              2^2 = delete (4)
-        *              2^3 = new (8)
+        *                2^0 = show (1)
+        *               2^1 = edit (2)
+        *               2^2 = delete (4)
+        *               2^3 = new (8)
         * If the user is 'admin' " 1=1" is returned (no effect)
         * If the user is not set at all (->user is not an array), then " 1=0" is returned (will cause no selection results at all)
         * The 95% use of this function is "->getPagePermsClause(1)" which will return WHERE clauses for *selecting* pages in backend listings - in other words will this check read permissions.
@@ -99,49 +99,51 @@ class tx_beacl_userAuthGroup {
         * @return      string          Part of where clause. Prefix " AND " to this.
         */
 
-       function getPagePermsClause($params, $that)     {
+       function getPagePermsClause($params, $that) {
 
                $fileCachePath = PATH_site . 'typo3temp/beacl_cache/';
                $filename = $fileCachePath . 'ppc_' . md5($that->user['uid'] . $params['perms']) . ',cache';
                        // Check if we can return something from cache
-               if (file_exists($filename)) return file_get_contents($filename);     
-               
-               
-                       // get be_acl config in EM
+               if (file_exists($filename)) {
+                       return t3lib_div::getURL($filename);
+               }
+
+
+               // get be_acl config in EM
                $beAclConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['be_acl']);
-               if(!$beAclConfig['disableOldPermissionSystem']) {
+               if (!$beAclConfig['disableOldPermissionSystem']) {
                        $str = $params['currentClause'];
                } else {
                        $str = '1 = 2';
                }
-                       // get some basic variables
+               // get some basic variables
                $perms = $params['perms'];
-               $this->aclPageList = Array();
+               $this->aclPageList = array();
 
-                       // get allowed IDs for user
+               // get allowed IDs for user
                $this->getPagePermsClause_single(0, $that->user['uid'], $perms);
-                       // get allowed IDs for every single group
-               if($that->groupList) {
-                       $groupList = explode(',',$that->groupList);
-                       foreach($groupList as $singleGroup) {
+               // get allowed IDs for every single group
+               if ($that->groupList) {
+                       $groupList = explode(',', $that->groupList);
+                       foreach ($groupList as $singleGroup) {
                                $this->getPagePermsClause_single(1, $singleGroup, $perms);
                        }
                }
-               if(!empty($this->aclPageList)) {
-                               // put all page IDs together to the final SQL string
-                       $str = '( '.$str.' ) OR ( pages.uid IN ('.implode(',',$this->aclPageList).') )';
-
-                               // if the user is in a workspace, that has to be taken into account
-                               // see t3lib_BEfunc::getWorkspaceVersionOfRecord() for the source of this query
-                       if ($that->workspace)   {
-                               $str .= ' OR ( pages.t3ver_wsid='.intval($that->workspace).' AND pages.t3ver_oid IN ('.implode(',',$this->aclPageList).') )';
+               if (!empty($this->aclPageList)) {
+                       // put all page IDs together to the final SQL string
+                       $str = '( ' . $str . ' ) OR ( pages.uid IN (' . implode(',', $this->aclPageList) . ') )';
+
+                       // if the user is in a workspace, that has to be taken into account
+                       // see t3lib_BEfunc::getWorkspaceVersionOfRecord() for the source of this query
+                       if ($that->workspace) {
+                               $str .= ' OR ( pages.t3ver_wsid=' . intval($that->workspace) . ' AND pages.t3ver_oid IN (' . implode(',', $this->aclPageList) . ') )';
                        }
                }
 
-                       // for safety, put whole where query part into brackets so it won't interfere with other parts of the page
-               $str = ' ( '.$str.' ) ';
-               
-                       // Store data in cache
+               // for safety, put whole where query part into brackets so it won't interfere with other parts of the page
+               $str = ' ( ' . $str . ' ) ';
+
+               // Store data in cache
                file_put_contents($filename, $str);
                return $str;
        }
@@ -157,38 +159,38 @@ class tx_beacl_userAuthGroup {
         * @return nothing, fills $this->aclPageList
         **/
        protected function getPagePermsClause_single($type, $object_id, $perms) {
-                       // reset aclDisallowed
+               // reset aclDisallowed
                $this->aclDisallowed = Array();
-                       // 1. fetch all ACLs relevant for the current user/group
+               // 1. fetch all ACLs relevant for the current user/group
                $aclAllowed = Array();
-               $where = ' ( (type = '.intval($type).' AND object_id = '.intval($object_id).')';
+               $where = ' ( (type = ' . intval($type) . ' AND object_id = ' . intval($object_id) . ')';
 
-               $whereAllow = ') AND (permissions & '.$perms.' = '.$perms.')';
-               $whereDeny = ') AND (permissions & '.$perms.' = 0)';
+               $whereAllow = ') AND (permissions & ' . $perms . ' = ' . $perms . ')';
+               $whereDeny = ') AND (permissions & ' . $perms . ' = 0)';
 
                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                        'pid, recursive',
                        'tx_beacl_acl',
-                       $where.$whereAllow
+                       $where . $whereAllow
                );
-               while($result = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+               while ($result = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                        $aclAllowed[] = $result;
                }
 
-               if($aclAllowed) {
-                               // get all "deny" acls if there are allow ACLs
+               if ($aclAllowed) {
+                       // get all "deny" acls if there are allow ACLs
                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                                'pid, recursive',
                                'tx_beacl_acl',
-                               $where.$whereDeny
+                               $where . $whereDeny
                        );
-                       while($result = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                       while ($result = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                                $this->aclDisallowed[$result['pid']] = $result['recursive']; // only one ACL per group/user per page is allowed, that's why this line imposes no problem. It rather increases speed.
                        }
 
                        // go through all allowed ACLs, if it is not recursive, add the page to the aclPageList, if recursive, call recursion function
-                       foreach($aclAllowed as $singleAllow) {
-                               if($singleAllow['recursive'] == 0) {
+                       foreach ($aclAllowed as $singleAllow) {
+                               if ($singleAllow['recursive'] == 0) {
                                        $this->aclPageList[$singleAllow['pid']] = $singleAllow['pid'];
                                } else {
                                        $this->aclTraversePageTree($singleAllow['pid']);
@@ -205,40 +207,83 @@ class tx_beacl_userAuthGroup {
         * @return nothing, fills $this->aclPageList
         **/
        protected function aclTraversePageTree($pid) {
-                       // if there is a disallow ACL for the current page, don't add the page to the aclPageList
-               if(array_key_exists($pid, $this->aclDisallowed)) {
-                       if($this->aclDisallowed[$pid] == 1) {
+
+               if (array_key_exists($pid, $this->aclDisallowed)) {
+                               // if there is a disallow ACL for the current page, don't add the page to the aclPageList
+                       if ($this->aclDisallowed[$pid] == 1) {
                                return 0; // if recursive, stop processing
                        }
-               } else { // in case there is no disallow ACL, add page ID to aclPageList
+               } else {
+                               // in case there is no disallow ACL, add page ID to aclPageList
                        $this->aclPageList[$pid] = $pid;
                }
 
                        // find subpages and call function itself again
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid','pages', 'pid='.intval($pid).' AND deleted=0');
-               while($result = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'pid=' . intval($pid) . ' AND deleted=0');
+               while ($result = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                        $this->aclTraversePageTree($result['uid']);
                }
        }
-       
+
        /**
-       * hook for clear cache, works for "all" and "configuration" clear command
-       * 
-       * @param array $params params for the hook
-       * @param object $pObj parent class (tcemain)
-       */
+        * hook for clear cache, works for "all" and "configuration" clear command
+        *
+        * @param array $params params for the hook
+        * @param object $pObj parent class (tcemain)
+        */
        public function clearCache($params, $pObj) {
-               if($params['cacheCmd'] == 'temp_CACHED' || $params['cacheCmd'] == 'all') {
-                       $tempPath = PATH_site . 'typo3temp/beacl_cache/'; 
-                       $handle=opendir($tempPath);
-                       while ($data=readdir($handle)) {
+               if ($params['cacheCmd'] == 'temp_CACHED' || $params['cacheCmd'] == 'all') {
+                       $this->clearBeaAclCache();
+               }
+       }
+
+       /**
+        * Hook tcemain for after database change action
+        *
+        * @param  string $status
+        * @param  string $table
+        * @param  string $id
+        * @param  array $fieldArray
+        * @param  t3lib_TCEmain $pObj
+        * @return void
+        */
+       public function processDatamap_afterDatabaseOperations($status, $table, $id, &$fieldArray, &$pObj) {
+               if ($table == 'pages') {
+                       $this->clearBeaAclCache();
+               }
+       }
+
+       /**
+        * Hook tcemain for after delete action
+        *
+        * @param  string $command
+        * @param  string $table
+        * @param  string $id
+        * @param  string $value
+        * @param  t3lib_TCEmain $pObj
+        * @return void
+        */
+       public function processCmdmap_postProcess ($command, $table ,$id, $value, &$pObj) {
+                       if ($command == 'delete' && $table == 'pages') {
+                               $this->clearBeaAclCache();
+                       }
+       }
+
+       /**
+        * Internal function for clearing cache
+        *
+        * @return void
+        */
+       protected function clearBeaAclCache() {
+               $tempPath = PATH_site . 'typo3temp/beacl_cache/';
+                       $handle = opendir($tempPath);
+                       while ($data = readdir($handle)) {
                                if (!is_dir($data) && $data != "." && $data != "..") {
                                        unlink($tempPath . $data);
                                }
                        }
                        closedir($handle);
-               }
        }
 }
 
-?>
+?>
\ No newline at end of file