Automatic deactivation of installed but deprecated extwensions fixed
[mailer.git] / inc / extensions-functions.php
index 58e0560271cb2ff34fe9bf6268eb01928cd3eaf9..e7e6bce3085bee962e5c0d2925ddb8f408e4b940 100644 (file)
@@ -42,11 +42,12 @@ if (!defined('__SECURITY')) {
 
 // Load the extension and maybe found language and function files.
 function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $dry_run = false) {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_mode=' . $ext_mode . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run));
        // Loading an extension in same mode, but not test/update, twice is not
        // good, so is the extension $ext_name already loaded in mode $ext_mode?
        if ((isset($GLOBALS['loaded_extension'][$ext_name][$ext_mode])) && (!in_array($ext_mode, array('update', 'test')))) {
                // If this happens twice, we need the bug report from you, except for updates/tests
-               debug_report_bug(__FUNCTION__, __LINE__, '() is called twice: ext_name=' . $ext_name . ', ext_mode='. $ext_mode . ',ext_sqls=' . print_r(getExtensionSqls(), true) . ', ext_register_running=' . print_r($GLOBALS['ext_register_running'], true) . ', ext_running_updates=' . print_r($GLOBALS['ext_running_updates'], true));
+               debug_report_bug(__FUNCTION__, __LINE__, __FUNCTION__ . '() is called twice: ext_name=' . $ext_name . ', ext_mode='. $ext_mode . ',ext_sqls=' . print_r(getExtensionSqls(), true) . ', ext_register_running=' . print_r($GLOBALS['ext_register_running'], true) . ', ext_running_updates=' . print_r($GLOBALS['ext_running_updates'], true));
        } // END - if
 
        // Make sure this situation can only happen once
@@ -151,19 +152,16 @@ function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $dry_run = fal
        // Extensions are not always active by default
        setExtensionAlwaysActive('N');
 
-       // Extension update notes
-       // @TODO Do we still need this? setExtensionUpdateNotes('');
-
        // Include the extension file
        loadCurrentExtensionInclude();
 
        // Is this extension deprecated?
-       if ((isExtensionDeprecated()) && (getExtensionMode() != 'test')) {
+       if ((isExtensionDeprecated()) && (!in_array(getExtensionMode(), array('test', 'update', 'deactivate'))) && (isExtensionActive($ext_name))) {
                // Deactivate the extension
                doDeactivateExtension($ext_name);
 
                // Abort here
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension load aborted, ext_name=' . $ext_name);
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension load aborted, ext_name=' . $ext_name . ' - Extension is deprecated.');
                return false;
        } // END - if
 
@@ -181,7 +179,7 @@ function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $dry_run = fal
 // Registers an extension and possible update dependencies
 function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates = false) {
        // Set current extension name
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',task_id=' . $taskId . ',dry_run=' . intval($dry_run) . ' - ENTERED!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',task_id=' . $taskId . ',dry_run=' . intval($dry_run) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - ENTERED!');
        setCurrentExtensionName($ext_name);
 
        // Enable dry-run
@@ -950,7 +948,7 @@ function doDeactivateExtension ($ext_name) {
        // Is the extension installed?
        if (!isExtensionInstalled($ext_name)) {
                // Non-installed extensions cannot be activated
-               debug_report_bug(__FUNCTION__, __LINE__, 'Tried to deactivate non-installed extension ' . $ext_name);
+               debug_report_bug(__FUNCTION__, __LINE__, 'Tried to deactivate non-installed extension ' . $ext_name . ',getExtensionMode()=' . getExtensionMode());
        } // END - if
 
        // Activate the extension
@@ -963,6 +961,9 @@ function doDeactivateExtension ($ext_name) {
        // Create new task (we ignore the task id here)
        createExtensionDeactivationTask($ext_name);
 
+       // Rebuild cache
+       rebuildCache('extension', 'extension');
+
        // Notify the admin
        sendAdminNotification(
                '{--ADMIN_EXTENSION_DEACTIVATED_SUBJECT--}',