]> git.mxchange.org Git - mailer.git/blobdiff - inc/extensions-functions.php
Fixes/rewrites
[mailer.git] / inc / extensions-functions.php
index 9c270f2ff06c669d74a2ee122a4213af8e42f714..5ed3e89ecf1affbae67e9c159e7398f73e29f5db 100644 (file)
@@ -178,7 +178,7 @@ function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $dry_run = fal
        return true;
 }
 
-// Registeres an extension and possible update depencies
+// Registers an extension and possible update dependencies
 function registerExtension ($ext_name, $taskId, $dry_run = false) {
        // Set current extension name
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',task_id=' . $taskId . ',dry_run=' . intval($dry_run) . ' - ENTERED!');
@@ -482,6 +482,7 @@ function doExtensionSqls ($ext_id, $load_mode) {
 // Check wether the given extension is installed
 function isExtensionInstalled ($ext_name) {
        // We don't like empty extension names here
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
        if (empty($ext_name)) {
                // Please fix them all
                debug_report_bug(__FUNCTION__, __LINE__, 'ext_name is empty.');
@@ -493,25 +494,28 @@ function isExtensionInstalled ($ext_name) {
        // Check if there is a cache entry
        if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
                // Use cache built from below queries
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - CACHE!');
                $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
        } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
                // Found!
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - FOUND!');
                $isInstalled = true;
 
                // Count cache hits
                incrementStatsEntry('cache_hits');
        } elseif ((isInstallationPhase())) {
                // Extensions are all inactive/not installed during installation
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - installion phase');
        } else {
                // Look in database
                $ext_id = getExtensionId($ext_name);
 
-               // Log debug message
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension ' . $ext_name . ' has ext_id=' . $ext_id);
-
                // Do we have a record?
                $isInstalled = ($ext_id > 0);
 
+               // Log debug message
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_id=' . $ext_id . ',isInstalled=' . intval($isInstalled));
+
                // Is it installed, then cache the entry
                if ($isInstalled === true) {
                        // Dummy call (get is okay here)
@@ -523,6 +527,7 @@ function isExtensionInstalled ($ext_name) {
        }
 
        // Return status
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isInstalled=' . intval($isInstalled) . ' - EXIT!');
        return $isInstalled;
 }
 
@@ -620,16 +625,16 @@ function getExtensionVersion ($ext_name, $force = false) {
                if (SQL_NUMROWS($result) == 1) {
                        // Load entry
                        $data = SQL_FETCHARRAY($result);
+
+                       // Set cache
+                       $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $data['ext_version'];
                } elseif (isDebugModeEnabled()) {
-                       // Not found, please report all
-                       debug_report_bug(__FUNCTION__, __LINE__, sprintf(": Cannot find extension %s in database!", $ext_name));
+                       // Not found, may happen while an extension is uninstalled
+                       logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot find extension %s in database!", $ext_name));
                }
 
                // Free result
                SQL_FREERESULT($result);
-
-               // Set cache
-               $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $data['ext_version'];
        }
 
        // Extension version should not be invalid
@@ -855,7 +860,7 @@ function getExtensionId ($ext_name) {
                incrementStatsEntry('cache_hits');
        } else {
                // Load from database
-               $result = SQL_QUERY_ESC("SELECT `id` AS ext_id FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
+               $result = SQL_QUERY_ESC("SELECT `id` AS `ext_id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
                        array($ext_name), __FUNCTION__, __LINE__);
 
                // Is the entry there?
@@ -1218,11 +1223,11 @@ function addExtensionDependency ($updateDepends) {
        // Is it not yet added?
        if ((isset($updateDepends, $GLOBALS['ext_running_updates'][getCurrentExtensionName()])) && (in_array($updateDepends, getExtensionUpdatesRunning()))) {
                /*
-                * Double-adding isn't fine, too. This may mean that
-                * addExtensionDependency() was called outside the switch() command in
-                * the extension's file which requires fixing.
+                * Double-adding happens when the extension and an update of the same
+                * extension requires the same other extension again.
                 */
-               debug_report_bug(__FUNCTION__, __LINE__, 'updateDepends=' . $updateDepends . ',extensionMode=' . getExtensionMode() . ',currentExtension=' . getCurrentExtensionName() . ' - CALLED TWICE!');
+               logDebugMessage(__FUNCTION__, __LINE__, 'updateDepends=' . $updateDepends . ',extensionMode=' . getExtensionMode() . ',currentExtension=' . getCurrentExtensionName() . ' - called twice.');
+               return;
        } // END - if
 
        // Add it to the list of extension update depencies map
@@ -1634,28 +1639,29 @@ function removeExtensionFromArray () {
                        } // END - if
                }
        } // END - foreach
+
+       // Remove from other caches as well
+       unset($GLOBALS['ext_is_installed'][$ext_name]);
+       unset($GLOBALS['loaded_extension'][$ext_name]);
 }
 
 // "Getter" for 'extension has a CSS file' (with same name, of course)
 function getExtensionHasCss () {
-       // Default is no CSS
-       $hasCss = 'N';
-
-       // Construct FQFN for check
-       $FQFN = sprintf("%stheme/%s/css/%s.css",
-               getPath(),
-               getCurrentTheme(),
-               getCurrentExtensionName()
-       );
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()])) {
+               // Construct FQFN for check
+               $FQFN = sprintf("%stheme/%s/css/%s.css",
+                       getPath(),
+                       getCurrentTheme(),
+                       getCurrentExtensionName()
+               );
 
-       // Is it there?
-       if (isFileReadable($FQFN)) {
-               // Readable, so it is there...
-               $hasCss = 'Y';
+               // Is it there?
+               $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()] = convertBooleanToYesNo(isFileReadable($FQFN));
        } // END - if
 
        // Return it
-       return $hasCss;
+       return $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()];
 }
 
 // Checks wether the given extension has a language file
@@ -1665,17 +1671,8 @@ function ifExtensionHasLanguageFile ($ext_name) {
                // Count cache hits
                incrementStatsEntry('cache_hits');
        } else {
-               // Not readable is default
-               $readable = 'N';
-
-               // Is the language file readable for this extension?
-               if (isLanguageIncludeReadable($ext_name)) {
-                       // Readable
-                       $readable = 'Y';
-               } // END - if
-
-               // Put it in cache
-               $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = $readable;
+               // Determine it and put it in cache
+               $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = convertBooleanToYesNo(isLanguageIncludeReadable($ext_name));
        }
 
        // Return result
@@ -1731,15 +1728,10 @@ function isExtensionFunctionFileReadable ($ext_name) {
                $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
 
                // Is this include there?
-               if ((isFileReadable($funcsInclude)) && (!isExtensionLibraryLoaded($ext_name)) && (getExtensionMode() == 'test')) {
-                       // Cache it!
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=Y - FOUND!');
-                       $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'Y';
-               } else {
-                       // Cache it!
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=N - NOT FOUND!');
-                       $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'N';
-               }
+               $isIncludeFound = ((isFileReadable($funcsInclude)) && (!isExtensionLibraryLoaded($ext_name)) && (getExtensionMode() == 'test'));
+
+               // And put in cache, converted
+               $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = convertBooleanToYesNo($isIncludeFound);
        }
 
        // Return result