]> git.mxchange.org Git - mailer.git/blobdiff - inc/extensions-functions.php
Fix for 'Cache not found but ext-cache is active'
[mailer.git] / inc / extensions-functions.php
index 710d154398739c4a7650de14256415e063ae11fd..5bcdf37ee2920623867fd033ca2bc0b8d970ae3a 100644 (file)
@@ -239,7 +239,7 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
 
                                // Extension version set? If empty the extension is not registered
                                if (empty($ext_ver)) {
-                                       // Extension not registered so far so first load task's ID...
+                                       // Extension not registered so far so first load task's id...
                                        $task = determineExtensionTaskId($ext_update);
 
                                        // Entry found?
@@ -325,6 +325,9 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
                                // Remove all SQL commands
                                unsetSqls();
 
+                               // Mark it as installed
+                               $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = true;
+
                                // In normal mode return a true on success
                                $ret = true;
                        } elseif (getExtensionDryRun() === true) {
@@ -434,7 +437,10 @@ function isExtensionInstalled ($ext_name) {
        $isInstalled = false;
 
        // Check if there is a cache entry
-       if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
+       if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
+               // Use cache built from below queries
+               $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
+       } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
                // Found!
                $isInstalled = true;
 
@@ -444,20 +450,19 @@ function isExtensionInstalled ($ext_name) {
                // Extensions are all inactive/not installed during installation
        } else {
                // Look in database
-               $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
-                       array($ext_name), __FILE__, __LINE__);
+               $ext_id = getExtensionId($ext_name);
 
                // Do we have a record?
-               $isInstalled = (SQL_NUMROWS($result) == 1);
+               $isInstalled = ($ext_id > 0);
 
                // Is it installed, then cache the entry
                if ($isInstalled === true) {
-                       // Dummy call
+                       // Dummy call (get is okay here)
                        getExtensionId($ext_name, true);
                } // END - if
 
-               // Free result
-               SQL_FREERESULT($result);
+               // Remember the status
+               $GLOBALS['ext_is_installed'][$ext_name] = $isInstalled;
        }
 
        // Return status
@@ -760,17 +765,18 @@ function getExtensionName ($ext_id) {
 }
 
 // Get extension id from name
-function getExtensionId ($ext_name, $forceDb = false) {
-       // Init ID number
+function getExtensionId ($ext_name) {
+       // Init id number
        $ret = 0;
 
+       // Do we have cache?
        if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
                // Load from cache
                $ret = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
 
                // Count cache hits
                incrementStatsEntry('cache_hits');
-       } elseif (($forceDb === true) || (!isExtensionActive('cache'))) {
+       } else {
                // Load from database
                $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
                        array($ext_name), __FUNCTION__, __LINE__);
@@ -779,19 +785,14 @@ function getExtensionId ($ext_name, $forceDb = false) {
                if (SQL_NUMROWS($result) == 1) {
                        // Get the extension's id from database
                        list($ret) = SQL_FETCHROW($result);
-
-                       // Cache it
-                       $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $ret;
                } // END - if
 
                // Free result
                SQL_FREERESULT($result);
-       }
 
-       if ($ret == 0) {
-               // We should fix these all!
-               debug_report_bug(__FUNCTION__ . ': Invalid extension name found. ext_name=' . $ext_name);
-       } // END - if
+               // Cache it
+               $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $ret;
+       }
 
        // Return value
        return $ret;
@@ -1000,7 +1001,7 @@ function determineExtensionTaskId ($ext_name) {
 
        // Entry found?
        if (SQL_NUMROWS($result) == 1) {
-               // Task found so load task's ID and register extension...
+               // Task found so load task's id and register extension...
                list($task_id) = SQL_FETCHROW($result);
        } // END - if
 
@@ -1022,7 +1023,7 @@ function determineTaskIdBySubject ($subject) {
 
        // Entry found?
        if (SQL_NUMROWS($result) == 1) {
-               // Task found so load task's ID and register extension...
+               // Task found so load task's id and register extension...
                list($task_id) = SQL_FETCHROW($result);
        } // END - if