From: Roland Häder Date: Tue, 9 Sep 2008 18:55:43 +0000 (+0000) Subject: Fixes for db/cache counter X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=commitdiff_plain;h=df8cb42d2d579310d1ccfb562b8f30eafdb2618e Fixes for db/cache counter --- diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index 14fa713b84..182b88895a 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -85,12 +85,12 @@ function SQL_QUERY($sql_string, $F, $L) { } // END - if // Count DB hits - if (!isset($_CONFIG['db_hits'])) { + if (!isset($_CONFIG['db_hits_run'])) { // Count in dummy variable - $_CONFIG['db_hits'] = 1; + $_CONFIG['db_hits_run'] = 1; } else { // Count to config array - $_CONFIG['db_hits']++; + $_CONFIG['db_hits_run']++; } // Return the result @@ -179,13 +179,17 @@ function SQL_SELECT_DB($dbName, $link, $F, $L) { } // SQL close link function SQL_CLOSE(&$link, $F, $L) { + global $_CONFIG, $cacheInstance, $cacheArray; + // Is there still a valid link? if (!is_resource($link)) { // Skip double close return false; } // END - if - global $_CONFIG, $cacheInstance, $cacheArray; + // Add new hits + $_CONFIG['db_hits'] += $_CONFIG['db_hits_run']; + //* DEBUG: */ echo "DB=".$_CONFIG['db_hits'].",CACHE=".$_CONFIG['cache_hits']."
\n"; if ((GET_EXT_VERSION("cache") >= "0.0.7") && (isset($_CONFIG['db_hits'])) && (isset($_CONFIG['cache_hits'])) && (is_object($cacheInstance))) { // Update counter for db/cache UPDATE_CONFIG(array("db_hits", "cache_hits"), array(bigintval($_CONFIG['db_hits']), bigintval($_CONFIG['cache_hits']))); diff --git a/inc/extensions.php b/inc/extensions.php index 970e0a71ad..17dbf7d6d4 100644 --- a/inc/extensions.php +++ b/inc/extensions.php @@ -241,6 +241,9 @@ function EXTENSION_RUN_SQLS($id, $EXT_LOAD_MODE) { global $cacheInstance; $SQLs = array(); + // By default no SQL has been executed + $sqlRan = false; + // This shall never do a non-admin user! if (!IS_ADMIN()) return false; @@ -249,9 +252,11 @@ function EXTENSION_RUN_SQLS($id, $EXT_LOAD_MODE) { if (empty($ext_name)) return false; // Load extension in detected mode + //* DEBUG: */ echo __FUNCTION__.":ext_name[{$id}]={$ext_name}
\n"; $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name); if (file_exists($file) && is_readable($file)) require($file); + //* DEBUG: */ echo __FUNCTION__.":SQLs::count=".count($SQLs)."
\n"; if ((is_array($SQLs) && (sizeof($SQLs) > 0))) { // Run SQL commands... foreach ($SQLs as $sql) { @@ -261,6 +266,7 @@ function EXTENSION_RUN_SQLS($id, $EXT_LOAD_MODE) { // Is there still an SQL query? if (!empty($sql)) { // Do we have an "ALTER TABLE" command? + //* DEBUG: */ echo __FUNCTION__.":SQL={$SQL}
\n"; if (substr(strtolower($sql), 0, 11) == "alter table") { // Analyse the alteration command SQL_ALTER_TABLE($sql, __FILE__, __LINE__); @@ -268,6 +274,9 @@ function EXTENSION_RUN_SQLS($id, $EXT_LOAD_MODE) { // Run regular SQL command $result = SQL_QUERY($sql, __FILE__, __LINE__, false); } + + // An SQL has been executed + $sqlRan = true; } // END - if } // END - foreach @@ -278,8 +287,10 @@ function EXTENSION_RUN_SQLS($id, $EXT_LOAD_MODE) { array($id), __FILE__, __LINE__); } // END - if + //* DEBUG: */ echo __FUNCTION__.":mode={$EXT_LOAD_MODE}
\n"; + // Remove cache file(s) if extension is active - if ((EXT_IS_ACTIVE("cache")) || (GET_EXT_VERSION("cache") != "")) { + if (((EXT_IS_ACTIVE("cache")) || (GET_EXT_VERSION("cache") != "")) && (((SQL_AFFECTEDROWS() == 1) && ($EXT_LOAD_MODE == "remove")) || ($sqlRan === true))) { //* DEBUG: */ echo __LINE__.": DESTROY!
\n"; // Remove cache files if ($cacheInstance->cache_file("extensions", true)) $cacheInstance->cache_destroy(); @@ -364,10 +375,12 @@ function GET_EXT_VERSION ($ext_name) { // Extensions are all inactive during installation if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing'))) return ""; + //* DEBUG: */ echo __FUNCTION__.": ext_name={$ext_name}
\n"; // Is the cache written? if (!empty($cacheArray['extensions']['ext_version'][$ext_name])) { // Load data from cache + //* DEBUG: */ echo __FUNCTION__.": CACHE!
\n"; $ret = $cacheArray['extensions']['ext_version'][$ext_name]; // Count cache hits @@ -382,6 +395,9 @@ function GET_EXT_VERSION ($ext_name) { // Set cache $cacheArray['extensions']['ext_version'][$ext_name] = $ret; } + + // Return result + //* DEBUG: */ echo __FUNCTION__.": ret={$ret}
\n"; return $ret; } // diff --git a/inc/libs/cache_functions.php b/inc/libs/cache_functions.php index 619579d537..711dc59554 100644 --- a/inc/libs/cache_functions.php +++ b/inc/libs/cache_functions.php @@ -145,10 +145,25 @@ class mxchange_cache } } - function add_row($data) { + function add_row ($data) { + global $cacheArray; + if (is_resource($this->cache_pointer)) { // Write every array element to cache file - foreach ($data as $k=>$v) { + foreach ($data as $k => $v) { + // Write global cache array for immediate access + if ((substr($k, 0, 4) == "ext_") && (isset($data['ext_name'])) && (isset($data['ext_id']))) { + if ($k != "ext_name") { + $cacheArray['extensions'][$k][$data['ext_name']] = $v; + } else { + $cacheArray['extensions'][$k][$data['ext_id']] = $v; + } + if (($k == "ext_keep") && ($v == "Y")) { + $cacheArray['active_extensions'][$data['ext_name']] = $v; + } // END - if + } // END - if + + // Write cache line to file @fwrite($this->cache_pointer, "\$data['".$k."'][] = \"".$v."\";\n"); } } else { diff --git a/inc/load_extensions.php b/inc/load_extensions.php index 88e4a469f2..9ed4eb42fa 100644 --- a/inc/load_extensions.php +++ b/inc/load_extensions.php @@ -186,7 +186,7 @@ if ((SQL_NUMROWS($res_ext_crt) > 0) && (($cacheMode == "init") || ($cacheMode == while (list($EXT_ID, $name, $lang, $css, $active, $version) = SQL_FETCHROW($res_ext_crt)) { // Get menu entry $menu = "N"; - if (MODULE_HAS_MENU($name)) { + if (MODULE_HAS_MENU($name, true)) { $menu = "Y"; } // END - if diff --git a/inc/modules/admin/overview-inc.php b/inc/modules/admin/overview-inc.php index c55b3909b4..665d189f4e 100644 --- a/inc/modules/admin/overview-inc.php +++ b/inc/modules/admin/overview-inc.php @@ -104,12 +104,17 @@ function OUTPUT_STANDARD_OVERVIEW(&$result_tasks) if (!empty($cacheArray['active_extensions'][$ext])) { // Maybe we want to keept the current extension active? - if (($cacheArray['active_extensions'][$ext] == "Y") && (!EXT_IS_ACTIVE($ext, true, true))) { + if (($cacheArray['active_extensions'][$ext] == "Y") && (!EXT_IS_ACTIVE($ext))) { // Reactivate this extension! $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_extensions SET ext_active='Y' WHERE ext_name='%s' LIMIT 1", array($ext), __FILE__, __LINE__); - EXTENSION_RUN_SQLS(GET_EXT_ID($ext), "activate"); - } + + // Extension has been activated? + if (SQL_AFFECTEDROWS() == 1) { + // Then run all queries + EXTENSION_RUN_SQLS(GET_EXT_ID($ext), "activate"); + } // END - if + } // END - if } } } diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 10b170f641..d3a95764bc 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -1581,26 +1581,25 @@ function GET_WHAT($MOD_CHECK) { return $wht; } // -function MODULE_HAS_MENU($mod) +function MODULE_HAS_MENU($mod, $forceDb = false) { global $cacheArray, $_CONFIG; // All is false by default $ret = false; + //* DEBUG: */ echo __FUNCTION__.":mod={$mod},cache=".GET_EXT_VERSION("cache")."
\n"; if (GET_EXT_VERSION("cache") >= "0.1.2") { - if (isset($cacheArray['modules']['has_menu'][$mod])) - { + // Cache version is okay, so let's check the cache! + if (isset($cacheArray['modules']['has_menu'][$mod])) { // Check module cache and count hit $ret = ($cacheArray['modules']['has_menu'][$mod] == "Y"); $_CONFIG['cache_hits']++; - } - elseif (isset($cacheArray['extensions']['ext_menu'][$mod])) - { + } elseif (isset($cacheArray['extensions']['ext_menu'][$mod])) { // Check cache and count hit $ret = ($cacheArray['extensions']['ext_menu'][$mod] == "Y"); $_CONFIG['cache_hits']++; } - } elseif ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && (!EXT_IS_ACTIVE("cache"))) { + } elseif ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && ((!EXT_IS_ACTIVE("cache")) || ($forceDb === true))) { // Check database for entry $result = SQL_QUERY_ESC("SELECT has_menu FROM "._MYSQL_PREFIX."_mod_reg WHERE module='%s' LIMIT 1", array($mod), __FILE__, __LINE__); @@ -1673,8 +1672,12 @@ function UPDATE_CONFIG ($entries, $values, $updateMode="") { //DEBUG_LOG(__FUNCTION__.":entries={$entries}"); SQL_QUERY("UPDATE "._MYSQL_PREFIX."_config SET ".$entries." WHERE config=0 LIMIT 1", __FILE__, __LINE__); - // Destroy cache - if ((GET_EXT_VERSION("cache") >= "0.1.2") && (SQL_AFFECTEDROWS() == 1)) { + // Get affected rows + $affectedRows = SQL_AFFECTEDROWS(); + //* DEBUG: */ echo __FUNCTION__.":entries={$entries},affectedRows={$affectedRows}
\n"; + + // Destroy cache? + if ((GET_EXT_VERSION("cache") >= "0.1.2") && ($affectedRows == 1)) { global $cacheInstance, $_CONFIG, $CSS; if ($cacheInstance->cache_file("config", true)) $cacheInstance->cache_destroy();