From: Roland Häder Date: Wed, 26 Aug 2009 04:14:26 +0000 (+0000) Subject: Many rewrites to get rid of dublicate modreg inserts while ext-cache is registered X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=commitdiff_plain;h=e1d636846bafc8ae71855595a2a2843463025e26 Many rewrites to get rid of dublicate modreg inserts while ext-cache is registered --- diff --git a/inc/extensions.php b/inc/extensions.php index 5f3a704895..93f6fa192a 100644 --- a/inc/extensions.php +++ b/inc/extensions.php @@ -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 - $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? @@ -464,7 +464,7 @@ function EXT_IS_ACTIVE ($ext_name) { } // 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'); @@ -494,7 +494,7 @@ function GET_EXT_VERSION ($ext_name) { 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).""); diff --git a/inc/extensions/ext-cache.php b/inc/extensions/ext-cache.php index 75780f06d2..171752500a 100644 --- a/inc/extensions/ext-cache.php +++ b/inc/extensions/ext-cache.php @@ -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')); -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"); @@ -87,8 +87,8 @@ switch ($EXT_LOAD_MODE) 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ü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; - 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__, "(".__LINE__."): ".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__, "(".__LINE__."): ".getMessage('CACHE_CANNOT_INITIALIZE')); + } // END - if + } // END - if + break; } // Keep this extension always active! diff --git a/inc/filters.php b/inc/filters.php index e8f598c857..433f495809 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -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'); - 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('load_includes', 'loadIncludeLUDES'); + registerFilter('load_includes', 'LOAD_INCLUDES'); // 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])) { - // 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 - 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}"); @@ -400,7 +394,7 @@ function FILTER_SOLVE_TASK ($data) { } // Filter to load include files -function FILTER_loadIncludeLUDES () { +function FILTER_LOAD_INCLUDES () { // Default is $data as inclusion list $data = GET_INC_POOL(); diff --git a/inc/functions.php b/inc/functions.php index 342ab2e3fc..eedc0215f9 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -347,8 +347,11 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) { $ret = $tmpl_file; } - // Add surrounding HTML comments to help finding bugs faster - $ret = "\n" . $ret . "\n"; + // Normal HTML output? + if ($GLOBALS['output_mode'] == 0) { + // Add surrounding HTML comments to help finding bugs faster + $ret = "\n" . $ret . "\n"; + } // END - if } elseif ((IS_ADMIN()) || ((isInstalling()) && (!isInstalled()))) { // Only admins shall see this warning or when installation mode is active $ret = "
{--TEMPLATE_404--}
@@ -2482,9 +2485,12 @@ function getActualVersion ($type = 'Revision') { } // 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 - $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']); diff --git a/inc/libs/cache_functions.php b/inc/libs/cache_functions.php index ca0aee8331..17910c97cd 100644 --- a/inc/libs/cache_functions.php +++ b/inc/libs/cache_functions.php @@ -226,13 +226,13 @@ class CacheSystem { } // Destroy an existing cache file - function destroyCacheFile ($removeArray = false) { + function destroyCacheFile ($removeArray = false, $force = false) { // Only run in regular output mode - if (getOutputMode() != 0) { + if ((getOutputMode() != 0) && ($force === false)) { // 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 diff --git a/inc/load_extensions.php b/inc/load_extensions.php index f8589b66d2..731bbd4bf9 100644 --- a/inc/load_extensions.php +++ b/inc/load_extensions.php @@ -287,9 +287,12 @@ if ((SQL_NUMROWS($res_ext_crt) > 0) && ((($GLOBALS['cache_mode'] == 'init') && ( // 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(); +} 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 @@ -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", - array($del_ext), __FILE__, __LINE__); + array($del_ext), __FILE__, __LINE__); // 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 diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 7137be73f1..b9eee9d477 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -208,16 +208,16 @@ function checkModulePermissions ($mod) { } 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? - 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 @@ -250,7 +250,10 @@ function checkModulePermissions ($mod) { // 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,