]> git.mxchange.org Git - mailer.git/blobdiff - inc/extensions.php
Fix added for extension update with always active extensions, thanks to profi-concept
[mailer.git] / inc / extensions.php
index 64e4c486993fe001850a65d2f25707c8557f0437..722fa681cbe2cecdc501c63d0e8a414005f22ea3 100644 (file)
@@ -89,20 +89,25 @@ function EXTENSION_REGISTER ($ext_name, $id, $dry_run=false)
                        $SQLs  = array();
                        $test  = false;
 
-                       // Backup language as well
-                       $LANG_BCK = $EXT_LANG_PREFIX;
-                       $EXT_ALWAYS_ACTIVE = "N";
-
                        // Load required extension also in update mode
                        $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $EXT_UPDATE_DEPENDS);
 
                        // Check for required file
                        if (FILE_READABLE($file)) {
-                               // File exists so let's load it
+                               // Bacup version number
                                $VER_BACKUP = $EXT_VERSION;
+
+                               // Backup language as well
+                               $LANG_BCK = $EXT_LANG_PREFIX;
+
+                               // Save the Parrent $EXT_ALWAYS_ACTIVE for later!
+                               $EXT_ALWAYS_ACTIVE_PARRENT = $EXT_ALWAYS_ACTIVE;
+
+                               // Set EXT_ALWAYS_ACTIVE for update
                                $EXT_ALWAYS_ACTIVE = "N";
+
+                               // File exists so let's load it
                                require($file);
-                               $EXT_VERSION = $VER_BACKUP;
 
                                // If versions mismatch update extension first
                                $ext_ver = GET_EXT_VERSION($EXT_UPDATE_DEPENDS);
@@ -134,6 +139,15 @@ function EXTENSION_REGISTER ($ext_name, $id, $dry_run=false)
                                        // Nothing to register / update before...
                                        $test = true;
                                }
+
+                               // Restore version number
+                               $EXT_VERSION = $VER_BACKUP;
+
+                               // Restore language back
+                               $EXT_LANG_PREFIX = $LANG_BCK;
+
+                               // Restore $EXT_ALWAYS_ACTIVE with the value from parrent
+                               $EXT_ALWAYS_ACTIVE = $EXT_ALWAYS_ACTIVE_PARRENT;
                        } else {
                                // Required file for update does not exists!
                                $test = true;
@@ -142,7 +156,6 @@ function EXTENSION_REGISTER ($ext_name, $id, $dry_run=false)
 
                        // Finally restore previous SQLs
                        $SQLs = $SQLs2; unset($SQLs2);
-                       $EXT_LANG_PREFIX = $LANG_BCK;
                } else {
                        // Does not depend on an other extension
                        $test = true;
@@ -301,18 +314,6 @@ function EXTENSION_RUN_SQLS($id, $EXT_LOAD_MODE) {
 
                //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):mode={$EXT_LOAD_MODE}<br />\n";
 
-               // Remove cache file(s) if extension is active
-               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();
-                       if ($cacheInstance->cache_file("mod_reg", true))    $cacheInstance->cache_destroy();
-                       if ($cacheInstance->cache_file("config", true))     $cacheInstance->cache_destroy();
-
-                       // @TODO This causes the whole (!) menu cache being purged
-                       CACHE_PURGE_ADMIN_MENU();
-               } // END - if
-
                // Is this the sql_patches?
                //* DEBUG: */ echo __LINE__.": {$id}/{$ext_name}/{$EXT_LOAD_MODE}<br />\n";
                if (($ext_name == "sql_patches") && (($EXT_LOAD_MODE == "register") || ($EXT_LOAD_MODE == "remove"))) {
@@ -321,6 +322,18 @@ function EXTENSION_RUN_SQLS($id, $EXT_LOAD_MODE) {
                        LOAD_URL("modules.php?module=admin&logout=1&".$EXT_LOAD_MODE."=sql_patches");
                } // END - if
        } // END - if
+
+       // Remove cache file(s) if extension is active
+       if (((EXT_IS_ACTIVE("cache")) || (GET_EXT_VERSION("cache") != "")) && (((SQL_AFFECTEDROWS() == 1)) || ($sqlRan === true) || ($EXT_LOAD_MODE == "activate") || ($EXT_LOAD_MODE == "deactivate"))) {
+               //* DEBUG: */ echo __LINE__.": DESTROY!<br />\n";
+               // Remove cache files
+               if ($cacheInstance->cache_file("extensions", true)) $cacheInstance->cache_destroy();
+               if ($cacheInstance->cache_file("mod_reg", true))    $cacheInstance->cache_destroy();
+               if ($cacheInstance->cache_file("config", true))     $cacheInstance->cache_destroy();
+
+               // @TODO This causes the whole (!) menu cache being purged
+               CACHE_PURGE_ADMIN_MENU();
+       } // END - if
 }
 // Check if given extension is active
 function EXT_IS_ACTIVE ($ext_name) {
@@ -349,11 +362,16 @@ function EXT_IS_ACTIVE ($ext_name) {
                        // Extension was not found!
                        return false;
                }
+
+               // Load entry
                list($active) = SQL_FETCHROW($result);
-               //* DEBUG: */ echo $ext_name."[DB]: {$active}<br />\n";
+
+               // Free result
                SQL_FREERESULT($result);
 
+
                // Write cache array
+               //* DEBUG: */ echo $ext_name."[DB]: {$active}<br />\n";
                $cacheArray['extensions']['ext_active'][$ext_name] = $active;
        } else {
                // Extension not active!
@@ -362,7 +380,7 @@ function EXT_IS_ACTIVE ($ext_name) {
        }
 
        // Debug message
-       //DEBUG_LOG(__FUNCTION__.": ext_name={$ext_name},active={$active}");
+       //DEBUG_LOG(__FUNCTION__, __LINE__, " ext_name={$ext_name},active={$active}");
 
        // Is this extension activated? (For admins we always have active extensions...)
        return ($active == "Y");
@@ -578,7 +596,7 @@ function GET_EXT_NAME ($id) {
                $ret = $cacheArray['extensions']['ext_name'][$id];
 
                // Count cache hits
-               $_CONFIG['cache_hits']++;
+               if (isset($_CONFIG['cache_hits'])) { $_CONFIG['cache_hits']++; } else { $_CONFIG['cache_hits'] = 1; }
        } elseif (!EXT_IS_ACTIVE("cache")) {
                // Load from database
                $result = SQL_QUERY_ESC("SELECT ext_name FROM "._MYSQL_PREFIX."_extensions WHERE id=%s LIMIT 1",
@@ -597,7 +615,7 @@ function GET_EXT_ID($name) {
                $ret = $cacheArray['extensions']['ext_id'][$name];
 
                // Count cache hits
-               $_CONFIG['cache_hits']++;
+               if (isset($_CONFIG['cache_hits'])) { $_CONFIG['cache_hits']++; } else { $_CONFIG['cache_hits'] = 1; }
        } elseif (!EXT_IS_ACTIVE("cache")) {
                // Load from database
                $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",