Many rewrites to get rid of dublicate modreg inserts while ext-cache is registered
authorRoland Häder <roland@mxchange.org>
Wed, 26 Aug 2009 04:14:26 +0000 (04:14 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 26 Aug 2009 04:14:26 +0000 (04:14 +0000)
inc/extensions.php
inc/extensions/ext-cache.php
inc/filters.php
inc/functions.php
inc/libs/cache_functions.php
inc/load_extensions.php
inc/mysql-manager.php

index 5f3a704895bc1a7588896fdbecb018a6e5c2158b..93f6fa192a254236a2f76f7a17f82019090b95b8 100644 (file)
@@ -442,7 +442,7 @@ function EXT_IS_ACTIVE ($ext_name) {
        } elseif (($ext_name == 'cache') || (GET_EXT_VERSION('cache') == '')) {
                //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "DB! ext_name={$ext_name}");
                // Load from database
        } elseif (($ext_name == 'cache') || (GET_EXT_VERSION('cache') == '')) {
                //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "DB! ext_name={$ext_name}");
                // Load from database
-               $result = SQL_QUERY_ESC("SELECT ext_active FROM `{!_MYSQL_PREFIX!}_extensions` WHERE `ext_name`='%s' LIMIT 1",
+               $result = SQL_QUERY_ESC("SELECT `ext_active` FROM `{!_MYSQL_PREFIX!}_extensions` WHERE `ext_name`='%s' LIMIT 1",
                        array($ext_name), __FUNCTION__, __LINE__);
 
                // Entry found?
                        array($ext_name), __FUNCTION__, __LINE__);
 
                // Entry found?
@@ -464,7 +464,7 @@ function EXT_IS_ACTIVE ($ext_name) {
        }
 
        // Debug message
        }
 
        // Debug message
-       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, " ext_name={$ext_name},active={$active}");
+       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "ext_name={$ext_name},active={$active}");
 
        // Is this extension activated? (For admins we always have active extensions...)
        return ($active == 'Y');
 
        // Is this extension activated? (For admins we always have active extensions...)
        return ($active == 'Y');
@@ -494,7 +494,7 @@ function GET_EXT_VERSION ($ext_name) {
                incrementConfigEntry('cache_hits');
        } elseif (!isCacheInstanceValid()) {
                // Load from database
                incrementConfigEntry('cache_hits');
        } elseif (!isCacheInstanceValid()) {
                // Load from database
-               $result = SQL_QUERY_ESC("SELECT ext_version FROM `{!_MYSQL_PREFIX!}_extensions` WHERE `ext_name`='%s' LIMIT 1",
+               $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{!_MYSQL_PREFIX!}_extensions` WHERE `ext_name`='%s' LIMIT 1",
                        array($ext_name), __FUNCTION__, __LINE__);
                //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": DB - ".SQL_NUMROWS($result)."");
 
                        array($ext_name), __FUNCTION__, __LINE__);
                //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": DB - ".SQL_NUMROWS($result)."");
 
index 75780f06d20cf0e4ddca1a8a87e2deb99b4c501e..171752500a96abdbb5e9bc58ea2517986413c86d 100644 (file)
@@ -49,8 +49,8 @@ EXT_SET_VERSION('0.2.2');
 // 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'));
 
 // 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'));
 
-switch ($EXT_LOAD_MODE)
-{
+// Which load mode?
+switch ($EXT_LOAD_MODE) {
        case 'register': // Do stuff when installation is running (modules.php?module=admin is called)
                // SQL commands to run
                ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_update BIGINT(20) UNSIGNED NOT NULL DEFAULT 3600");
        case 'register': // Do stuff when installation is running (modules.php?module=admin is called)
                // SQL commands to run
                ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_update BIGINT(20) UNSIGNED NOT NULL DEFAULT 3600");
@@ -87,8 +87,8 @@ switch ($EXT_LOAD_MODE)
                break;
 
        case 'update': // Update an extension
                break;
 
        case 'update': // Update an extension
-               switch ($EXT_VER)
-               {
+               // Which version?
+               switch ($EXT_VER) {
                        case '0.0.1': // SQL queries for v0.0.1
                                // Update notes (these will be set as task text!)
                                EXT_SET_UPDATE_NOTES("Es wurde die Zeitmarke der Cache-Datei extensions.cache mit ber&uuml;cksichtigt. Dies hatte die Folge, dass wenn bei einem Gast die Datei aktualisiert wurde, nur aktivierte und nicht die deaktivierten mit geladen wurden. Folglich fiehlen einfach ein paar Erweiterungen aus.");
                        case '0.0.1': // SQL queries for v0.0.1
                                // Update notes (these will be set as task text!)
                                EXT_SET_UPDATE_NOTES("Es wurde die Zeitmarke der Cache-Datei extensions.cache mit ber&uuml;cksichtigt. Dies hatte die Folge, dass wenn bei einem Gast die Datei aktualisiert wurde, nur aktivierte und nicht die deaktivierten mit geladen wurden. Folglich fiehlen einfach ein paar Erweiterungen aus.");
@@ -240,23 +240,23 @@ switch ($EXT_LOAD_MODE)
                }
                break;
 
                }
                break;
 
-                       case 'modify': // When the extension got modified
-                               break;
+       case 'modify': // When the extension got modified
+               break;
 
 
-                       case 'test': // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
-                               break;
+       case 'test': // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
+               break;
 
 
-                       default: // Do stuff when extension is loaded
-                               // Create instance on class
-                               if ($GLOBALS['cache_mode'] != 'init') {
-                                       // Initialize cache system only when it's needed
-                                       $GLOBALS['cache_instance'] = new CacheSystem(getConfig('cache_update'), "inc/".getConfig('cache_path'), getConfig('cache_tested'));
-                                       if ($GLOBALS['cache_instance']->getStatus() != 'done') {
-                                               // Failed to initialize cache sustem
-                                               addFatalMessage(__FILE__, __LINE__, "(<font color=\"#0000aa\">".__LINE__."</font>): ".getMessage('CACHE_CANNOT_INITIALIZE'));
-                                       } // END - if
-                               } // END - if
-                               break;
+       default: // Do stuff when extension is loaded
+               // Create instance on class
+               if ($GLOBALS['cache_mode'] != 'init') {
+                       // Initialize cache system only when it's needed
+                       $GLOBALS['cache_instance'] = new CacheSystem(getConfig('cache_update'), 'inc/' . getConfig('cache_path'), getConfig('cache_tested'));
+                       if ($GLOBALS['cache_instance']->getStatus() != 'done') {
+                               // Failed to initialize cache sustem
+                               addFatalMessage(__FILE__, __LINE__, "(<font color=\"#0000aa\">".__LINE__."</font>): ".getMessage('CACHE_CANNOT_INITIALIZE'));
+                       } // END - if
+               } // END - if
+               break;
 }
 
 // Keep this extension always active!
 }
 
 // Keep this extension always active!
index e8f598c857c1f18dc1c89c20055ef1f343e61b3b..433f4958099751fac2a590f2c0131458aee57208 100644 (file)
@@ -115,14 +115,14 @@ ORDER BY `filter_id` ASC", __FUNCTION__, __LINE__);
        // Filters for post-extension-registration
        registerFilter('post_extension_installed', 'AUTO_ACTIVATE_EXTENSION');
        registerFilter('post_extension_installed', 'SOLVE_TASK');
        // Filters for post-extension-registration
        registerFilter('post_extension_installed', 'AUTO_ACTIVATE_EXTENSION');
        registerFilter('post_extension_installed', 'SOLVE_TASK');
-       registerFilter('post_extension_installed', 'loadIncludeLUDES');
+       registerFilter('post_extension_installed', 'LOAD_INCLUDES');
        registerFilter('post_extension_installed', 'REMOVE_UPDATES');
 
        // Solving tasks
        registerFilter('solve_task', 'SOLVE_TASK');
 
        // Loading includes in general
        registerFilter('post_extension_installed', 'REMOVE_UPDATES');
 
        // Solving tasks
        registerFilter('solve_task', 'SOLVE_TASK');
 
        // Loading includes in general
-       registerFilter('load_includes', 'loadIncludeLUDES');
+       registerFilter('load_includes', 'LOAD_INCLUDES');
 
        // Run SQLs
        registerFilter('run_sqls', 'RUN_SQLS');
 
        // Run SQLs
        registerFilter('run_sqls', 'RUN_SQLS');
@@ -190,21 +190,15 @@ function unregisterFilter ($filterName, $filterFunction, $force = false, $dry_ru
 function runFilterChain ($filterName, $data = null, $silentAbort = true) {
        // Is that filter chain there?
        if (!isset($GLOBALS['filters']['chains'][$filterName])) {
 function runFilterChain ($filterName, $data = null, $silentAbort = true) {
        // Is that filter chain there?
        if (!isset($GLOBALS['filters']['chains'][$filterName])) {
-               // Then abort here (quick'N'dirty hack)
-               if (($silentAbort === false) && (defined('FILTER_FAILED_NO_FILTER_FOUND'))) {
-                       // Add fatal message
-                       addFatalMessage(__FUNCTION__, __LINE__, getMessage('FILTER_FAILED_NO_FILTER_FOUND'), $filterName);
-               } // END - if
-
-               // Abort here
-               return false;
+               // We should find all these non-existing filter chains
+               debug_report_bug('Filter chain '.$filterName.' not found!');
        } // END - if
 
        // Default return value
        $returnValue = $data;
 
        // Then run all filters
        } // END - if
 
        // Default return value
        $returnValue = $data;
 
        // Then run all filters
-       foreach ($GLOBALS['filters']['chains'][$filterName] as $filterFunction=>$active) {
+       foreach ($GLOBALS['filters']['chains'][$filterName] as $filterFunction => $active) {
                // Debug message
                //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Running: name={$filterName},func={$filterFunction},active={$active}");
 
                // Debug message
                //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Running: name={$filterName},func={$filterFunction},active={$active}");
 
@@ -400,7 +394,7 @@ function FILTER_SOLVE_TASK ($data) {
 }
 
 // Filter to load include files
 }
 
 // Filter to load include files
-function FILTER_loadIncludeLUDES () {
+function FILTER_LOAD_INCLUDES () {
        // Default is $data as inclusion list
        $data = GET_INC_POOL();
 
        // Default is $data as inclusion list
        $data = GET_INC_POOL();
 
index 342ab2e3fcf36b64cbc907c6fd2cb2dd189f5def..eedc0215f907ba0cd906e99aadef557541a458f1 100644 (file)
@@ -347,8 +347,11 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
                        $ret = $tmpl_file;
                }
 
                        $ret = $tmpl_file;
                }
 
-               // Add surrounding HTML comments to help finding bugs faster
-               $ret = "<!-- Template " . $template . " - Start -->\n" . $ret . "<!-- Template " . $template . " - End -->\n";
+               // Normal HTML output?
+               if ($GLOBALS['output_mode'] == 0) {
+                       // Add surrounding HTML comments to help finding bugs faster
+                       $ret = "<!-- Template " . $template . " - Start -->\n" . $ret . "<!-- Template " . $template . " - End -->\n";
+               } // END - if
        } elseif ((IS_ADMIN()) || ((isInstalling()) && (!isInstalled()))) {
                // Only admins shall see this warning or when installation mode is active
                $ret = "<br /><span class=\"guest_failed\">{--TEMPLATE_404--}</span><br />
        } elseif ((IS_ADMIN()) || ((isInstalling()) && (!isInstalled()))) {
                // Only admins shall see this warning or when installation mode is active
                $ret = "<br /><span class=\"guest_failed\">{--TEMPLATE_404--}</span><br />
@@ -2482,9 +2485,12 @@ function getActualVersion ($type = 'Revision') {
                } // END - if
 
                // Is the cache file outdated/invalid?
                } // END - if
 
                // Is the cache file outdated/invalid?
-               if ($new === true){
+               if ($new === true) {
+                       // Reload the cache file
+                       $GLOBALS['cache_instance']->loadCacheFile('revision');
+
                        // Destroy cache file
                        // Destroy cache file
-                       $GLOBALS['cache_instance']->destroyCacheFile();
+                       $GLOBALS['cache_instance']->destroyCacheFile(false, true);
 
                        // @TODO shouldn't do the unset and the reloading $GLOBALS['cache_instance']->destroyCacheFile() Or a new methode like forceCacheReload('revision')?
                        unset($GLOBALS['cache_array']['revision']);
 
                        // @TODO shouldn't do the unset and the reloading $GLOBALS['cache_instance']->destroyCacheFile() Or a new methode like forceCacheReload('revision')?
                        unset($GLOBALS['cache_array']['revision']);
index ca0aee8331aebeb06611e7661d97b930e790755e..17910c97cdacc7c785655fae0f4b8e846a334187 100644 (file)
@@ -226,13 +226,13 @@ class CacheSystem {
        }
 
        // Destroy an existing cache file
        }
 
        // Destroy an existing cache file
-       function destroyCacheFile ($removeArray = false) {
+       function destroyCacheFile ($removeArray = false, $force = false) {
                // Only run in regular output mode
                // Only run in regular output mode
-               if (getOutputMode() != 0) {
+               if ((getOutputMode() != 0) && ($force === false)) {
                        // Debug message if allowed
                        if (isDebugModeEnabled()) {
                                // Debug message
                        // Debug message if allowed
                        if (isDebugModeEnabled()) {
                                // Debug message
-                               DEBUG_LOG(__METHOD__, __LINE__, 'Not removing cache ' . $this->name . ' in output_mode=' . getOutputMode());
+                               debug_report_bug('Not removing cache ' . $this->name . ' in output_mode=' . getOutputMode());
                        } // END - if
 
                        // Abort here
                        } // END - if
 
                        // Abort here
index f8589b66d2f7f4a51a932a74ed05747f4512d366..731bbd4bf94aec7335ce0801324bccd38d1f3ea3 100644 (file)
@@ -287,9 +287,12 @@ if ((SQL_NUMROWS($res_ext_crt) > 0) && ((($GLOBALS['cache_mode'] == 'init') && (
 
        // Free memory
        SQL_FREERESULT($res_ext_crt);
 
        // Free memory
        SQL_FREERESULT($res_ext_crt);
-} elseif (!EXT_IS_ACTIVE('cache')) {
+} elseif ((!EXT_IS_ACTIVE('cache')) || (($GLOBALS['cache_mode'] == 'init') && (getOutputMode() != 0))) {
        // Init filter system even when there are no extensions installed. #16
        initFilterSystem();
        // Init filter system even when there are no extensions installed. #16
        initFilterSystem();
+} elseif ($GLOBALS['cache_mode'] != 'load') {
+       // Something unexpected!
+       debug_report_bug('Unexpected state in '.basename(__FILE__).': cache_mode='.$GLOBALS['cache_mode'].', numRows='.SQL_NUMROWS($res_ext_crt));
 }
 
 // Run the filter
 }
 
 // Run the filter
@@ -301,11 +304,11 @@ if (!empty($DEL[0])) {
        foreach ($DEL as $del_ext) {
                // First remove entry from extensions table
                SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_extensions` WHERE `ext_name`='%s' LIMIT 1",
        foreach ($DEL as $del_ext) {
                // First remove entry from extensions table
                SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_extensions` WHERE `ext_name`='%s' LIMIT 1",
-               array($del_ext), __FILE__, __LINE__);
+                       array($del_ext), __FILE__, __LINE__);
 
                // Remove (maybe?) found tasks (main task and possible updates
 
                // Remove (maybe?) found tasks (main task and possible updates
-               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_task_system` WHERE subject='[%s:]' AND (task_type='EXTENSION' OR task_type='EXTENSION_UPDATE')",
-               array($del_ext), __FILE__, __LINE__);
+               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_task_system` WHERE `subject`='[%s:]' AND (`task_type`='EXTENSION' OR `task_type`='EXTENSION_UPDATE')",
+                       array($del_ext), __FILE__, __LINE__);
        } // END - foreach
 
        // I think it's not neccessary to run the optimization function here
        } // END - foreach
 
        // I think it's not neccessary to run the optimization function here
index 7137be73f1506e172de78d16de92b78503ed3168..b9eee9d47739ac896f5b38d720afcc0e3e26549a 100644 (file)
@@ -208,16 +208,16 @@ function checkModulePermissions ($mod) {
                } else {
                        // @TODO Nothing helped???
                        DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("ret=%s,locked=%s,admin=%s,mem=%s",
                } else {
                        // @TODO Nothing helped???
                        DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("ret=%s,locked=%s,admin=%s,mem=%s",
-                       $ret,
-                       $locked,
-                       $admin,
-                       $mem
+                               $ret,
+                               $locked,
+                               $admin,
+                               $mem
                        ));
                }
        } // END - if
 
        // Still no luck or not found?
                        ));
                }
        } // END - if
 
        // Still no luck or not found?
-       if (($ret == 'cache_miss') || ($found === false)) {
+       if (($found === false) && (!EXT_IS_ACTIVE('cache')) && ($ret != 'done'))  {
                //              ----- Legacy module -----                                               ---- Module in base folder  ----                       --- Module with extension's name ---
                if ((isFileReadable(sprintf("%sinc/modules/%s.php", constant('PATH'), $mod))) || (isFileReadable(sprintf("%s%s.php", constant('PATH'), $mod))) || (isFileReadable(sprintf("%s%s/%s.php", constant('PATH'), $extension, $mod)))) {
                        // Data is missing so we add it
                //              ----- Legacy module -----                                               ---- Module in base folder  ----                       --- Module with extension's name ---
                if ((isFileReadable(sprintf("%sinc/modules/%s.php", constant('PATH'), $mod))) || (isFileReadable(sprintf("%s%s.php", constant('PATH'), $mod))) || (isFileReadable(sprintf("%s%s/%s.php", constant('PATH'), $extension, $mod)))) {
                        // Data is missing so we add it
@@ -250,7 +250,10 @@ function checkModulePermissions ($mod) {
                        // Module not found we don't add it to the database
                        $ret = '404';
                }
                        // Module not found we don't add it to the database
                        $ret = '404';
                }
-       } elseif (!$found) {
+       } elseif ($ret == 'cache_miss') {
+               // Rebuild the cache files
+               rebuildCacheFiles('modreg', 'modreg');
+       } elseif ($found === false) {
                // Problem with module detected
                DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Problem in module %s detected. ret=%s, locked=%s, hidden=%s, mem=%s, admin=%s",
                        $mod,
                // Problem with module detected
                DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Problem in module %s detected. ret=%s, locked=%s, hidden=%s, mem=%s, admin=%s",
                        $mod,