From b514745d01e674b36f1faf63a30da08ab3575967 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 31 Oct 2012 13:56:40 +0000 Subject: [PATCH] * Admin: new function "Clear cache and register hooks", also called automatic when restoring a backup --- .../class.admin_prefs_sidebox_hooks.inc.php | 4 +- admin/lang/egw_de.lang | 2 +- admin/lang/egw_en.lang | 2 +- phpgwapi/inc/class.db_backup.inc.php | 6 +- phpgwapi/inc/class.egw_cache.inc.php | 87 ++++++++++++++++++- 5 files changed, 94 insertions(+), 7 deletions(-) diff --git a/admin/inc/class.admin_prefs_sidebox_hooks.inc.php b/admin/inc/class.admin_prefs_sidebox_hooks.inc.php index 8f2a1826bd..cbd39cbc40 100644 --- a/admin/inc/class.admin_prefs_sidebox_hooks.inc.php +++ b/admin/inc/class.admin_prefs_sidebox_hooks.inc.php @@ -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(); common::delete_image_map(); diff --git a/admin/lang/egw_de.lang b/admin/lang/egw_de.lang index 63e3db4f32..7958fdfc7b 100644 --- a/admin/lang/egw_de.lang +++ b/admin/lang/egw_de.lang @@ -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 %1 to %2 for %3 admin de Durch Abhaken %3 in %2 %1 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) diff --git a/admin/lang/egw_en.lang b/admin/lang/egw_en.lang index 127633c72f..482ad8af0f 100644 --- a/admin/lang/egw_en.lang +++ b/admin/lang/egw_en.lang @@ -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 %1 to %2 for %3 admin en Check items to %1 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 diff --git a/phpgwapi/inc/class.db_backup.inc.php b/phpgwapi/inc/class.db_backup.inc.php index 64ac0a5b3e..3ecc954e0c 100644 --- a/phpgwapi/inc/class.db_backup.inc.php +++ b/phpgwapi/inc/class.db_backup.inc.php @@ -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 ''; } diff --git a/phpgwapi/inc/class.egw_cache.inc.php b/phpgwapi/inc/class.egw_cache.inc.php index 374b969064..886cc160f2 100644 --- a/phpgwapi/inc/class.egw_cache.inc.php +++ b/phpgwapi/inc/class.egw_cache.inc.php @@ -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