Caching of filters added (should work now)
authorRoland Häder <roland@mxchange.org>
Wed, 26 Aug 2009 05:04:58 +0000 (05:04 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 26 Aug 2009 05:04:58 +0000 (05:04 +0000)
12 files changed:
.gitattributes
inc/extensions/ext-cache.php
inc/filters.php
inc/language/cache_de.php
inc/libs/cache_functions.php
inc/load_cache.php
inc/load_extensions.php
inc/loader/load_cache-config.php
inc/loader/load_cache-filter.php [new file with mode: 0644]
inc/modules/admin/overview-inc.php
inc/modules/admin/what-config_cache.php
templates/de/html/admin/admin_config_cache.tpl

index 4b456d2..113ad40 100644 (file)
@@ -274,6 +274,7 @@ inc/load_extensions.php -text
 inc/loader/.htaccess -text
 inc/loader/load_cache-admin.php -text
 inc/loader/load_cache-config.php -text
+inc/loader/load_cache-filter.php -text
 inc/loader/load_cache-modreg.php -text
 inc/loader/load_cache-refdepths.php -text
 inc/loader/load_cache-refsystem.php -text
index 1717525..8f384d5 100644 (file)
@@ -44,10 +44,10 @@ if (!defined('__SECURITY')) {
 }
 
 // Version number
-EXT_SET_VERSION('0.2.2');
+EXT_SET_VERSION('0.2.3');
 
 // Version history array (add more with , '0.1.0' and so on)
-EXT_SET_VER_HISTORY(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2'));
+EXT_SET_VER_HISTORY(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3'));
 
 // Which load mode?
 switch ($EXT_LOAD_MODE) {
@@ -74,6 +74,7 @@ switch ($EXT_LOAD_MODE) {
                unregisterFilter('post_admin_deleted', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
                unregisterFilter('post_admin_reset_pass', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
                unregisterFilter('extension_remove', 'CACHE_DESTROY_ALL', true, $dry_run);
+               unregisterFilter('shutdown', 'CACHE_DESTROY_FILTER', true, $dry_run);
                break;
 
        case 'activate': // Do stuff when admin activates this extension
@@ -237,6 +238,16 @@ switch ($EXT_LOAD_MODE) {
                                // Update notes (these will be set as task text!)
                                EXT_SET_UPDATE_NOTES("Weitere Filter hinzugef&uuml;gt.");
                                break;
+
+                       case '0.2.3': // SQL queries for v0.2.3
+                               ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_filter ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+
+                               // Update notes (these will be set as task text!)
+                               EXT_SET_UPDATE_NOTES("Cachen von Filtern hinzugef&uuml;gt.");
+
+                               // Register a new filter
+                               registerFilter('shutdown', 'CACHE_DESTROY_FILTER', false, true, $dry_run);
+                               break;
                }
                break;
 
index 433f495..39d86d1 100644 (file)
@@ -47,8 +47,7 @@ function initFilterSystem () {
        // Is the filter already initialized?
        if ((isset($GLOBALS['filters']['chains'])) && (is_array($GLOBALS['filters']['chains']))) {
                // Then abort here
-               addFatalMessage(__FUNCTION__, __LINE__, getMessage('FILTER_FAILED_ALREADY_INIT'));
-               return false;
+               debug_report_bug(getMessage('FILTER_FAILED_ALREADY_INIT'));
        } // END - if
 
        // Init the filter system (just some ideas)
@@ -63,7 +62,26 @@ function initFilterSystem () {
        $GLOBALS['filters']['counter'] = array();
 
        // Load all saved filers if sql_patches is updated
-       if (GET_EXT_VERSION('sql_patches') >= '0.5.9') {
+       if (isset($GLOBALS['cache_array']['filter'])) {
+               // Found in cache so rewrite the array
+               $filterArray = array();
+               foreach ($GLOBALS['cache_array']['filter']['filter_name'] as $idx => $filterName) {
+                       // Get filter function
+                       $filterFunction = $GLOBALS['cache_array']['filter']['filter_function'][$idx];
+
+                       // Add the element with mapped index
+                       $filterArray['counter'][$filterName][$filterFunction] = $GLOBALS['cache_array']['filter']['filter_counter'][$idx];
+                       $filterArray['loaded'][$filterName][$filterFunction]  = true;
+                       $filterArray['chains'][$filterName][$filterFunction]  = $GLOBALS['cache_array']['filter']['filter_active'][$idx];
+               } // END - foreach
+
+               // Set the array
+               //die('<pre>'.print_r($filterArray, true).'</pre>');
+               $GLOBALS['filters'] = $filterArray;
+
+               // Remove the cache
+               unset($GLOBALS['cache_array']['filter']);
+       } elseif (GET_EXT_VERSION('sql_patches') >= '0.5.9') {
                // Init add
                $add = '';
                if (GET_EXT_VERSION('sql_patches') >= '0.6.0') $add = ", `filter_counter`";
@@ -100,38 +118,38 @@ ORDER BY `filter_id` ASC", __FUNCTION__, __LINE__);
 
                // Free result
                SQL_FREERESULT($result);
-       } // END - if
 
-       // Init filters
-       registerFilter('init', 'UPDATE_LOGIN_DATA');
-       registerFilter('init', 'INIT_RANDOMIZER');
+               // Init filters
+               registerFilter('init', 'UPDATE_LOGIN_DATA');
+               registerFilter('init', 'INIT_RANDOMIZER');
 
-       // Login failures handler
-       registerFilter('post_youhere_line', 'CALL_HANDLER_LOGIN_FAILTURES');
+               // Login failures handler
+               registerFilter('post_youhere_line', 'CALL_HANDLER_LOGIN_FAILTURES');
 
-       // Filters for pre-extension-registration
-       registerFilter('pre_extension_installed', 'RUN_SQLS');
+               // Filters for pre-extension-registration
+               registerFilter('pre_extension_installed', 'RUN_SQLS');
 
-       // Filters for post-extension-registration
-       registerFilter('post_extension_installed', 'AUTO_ACTIVATE_EXTENSION');
-       registerFilter('post_extension_installed', 'SOLVE_TASK');
-       registerFilter('post_extension_installed', 'LOAD_INCLUDES');
-       registerFilter('post_extension_installed', 'REMOVE_UPDATES');
+               // Filters for post-extension-registration
+               registerFilter('post_extension_installed', 'AUTO_ACTIVATE_EXTENSION');
+               registerFilter('post_extension_installed', 'SOLVE_TASK');
+               registerFilter('post_extension_installed', 'LOAD_INCLUDES');
+               registerFilter('post_extension_installed', 'REMOVE_UPDATES');
 
-       // Solving tasks
-       registerFilter('solve_task', 'SOLVE_TASK');
+               // Solving tasks
+               registerFilter('solve_task', 'SOLVE_TASK');
 
-       // Loading includes in general
-       registerFilter('load_includes', 'LOAD_INCLUDES');
+               // Loading includes in general
+               registerFilter('load_includes', 'LOAD_INCLUDES');
 
-       // Run SQLs
-       registerFilter('run_sqls', 'RUN_SQLS');
+               // Run SQLs
+               registerFilter('run_sqls', 'RUN_SQLS');
 
-       // Admin ACL check
-       registerFilter('check_admin_acl', 'CHECK_ADMIN_ACL');
+               // Admin ACL check
+               registerFilter('check_admin_acl', 'CHECK_ADMIN_ACL');
 
-       // Register shutdown filters
-       registerFilter('shutdown', 'FLUSH_FILTERS');
+               // Register shutdown filters
+               registerFilter('shutdown', 'FLUSH_FILTERS');
+       } // END - if
 }
 
 // "Registers" a new filter function
@@ -319,9 +337,9 @@ function FILTER_FLUSH_FILTERS () {
                        foreach ($filterArray as $filterFunction => $cnt) {
                                // Construct and add the query
                                ADD_SQL(sprintf("UPDATE `{!_MYSQL_PREFIX!}_filters` SET `filter_counter`=%s WHERE `filter_name`='%s' AND `filter_function`='%s' LIMIT 1",
-                               bigintval($cnt),
-                               $filterName,
-                               $filterFunction
+                                       bigintval($cnt),
+                                       $filterName,
+                                       $filterFunction
                                ));
                        } // END - foreach
                } // END - foreach
index d6aa353..a9e3ca5 100644 (file)
@@ -65,6 +65,7 @@ define('ADMIN_CACHE_CONFIG', "Soll der Zugriff auf die Tabelle <strong>{!_MYSQL_
 define('ADMIN_CACHE_MODREG', "Soll der Zugriff auf die Tabelle <strong>{!_MYSQL_PREFIX!}_mod_reg</strong> beschleunigt werden?");
 define('ADMIN_CACHE_REFDEPTH', "Soll der Zugriff auf die Tabelle <strong>{!_MYSQL_PREFIX!}_refdepths</strong> beschleunigt werden?");
 define('ADMIN_CACHE_REFSYS', "Soll der Zugriff auf die Tabelle <strong>{!_MYSQL_PREFIX!}_refsystem</strong> beschleunigt werden?");
+define('ADMIN_CACHE_filter', "Soll der Zugriff auf die Tabelle <strong>{!_MYSQL_PREFIX!}_filter</strong> beschleunigt werden?");
 define('ADMIN_CACHE_THEMES', "Soll der Zugriff auf die Tabelle <strong>{!_MYSQL_PREFIX!}_themes</strong> beschleunigt werden?");
 define('ADMIN_CACHE_ADMIN_MENU', "Soll der Aufbau des Administratormen&uuml;s beschleunigt werden (EXPERIMENTELL!)?");
 define('ADMIN_CACHE_PATH', "Relativer Pfad f&uuml;r alle Cache-Dateien zum Pfad <strong>inc</strong>");
index 17910c9..a34313d 100644 (file)
@@ -477,7 +477,7 @@ function FILTER_CACHE_DESTROY_ON_ADMIN_CHANGE () {
 // Destroy all cache files
 function FILTER_CACHE_DESTROY_ALL () {
        // Skip this step if the cache instance is not there
-       DEBUG_LOG(__FUNCTION__, __LINE__, 'Called!');
+       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, 'Called!');
        if (!isCacheInstanceValid()) return false;
 
        // Remove cache files
@@ -490,7 +490,17 @@ function FILTER_CACHE_DESTROY_ALL () {
        if ($GLOBALS['cache_instance']->loadCacheFile('refsystem'))   $GLOBALS['cache_instance']->destroyCacheFile(false);
        if ($GLOBALS['cache_instance']->loadCacheFile('themes'))      $GLOBALS['cache_instance']->destroyCacheFile(false);
        if ($GLOBALS['cache_instance']->loadCacheFile('revision'))    $GLOBALS['cache_instance']->destroyCacheFile(false);
-       DEBUG_LOG(__FUNCTION__, __LINE__, 'Done!');
+       if ($GLOBALS['cache_instance']->loadCacheFile('filter'))      $GLOBALS['cache_instance']->destroyCacheFile(false);
+       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, 'Done!');
+}
+
+// Filter for purging 'filter' cache
+function FILTER_CACHE_DESTROY_FILTER () {
+       // Skip this step if the cache instance is not there
+       if ((!isCacheInstanceValid()) || (getConfig('update_filter_usage') == 'N')) return false;
+
+       // Remove cache files
+       if ($GLOBALS['cache_instance']->loadCacheFile('filter'))      $GLOBALS['cache_instance']->destroyCacheFile(false);
 }
 
 // Filter for purging entire admin menu cache
index ffe91d9..2a6dc15 100644 (file)
@@ -46,8 +46,16 @@ if (!defined('__SECURITY')) {
 INIT_INC_POOL();
 SET_INC_POOL(getArrayFromDirectory('inc/loader/', 'load_cache-'));
 
-// Run the filter
-runFilterChain('load_includes');
+// Pre-load filter cacher
+loadIncludeOnce('inc/loader/load_cache-filter.php');
+
+// Init filter system here
+initFilterSystem();
+
+// We have to include all here by-hand
+foreach (GET_INC_POOL() as $inc) {
+       loadIncludeOnce($inc);
+} // END - foreach
 
 //
 ?>
index 731bbd4..d5c3130 100644 (file)
@@ -159,7 +159,7 @@ if ($GLOBALS['cache_mode'] == 'load') {
                $EXT_DUMMY['ext_deprecated'][$name] = 'N';
 
                // Mark it as active extension
-               $GLOBALS['cache_array']['active_extensions']['$name'] = $EXT_DUMMY['ext_keep'][$k];
+               $GLOBALS['cache_array']['active_extensions'][$name] = $EXT_DUMMY['ext_keep'][$k];
                unset($EXT_DUMMY['ext_keep'][$k]);
 
                // Remove unneccessary data from memory
@@ -184,9 +184,6 @@ if ($GLOBALS['cache_mode'] == 'load') {
                LOAD_EXTENSION($ext);
        } // END - foreach
 
-       // Init filter system
-       initFilterSystem();
-
        // Load more cache files (like admins)
        loadIncludeOnce('inc/load_cache.php');
 
@@ -274,16 +271,16 @@ if ((SQL_NUMROWS($res_ext_crt) > 0) && ((($GLOBALS['cache_mode'] == 'init') && (
                }
        } // END - while
 
-       // Init filter system
-       initFilterSystem();
-
        if ($GLOBALS['cache_mode'] == 'init') {
                // Close cache file
                $GLOBALS['cache_instance']->finalize();
 
                // Load more cache files (like admins)
                loadIncludeOnce('inc/load_cache.php');
-       } // END - if
+       } else {
+               // Init filter system for non-init mode
+               initFilterSystem();
+       }
 
        // Free memory
        SQL_FREERESULT($res_ext_crt);
index b0e9f29..8f7e4a7 100644 (file)
@@ -52,7 +52,7 @@ if (($GLOBALS['cache_instance']->loadCacheFile('config', true)) && ($GLOBALS['ca
        $GLOBALS['cache_instance']->storeExtensionVersion('sql_patches');
 
        // Load all modules and their data
-       $result = SQL_QUERY('SELECT * FROM `{!_MYSQL_PREFIX!}_config` ORDER BY config ASC', __FILE__, __LINE__);
+       $result = SQL_QUERY('SELECT * FROM `{!_MYSQL_PREFIX!}_config` ORDER BY `config` ASC', __FILE__, __LINE__);
        while ($data = SQL_FETCHARRAY($result)) {
                // Add row to cache file
                $GLOBALS['cache_instance']->addRow($data);
diff --git a/inc/loader/load_cache-filter.php b/inc/loader/load_cache-filter.php
new file mode 100644 (file)
index 0000000..de3c932
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+/************************************************************************
+ * MXChange v0.2.1                                    Start: 08/26/2008 *
+ * ===============                              Last change: 08/26/2008 *
+ *                                                                      *
+ * -------------------------------------------------------------------- *
+ * File              : load_cache-filter.php                            *
+ * -------------------------------------------------------------------- *
+ * Short description : Load more cache files                            *
+ * -------------------------------------------------------------------- *
+ * Kurzbeschreibung  : Mehr Cache-Dateien nachladen                     *
+ * -------------------------------------------------------------------- *
+ * $Revision:: 1092                                                   $ *
+ * $Date:: 2009-07-28 20:50:32 +0200 (Tue, 28 Jul 2009)               $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author:: quix0r                                                   $ *
+ * Needs to be in all Files and every File needs "svn propset           *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
+ * -------------------------------------------------------------------- *
+ * Copyright (c) 2003 - 2008 by Roland Haeder                           *
+ * For more information visit: http://www.mxchange.org                  *
+ *                                                                      *
+ * This program 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.                                  *
+ *                                                                      *
+ * This program 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.                         *
+ *                                                                      *
+ * You should have received a copy of the GNU General Public License    *
+ * along with this program; if not, write to the Free Software          *
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
+ * MA  02110-1301  USA                                                  *
+ ************************************************************************/
+
+// Some security stuff...
+if (!defined('__SECURITY')) {
+       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
+       require($INC);
+}
+
+// Skip this cache if we count usage
+if (getConfig('update_filter_usage') == 'Y') return;
+
+// Next cached table is the filteruration (filter)...
+if (($GLOBALS['cache_instance']->loadCacheFile('filter', true)) && ($GLOBALS['cache_instance']->extensionVersionMatches('sql_patches'))) {
+       // Load filter from cache
+       $GLOBALS['cache_array']['filter'] = $GLOBALS['cache_instance']->getArrayFromCache();
+} elseif ((getConfig('cache_filter') == 'Y') && (getOutputMode() != '1') && (getOutputMode() != '-1')) {
+       // Create cache file here
+       $GLOBALS['cache_instance']->init('FILTER');
+       $GLOBALS['cache_instance']->storeExtensionVersion('sql_patches');
+
+       // Load all modules and their data
+       $result = SQL_QUERY('SELECT * FROM `{!_MYSQL_PREFIX!}_filters` ORDER BY `filter_name` ASC', __FILE__, __LINE__);
+       while ($data = SQL_FETCHARRAY($result)) {
+               // Add row to cache file
+               $GLOBALS['cache_instance']->addRow($data);
+       } // END - while
+
+       // Free memory
+       SQL_FREERESULT($result);
+
+       // Close the cache
+       $GLOBALS['cache_instance']->finalize();
+
+       // Include loader again
+       require(__FILE__);
+}
+
+//
+?>
index 4675398..e553173 100644 (file)
@@ -45,18 +45,20 @@ if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
 function OUTPUT_STANDARD_OVERVIEW (&$result_tasks) {
        // First check for solved and not assigned tasks and assign them to current admin
        SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_task_system` SET `assigned_admin`=%s WHERE assigned_admin < 1 AND status != 'NEW'",
-       array(getCurrentAdminId()), __FILE__, __LINE__);
+               array(getCurrentAdminId()), __FILE__, __LINE__);
 
        // We currently don't want to install an extension so let's find out if we need...
        $EXT_LOAD_MODE = 'register';
        $jobsDone = true;
 
        // Open the extension directory
-       $extensionList = getArrayFromDirectory("inc/extensions/", "ext-", false, false);
+       $extensionList = getArrayFromDirectory('inc/extensions/', 'ext-', false, false);
        foreach ($extensionList as $file) {
+               // Only file name is required... :(
+               $file = basename($file);
+
                // Is this file an extension?
-               if ((substr($file, 0, 4) == "ext-") && (substr($file, -4) == '.php')) {
-                       //* DEBUG: */ echo $file."<br />\n";
+               if ((substr($file, 0, 4) == 'ext-') && (substr($file, -4) == '.php')) {
                        // Possible newly installed extension found so we extract extension's name
                        $ext_name = strtolower(substr($file, 4, -4)); // Keep always extension names on lower case!!!
 
@@ -65,6 +67,7 @@ function OUTPUT_STANDARD_OVERVIEW (&$result_tasks) {
 
                        // Check if extension is installed or not
                        $ext_ver = GET_EXT_VERSION($ext_name);
+                       //* DEBUG: */ echo $ext_name."=".$ext_ver."<br />\n";
 
                        // Is the extension not yet installed?
                        if (empty($ext_ver)) {
index 59ac1df..28b2d7e 100644 (file)
@@ -83,6 +83,10 @@ if (isFormSent()) {
                $GLOBALS['cache_instance']->destroyCacheFile();
        } // END - if
 
+       if ((REQUEST_POST('cache_filter') == 'N') && ($GLOBALS['cache_instance']->loadCacheFile('filter'))) {
+               $GLOBALS['cache_instance']->destroyCacheFile();
+       } // END - if
+
        // Save configuration
        ADMIN_SAVE_SETTINGS_POST();
 } else {
@@ -172,6 +176,18 @@ if (isFormSent()) {
                        break;
        } // END - switch
 
+       switch (getConfig('cache_filter')) {
+               case 'Y':
+                       define('__FILTER_Y', ' checked="checked"');
+                       define('__FILTER_N', '');
+                       break;
+
+               case 'N':
+                       define('__FILTER_Y', '');
+                       define('__FILTER_N', ' checked="checked"');
+                       break;
+       } // END - switch
+
        switch (getConfig('cache_themes')) {
                case 'Y':
                        define('__THEMES_Y', ' checked="checked"');
index 478af6b..4d1dca9 100644 (file)
        </tr>
        <tr>
                <td align="right" width="350" height="20">
+               {--ADMIN_CACHE_FILTER--}</td>
+               <td width="150" style="padding-left: 10px"><input type="radio"
+                       name="cache_filter" value="Y" class="admin_normal"{!__FILTER_Y!} />&nbsp;{--YES--}
+               <input type="radio" name="cache_filter" value="N" class="admin_normal"{!__FILTER_N!} />&nbsp;{--NO--}&nbsp;
+               </td>
+       </tr>
+       <tr>
+               <td colspan="2" class="seperator" height="10">&nbsp;</td>
+       </tr>
+       <tr>
+               <td align="right" width="350" height="20">
                {--ADMIN_CACHE_THEMES--}</td>
                <td width="150" style="padding-left: 10px"><input type="radio"
                        name="cache_themes" value="Y" class="admin_normal"{!__THEMES_Y!} />&nbsp;{--YES--}