[BUGFIX] EM: Uploading extensions fails with Fatal Errors
authorSteffen Gebert <steffen.gebert@typo3.org>
Sun, 23 Oct 2011 20:24:36 +0000 (22:24 +0200)
committerSteffen Gebert <steffen.gebert@typo3.org>
Sun, 18 Dec 2011 11:08:29 +0000 (12:08 +0100)
In case of an extension having dependencies, suggestions, or conflicts,
the Extension Manager fails with PHP Fatal Errors.

Change-Id: Iaa04d733f25bf2e3bd7e2c2fcc2e85aa1461975e
Resolves: #27836
Releases: 4.6, 4.5
Reviewed-on: http://review.typo3.org/7111
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Steffen Gebert
Tested-by: Steffen Gebert
typo3/sysext/em/classes/connection/class.tx_em_connection_extdirectserver.php
typo3/sysext/em/classes/install/class.tx_em_install.php

index 0e7e098..dec521a 100644 (file)
@@ -1399,6 +1399,25 @@ class tx_em_Connection_ExtDirectServer {
        }
 
        /**
+        * Disables (uninstalls) an extension
+        *
+        * @param string $extensionKey Extension to uninstall
+        * @return void
+        */
+       public function disableExtension($extensionKey) {
+               /** @var tx_em_Extensions_List */
+               $this->extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
+               /** @var $install tx_em_Install */
+               $install = t3lib_div::makeInstance('tx_em_Install', $this);
+
+               list($installedList,) = $this->extensionList->getInstalledExtensions();
+               $newExtensionList = $this->extensionList->removeExtFromList($extensionKey, $installedList);
+
+               $install->writeNewExtensionList($newExtensionList);
+               tx_em_Tools::refreshGlobalExtList();
+       }
+
+       /**
         * Reset all states for current user
         *
         * @return void
index 2097b1c..120bdc0 100644 (file)
@@ -534,11 +534,20 @@ class tx_em_Install {
                        }
                }
 
-               if (($depError || $depIgnore) && $this->parentObject instanceof SC_mod_tools_em_index) {
-                       $content .= $this->parentObject->doc->section(
-                               $GLOBALS['LANG']->getLL('removeExtFromList_dependency_error'),
-                               implode('<br />', $msg), 0, 1, 2
-                       );
+               if ($depError || $depIgnore) {
+                               // dependent of the context in which we are (AJAX with tx_em_connection_ExtDirectServer or
+                               // old-school rendering with historic pages in shiny ExtJS frames) we have various options
+                       if ($this->parentObject instanceof SC_mod_tools_em_index) {
+                                       // we're in the lucky position to ask the user to uninstall the extension again
+                               $content .= $this->parentObject->doc->section(
+                                       $GLOBALS['LANG']->getLL('removeExtFromList_dependency_error'),
+                                       implode('<br />', $msg), 0, 1, 2
+                               );
+                       } elseif ($this->parentObject instanceof tx_em_Connection_ExtDirectServer) {
+                                       // with ExtDirect, we are in a context, where we cannot ask the user for feedback
+                                       // thus we silently uninstall the newly uploaded extension
+                               $this->parentObject->disableExtension($extKey);
+                       }
                }
 
                // Check conflicts with other extensions:
@@ -580,10 +589,20 @@ class tx_em_Install {
                                }
                        }
                }
+
                if ($conflictError || $conflictIgnore) {
-                       $content .= $this->parentObject->doc->section(
-                               $GLOBALS['LANG']->getLL('checkDependencies_conflict_error'), implode('<br />', $msg), 0, 1, 2
-                       );
+                               // dependent of the context in which we are (AJAX with tx_em_connection_ExtDirectServer or
+                               // old-school rendering with historic pages in shiny ExtJS frames) we have various options
+                       if ($this->parentObject instanceof SC_mod_tools_em_index) {
+                                       // we're in the lucky position to ask the user to uninstall the extension again
+                               $content .= $this->parentObject->doc->section(
+                                       $GLOBALS['LANG']->getLL('checkDependencies_conflict_error'), implode('<br />', $msg), 0, 1, 2
+                               );
+                       } elseif ($this->parentObject instanceof tx_em_Connection_ExtDirectServer) {
+                                       // with ExtDirect, we are in a context, where we cannot ask the user for feedback
+                                       // thus we silently uninstall the newly uploaded extension
+                               $this->parentObject->disableExtension($extKey);
+                       }
                }
 
                // Check suggests on other extensions:
@@ -629,15 +648,26 @@ class tx_em_Install {
                                        $suggestion = true;
                                }
                        }
+
                        if ($suggestion || $suggestionIgnore) {
-                               $content .= $this->parentObject->doc->section(
-                                       sprintf($GLOBALS['LANG']->getLL('checkDependencies_exts_suggested_by_ext'), $extKey),
-                                       implode('<br />', $msg), 0, 1, 1
-                               );
+                                       // dependent of the context in which we are (AJAX with tx_em_connection_ExtDirectServer or
+                                       // old-school rendering with historic pages in shiny ExtJS frames) we have various options
+                               if ($this->parentObject instanceof SC_mod_tools_em_index) {
+                                               // we're in the lucky position to ask the user to uninstall the extension again
+                                       $content .= $this->parentObject->doc->section(
+                                               sprintf($GLOBALS['LANG']->getLL('checkDependencies_exts_suggested_by_ext'), $extKey),
+                                               implode('<br />', $msg), 0, 1, 1
+                                       );
+                               } elseif ($this->parentObject instanceof tx_em_Connection_ExtDirectServer) {
+                                               // with ExtDirect, we are in a context, where we cannot ask the user for feedback
+                                               // thus we silently uninstall the newly uploaded extension
+                                       $this->parentObject->disableExtension($extKey);
+                               }
                        }
                }
 
-               if ($depError || $conflictError || $suggestion) {
+                       // only when we are in old-school HTML output mode (thus not ExtDirect), we can ask for user feedback
+               if (($depError || $conflictError || $suggestion) && ($this->parentObject instanceof SC_mod_tools_em_index)) {
                        foreach ($this->parentObject->CMD as $k => $v) {
                                $content .= '<input type="hidden" name="CMD[' . $k . ']" value="' . $v . '" />';
                        }