[21020] New feature: Delete users ACL-cache as bulk operation / improvement : fetchmode 4686:4746

Sigurd Nes <[email protected]> Sun, 07 Feb 2010 10:42:50 +0000
Newsgroups gmane.comp.web.phpgroupware.cvs
Message-ID <[email protected]>
Revision: 21020
          http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=21020
Author:   sigurdne
Date:     2010-02-07 10:42:49 +0000 (Sun, 07 Feb 2010)
Log Message:
-----------
New feature: Delete users ACL-cache as bulk operation / improvement: fetchmode 4686:4746

Modified Paths:
--------------
    people/sigurdne/modules/admin/trunk/inc/class.menu.inc.php
    people/sigurdne/modules/admin/trunk/inc/class.soaccess_history.inc.php
    people/sigurdne/modules/admin/trunk/inc/class.soapplications.inc.php
    people/sigurdne/modules/admin/trunk/inc/class.solog.inc.php
    people/sigurdne/modules/admin/trunk/inc/class.uiaccounts.inc.php

Modified: people/sigurdne/modules/admin/trunk/inc/class.menu.inc.php
===================================================================
--- people/sigurdne/modules/admin/trunk/inc/class.menu.inc.php	2010-02-07 10:40:47 UTC (rev 21019)
+++ people/sigurdne/modules/admin/trunk/inc/class.menu.inc.php	2010-02-07 10:42:49 UTC (rev 21020)
@@ -86,6 +86,15 @@
 				);
 			}
 
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
+			{
+				$menus['admin']['clear_user_cache'] = array
+				(
+					'text'	=> lang('Clear user cache'),
+					'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'admin.uiaccounts.clear_user_cache') )
+				);
+			}
+
 //			if (! $GLOBALS['phpgw']->acl->check('sync_account', PHPGW_ACL_READ, 'admin'))
 			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
 			{

Modified: people/sigurdne/modules/admin/trunk/inc/class.soaccess_history.inc.php
===================================================================
--- people/sigurdne/modules/admin/trunk/inc/class.soaccess_history.inc.php	2010-02-07 10:40:47 UTC (rev 21019)
+++ people/sigurdne/modules/admin/trunk/inc/class.soaccess_history.inc.php	2010-02-07 10:42:49 UTC (rev 21020)
@@ -52,10 +52,10 @@
 		{
 			$where = $this->test_account_id($account_id);
 
-			$this->db->query("SELECT COUNT(*) from phpgw_access_log $where", __LINE__, __FILE__);
+			$this->db->query("SELECT COUNT(*) as cnt from phpgw_access_log $where", __LINE__, __FILE__);
 			$this->db->next_record();
 
-			return $this->db->f(0);
+			return $this->db->f('cnt');
 		}
 
 		function return_logged_out($account_id)
@@ -68,9 +68,9 @@
 			{
 				$where = 'WHERE lo !=0';
 			}
-			$this->db->query("SELECT COUNT(*) FROM phpgw_access_log $where", __LINE__, __FILE__);
+			$this->db->query("SELECT COUNT(*) as cnt FROM phpgw_access_log $where", __LINE__, __FILE__);
 			$this->db->next_record();
 
-			return $this->db->f(0);
+			return $this->db->f('cnt');
 		}
 	}

Modified: people/sigurdne/modules/admin/trunk/inc/class.soapplications.inc.php
===================================================================
--- people/sigurdne/modules/admin/trunk/inc/class.soapplications.inc.php	2010-02-07 10:40:47 UTC (rev 21019)
+++ people/sigurdne/modules/admin/trunk/inc/class.soapplications.inc.php	2010-02-07 10:42:49 UTC (rev 21020)
@@ -59,10 +59,10 @@
 			/* Yes, the sequence should work, but after a mass import in setup (new install)
 			  it does not work on pg
 			*/
-			$sql = 'SELECT MAX(app_id) from phpgw_applications';
+			$sql = 'SELECT MAX(app_id) as max_app_id from phpgw_applications';
 			$this->db->query($sql,__LINE__,__FILE__);
 			$this->db->next_record();
-			$app_id = $this->db->f(0) + 1;
+			$app_id = $this->db->f('max_app_id') + 1;
 			$sql = 'INSERT INTO phpgw_applications (app_id,app_name,app_enabled,app_order) VALUES('
 				. $app_id . ",'" . addslashes($data['n_app_name']) . "','"
 				. $data['n_app_status'] . "','" . $data['app_order'] . "')";
@@ -83,10 +83,10 @@
 
 		function exists($app_name)
 		{
-			$this->db->query("SELECT COUNT(app_name) FROM phpgw_applications WHERE app_name='" . addslashes($app_name) . "'",__LINE__,__FILE__);
+			$this->db->query("SELECT COUNT(app_name) as cnt FROM phpgw_applications WHERE app_name='" . addslashes($app_name) . "'",__LINE__,__FILE__);
 			$this->db->next_record();
 
-			if ($this->db->f(0) != 0)
+			if ($this->db->f('cnt') != 0)
 			{
 				return True;
 			}
@@ -95,9 +95,9 @@
 
 		function app_order()
 		{
-			$this->db->query('SELECT (MAX(app_order)+1) FROM phpgw_applications',__LINE__,__FILE__);
+			$this->db->query('SELECT (MAX(app_order)+1) as next_order FROM phpgw_applications',__LINE__,__FILE__);
 			$this->db->next_record();
-			return $this->db->f(0);
+			return $this->db->f('next_order');
 		}
 
 		function delete($app_name)

Modified: people/sigurdne/modules/admin/trunk/inc/class.solog.inc.php
===================================================================
--- people/sigurdne/modules/admin/trunk/inc/class.solog.inc.php	2010-02-07 10:40:47 UTC (rev 21019)
+++ people/sigurdne/modules/admin/trunk/inc/class.solog.inc.php	2010-02-07 10:42:49 UTC (rev 21020)
@@ -53,10 +53,10 @@
 		{
 			$where = $this->test_account_id($account_id);
 
-			$this->db->query("SELECT COUNT(*) FROM phpgw_log $where", __LINE__, __FILE__);
+			$this->db->query("SELECT COUNT(*) as cnt FROM phpgw_log $where", __LINE__, __FILE__);
 			$this->db->next_record();
 
-			return $this->db->f(0);
+			return $this->db->f('cnt');
 		}
 		
 		function purge_log($account_id)

Modified: people/sigurdne/modules/admin/trunk/inc/class.uiaccounts.inc.php
===================================================================
--- people/sigurdne/modules/admin/trunk/inc/class.uiaccounts.inc.php	2010-02-07 10:40:47 UTC (rev 21019)
+++ people/sigurdne/modules/admin/trunk/inc/class.uiaccounts.inc.php	2010-02-07 10:42:49 UTC (rev 21020)
@@ -53,7 +53,8 @@
 			'edit_user'		=> true,
 			'edit_group'	=> true,
 			'view_user'		=> true,
-			'sync_accounts_contacts'	=> true
+			'sync_accounts_contacts'	=> true,
+			'clear_user_cache'			=> true
 		);
 
 		/**
@@ -1297,4 +1298,22 @@
 			$GLOBALS['phpgw']->redirect_link('/admin/index.php');
 		}
 
+		/**
+		* Clear ACL-cache for all users
+		*
+		* @return void
+		*/
+
+		function clear_user_cache()
+		{
+			if(	$GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin') )
+			{
+				$account_list = $GLOBALS['phpgw']->accounts->get_list('both', -1);
+				foreach ( $account_list as  $id => $account)
+				{
+					$GLOBALS['phpgw']->acl->clear_user_cache($id);
+				}
+			}
+			$GLOBALS['phpgw']->redirect_link('/admin/index.php');
+		}
 	}