[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)
committerXavier Perseguers <xavier@typo3.org>
Mon, 24 Oct 2011 20:38:02 +0000 (22:38 +0200)
In case of an extension having dependencies, suggestions, or conflicts,
the Extension Manager fails with PHP Fatal Errors.

Change-Id: I26e8f12df7df7be3c21a6e7735635e38df70e87b
Resolves: #27836
Releases: 4.6, 4.5
Reviewed-on: http://review.typo3.org/6202
Reviewed-by: Stefan Neufeind
Tested-by: Xavier Perseguers
Reviewed-by: Xavier Perseguers
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/em/classes/connection/class.tx_em_connection_extdirectserver.php
typo3/sysext/em/classes/install/class.tx_em_install.php

index 1df96ad..339a8d9 100644 (file)
@@ -1455,6 +1455,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 ddb4288..0b99f57 100644 (file)
@@ -537,11 +537,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:
@@ -583,10 +592,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:
@@ -632,15 +651,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 . '" />';
                        }