Fixes for db/cache counter
authorRoland Häder <roland@mxchange.org>
Tue, 9 Sep 2008 18:55:43 +0000 (18:55 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 9 Sep 2008 18:55:43 +0000 (18:55 +0000)
inc/db/lib-mysql3.php
inc/extensions.php
inc/libs/cache_functions.php
inc/load_extensions.php
inc/modules/admin/overview-inc.php
inc/mysql-manager.php

index 14fa713b84649b96421e2456fbdb454ca93f49d3..182b88895a08b7bd9bfe3253bc6fd6a80beb2ae7 100644 (file)
@@ -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']."<br />\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'])));
index 970e0a71ad57cabdcc4a61aa4d0ba088b98ba384..17dbf7d6d4aaf5c3e1a97527f880e2786c57eba1 100644 (file)
@@ -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}<br />\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)."<br />\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}<br />\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}<br />\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!<br />\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}<br />\n";
 
        // Is the cache written?
        if (!empty($cacheArray['extensions']['ext_version'][$ext_name])) {
                // Load data from cache
+               //* DEBUG: */ echo __FUNCTION__.": CACHE!<br />\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}<br />\n";
        return $ret;
 }
 //
index 619579d5377425ef1ff8926e807723d9098a12ed..711dc5955401120849bdca078293477bcb5edcff 100644 (file)
@@ -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 {
index 88e4a469f22e6b7f85a59edfb104f3f5955b9cfb..9ed4eb42fab97710d8988d397ef2eaccdcb0b1ec 100644 (file)
@@ -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
 
index c55b3909b4fed0d88bb4c6831abfe6ab5c618f20..665d189f4e55e067594d3cae798bfe078b6f7809 100644 (file)
@@ -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
                                }
                        }
                }
index 10b170f64110536234d35705385dbd168e1d78b9..d3a95764bcf77dd162d25ba37e56b149c9d1ffe7 100644 (file)
@@ -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")."<br />\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}<br />\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();