} // 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
}
// 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'])));
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;
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) {
// 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__);
// Run regular SQL command
$result = SQL_QUERY($sql, __FILE__, __LINE__, false);
}
+
+ // An SQL has been executed
+ $sqlRan = true;
} // END - if
} // END - foreach
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();
// 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
// Set cache
$cacheArray['extensions']['ext_version'][$ext_name] = $ret;
}
+
+ // Return result
+ //* DEBUG: */ echo __FUNCTION__.": ret={$ret}<br />\n";
return $ret;
}
//
}
}
- 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 {
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
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
}
}
}
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__);
//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();