* Admin: new function "Clear cache and register hooks", also called automatic when restoring a backup

This commit is contained in:
Ralf Becker 2012-11-05 14:10:23 +00:00
parent 411bc98d9d
commit 19e8654778
11 changed files with 162 additions and 13 deletions

View File

@ -98,7 +98,7 @@ class admin_prefs_sidebox_hooks
if (! $GLOBALS['egw']->acl->check('applications_access',16,'admin'))
{
$file['Find and Register all Application Hooks'] = egw::link('/index.php','menuaction=admin.admin_prefs_sidebox_hooks.register_all_hooks');
$file['Clear cache and register hooks'] = egw::link('/index.php','menuaction=admin.admin_prefs_sidebox_hooks.register_all_hooks');
}
if (! $GLOBALS['egw']->acl->check('asyncservice_access',1,'admin'))
@ -141,6 +141,8 @@ class admin_prefs_sidebox_hooks
{
$GLOBALS['egw']->redirect_link('/index.php');
}
egw_cache::flush(egw_cache::INSTANCE);
$GLOBALS['egw']->hooks->register_all_hooks();
if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited

View File

@ -132,6 +132,7 @@ check categories for not (longer) existing accounts admin de Prüfe Kategorien a
check ip address of all sessions admin de IP-Adresse für alle Sessions überprüfen
check items to <b>%1</b> to %2 for %3 admin de Durch Abhaken %3 in %2 <b>%1</b>
children admin de Kinder
clear cache and register hooks admin de Cache löschen und Hooks registrieren
click to select a color admin de Anklicken um eine Farbe auszuwählen
color admin de Farbe
command scheduled to run at %1 admin de Ausführung des Befehls eingeplant am/um %1
@ -289,7 +290,6 @@ false admin de Falsch
field '%1' already exists !!! admin de Feld '%1' existiert bereits !!!
file space admin de Speicherplatz
file space must be an integer admin de Speicherplatz muss eine Zahl sein
find and register all application hooks admin de Suchen und registrieren der "Hooks" aller Anwendungen
for the times above admin de für die oben angegebenen Zeiten
for the times below (empty values count as '*', all empty = every minute) admin de für die darunter angegebenen Zeiten (leere Felder zählen als "*", alles leer = jede Minute)
force password strength (1-5, default empty: no check against rules for a strong password)? admin de Erzwinge eine gewisse Qualität der Passwörter im Passwort-Ändern Dialog (1-5, 1:gering, 5=stark; Default=leer kein Check gegen Regeln zur Passwortqualität)

View File

@ -132,6 +132,7 @@ check categories for not (longer) existing accounts admin en Check categories fo
check ip address of all sessions admin en Check IP address of all sessions
check items to <b>%1</b> to %2 for %3 admin en Check items to <b>%1</b> to %2 for %3
children admin en Children
clear cache and register hooks admin en Clear cache and register hooks
click to select a color admin en Click to select a color
color admin en Color
command scheduled to run at %1 admin en Command scheduled to run at %1
@ -289,7 +290,6 @@ false admin en False
field '%1' already exists !!! admin en Field '%1' already exists!
file space admin en File space
file space must be an integer admin en File space must be an integer
find and register all application hooks admin en Find and register all application hooks
for the times above admin en For the times above
for the times below (empty values count as '*', all empty = every minute) admin en For the times below: empty values count as '*', all empty = every minute.
force password strength (1-5, default empty: no check against rules for a strong password)? admin en Set required password strength. 1 = weak, up to 5 = very strong. Default = empty, no password strength checked

View File

@ -620,12 +620,12 @@ class db_backup
{
return lang('Restore failed');
}
// flush instance cache
egw_cache::flush(egw_cache::INSTANCE);
// search-and-register-hooks
$GLOBALS['egw']->hooks->register_all_hooks();
// invalidate categories cache, it's instance wide
categories::invalidate_cache();
return '';
}

View File

@ -512,6 +512,62 @@ class egw_cache
return $GLOBALS['egw_info']['server'][$name];
}
/**
* Flush (delete) whole (instance) cache or application/class specific part of it
*
* @param $string $level=self::INSTANCE
* @param string $app=null
*/
static public function flush($level=self::INSTANCE, $app=null)
{
$ret = true;
if (!($provider = self::get_provider($level)))
{
$ret = false;
}
else
{
$keys = array($level);
if ($app) $keys[] = $app;
if (!$provider->flush($keys))
{
if ($level == self::INSTANCE)
{
self::generate_instance_key();
}
else
{
$ret = false;
}
}
}
//error_log(__METHOD__."('$level', '$app') returning ".array2string($ret));
return $ret;
}
/**
* Key used for instance specific data
*
* @var string
*/
private static $instance_key;
/**
* Generate a new instance key and by doing so effectivly flushes whole instance cache
*
* @return string new key also stored in self::$instance_key
*/
static public function generate_instance_key()
{
$install_id = self::get_system_config('install_id');
self::$instance_key = self::INSTANCE.'-'.$install_id.'-'.microtime(true);
self::setTree(__CLASS__, $install_id, self::$instance_key);
//error_log(__METHOD__."() install_id='$install_id' returning '".self::$instance_key."'");
return self::$instance_key;
}
/**
* Get keys array from $level, $app and $location
*
@ -537,7 +593,13 @@ class egw_cache
}
break;
case self::INSTANCE:
$bases[$level] = $level.'-'.self::get_system_config('install_id');
if (!isset(self::$instance_key))
{
self::$instance_key = self::getTree(__CLASS__, self::get_system_config('install_id'));
//error_log(__METHOD__."('$level',...) instance_key read from tree-cache=".array2string(self::$instance_key));
if (!isset(self::$instance_key)) self::generate_instance_key();
}
$bases[$level] = self::$instance_key;
break;
}
}
@ -596,6 +658,16 @@ interface egw_cache_provider
* @return boolean true on success, false on error (eg. $key not set)
*/
function delete(array $keys);
/**
* Delete all data under given keys
*
* Providers can return false, if they do not support flushing part of the cache (eg. memcache)
*
* @param array $keys eg. array($level,$app,$location)
* @return boolean true on success, false on error (eg. $key not set)
*/
function flush(array $keys);
}
/**
@ -722,6 +794,19 @@ abstract class egw_cache_provider_check implements egw_cache_provider
return $failed;
}
/**
* Delete all data under given keys
*
* Providers can return false, if they do not support flushing part of the cache (eg. memcache)
*
* @param array $keys eg. array($level,$app,$location)
* @return boolean true on success, false on error (eg. $key not set)
*/
function flush(array $keys)
{
return false;
}
}
// some testcode, if this file is called via it's URL

View File

@ -116,13 +116,30 @@ class egw_cache_apc extends egw_cache_provider_check implements egw_cache_provid
return apc_delete(self::key($keys));
}
/**
* Delete all data under given keys
*
* @param array $keys eg. array($level,$app,$location)
* @return boolean true on success, false on error (eg. $key not set)
*/
function flush(array $keys)
{
//error_log(__METHOD__."(".array2string($keys).")");
foreach(new APCIterator('user', $preg='/^'.preg_quote(self::key($keys).'/')) as $item)
{
//error_log(__METHOD__."(".array2string($keys).") preg='$preg': calling apc_delete('$item[key]')");
apc_delete($item['key']);
}
return true;
}
/**
* Create a single key from $keys
*
* @param array $keys
* @return string
*/
private function key(array $keys)
private static function key(array $keys)
{
return implode('::',$keys);
}

View File

@ -128,6 +128,49 @@ class egw_cache_files extends egw_cache_provider_check implements egw_cache_prov
return unlink($fname);
}
/**
* Delete all data under given keys
*
* @param array $keys eg. array($level,$app,$location)
* @return boolean true on success, false on error (eg. $key not set)
*/
function flush(array $keys)
{
$dir = $this->filename($keys, false);
return file_exists($dir) ? self::rm_recursive($dir) : true;
}
/**
* Recursive delete a path
*
* @param string $path
* @return boolean true on success, false otherwise
*/
private static function rm_recursive($path)
{
if (!is_dir($path))
{
return unlink($path);
}
foreach(scandir($path) as $file)
{
if ($file == '.' || $file == '..') continue;
$file = $path.'/'.$file;
if (is_dir($file))
{
if (!self::rm_recursive($file)) return false;
}
else
{
if (!unlink($path.'/'.$file)) return false;
}
}
return rmdir($path);
}
/**
* Create a path from $keys and $basepath
*

View File

@ -232,6 +232,8 @@ else
if(@get_var('hooks', Array('GET')))
{
egw_cache::flush(egw_cache::INSTANCE);
// Find & register all application hooks
foreach($setup_info as $appname => $info)
{

View File

@ -69,7 +69,7 @@ class setup_html
}
$GLOBALS['header_template']->set_var('domain','');
$setting = get_var('setting',Array('POST'));
while($setting && list($k,$v) = @each($setting))
{
@ -135,7 +135,7 @@ class setup_html
{
$btn_logout = '<a href="index.php?FormLogout=' . $logoutfrom . '" class="link">' . lang('Logout').'</a>';
$check_install = '<a class="textsidebox" href="check_install.php">'.lang('Check installation').'</a>';
$register_hooks = '<a class="textsidebox" href="applications.php?hooks=1">'.lang('Find and Register all Application Hooks').'</a>';
$register_hooks = '<a class="textsidebox" href="applications.php?hooks=1">'.lang('Clear cache and register hooks').'</a>';
}
$GLOBALS['setup_tpl']->set_var('lang_setup', lang('setup'));
@ -305,7 +305,7 @@ class setup_html
}
}
$select .= '</select>' . "\n";
return $select;
}

View File

@ -151,6 +151,7 @@ checking php.ini setup de Überprüfe die php.ini Datei
checking required php version %1 (recommended %2) setup de Überprüfe benötigte PHP Version %1 (empfohlen %2)
checking the egroupware installation setup de Überprüfe die EGroupware-Installation
checks egroupware's installed, it's versions and necessary upgrads (return values see --exit-codes) setup de Überprüft ob EGroupware installiert ist, die Version und notwendige Aktualisierungen (Rückgabewerte siehe --exit-codes)
clear cache and register hooks setup de Cache löschen und Hooks registrieren
click <a href="index.php">here</a> to return to setup. setup de <a href="index.php">Hier klicken</a> um zu Setup zurück zu kehren.
click here setup de Hier klicken
click here to re-run the installation tests setup de zum Wiederholen der Installationstests hier klicken
@ -294,7 +295,6 @@ file uploads are switched off: you can not use any of the filemanagers, nor can
filename setup de Dateiname
filesystem setup de Dateisystem
filesystem (default) setup de Dateisystem (Vorgabe)
find and register all application hooks setup de Suchen und registrieren der "Hooks" aller Anwendungen
force selectbox setup de Auswahl erzwingen
give admin access to all installed apps setup de Admin Zugang zu allen installierten Anwendungen geben
gives further options setup de gibt zusätzliche Optionen

View File

@ -151,6 +151,7 @@ checking php.ini setup en Checking php.ini
checking required php version %1 (recommended %2) setup en Checking required PHP version %1 (recommended %2)
checking the egroupware installation setup en Checking the eGroupWare Installation
checks egroupware's installed, it's versions and necessary upgrads (return values see --exit-codes) setup en Checks EGroupware, it's versions and necessary upgrades (return values see --exit-codes)
clear cache and register hooks setup en Clear cache and register hooks
click <a href="index.php">here</a> to return to setup. setup en Click <a href="index.php">here</a> to return to setup.
click here setup en Click here
click here to re-run the installation tests setup en Click here to re-run the installation tests
@ -294,7 +295,6 @@ file uploads are switched off: you can not use any of the filemanagers, nor can
filename setup en File name
filesystem setup en File system
filesystem (default) setup en File system (default)
find and register all application hooks setup en Find and register all application hooks
force selectbox setup en Force select box
give admin access to all installed apps setup en Give admin access to all installed apps
gives further options setup en Gives further options