From 168bc2ed4b0c4e9311d88873f95dba59a58d0975 Mon Sep 17 00:00:00 2001
From: Nicole Cordes <typo3@cordes.co>
Date: Tue, 13 Oct 2015 10:28:45 +0200
Subject: [PATCH] [TASK] Enable EM offline mode when using composer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

If the composer mode is activated, the Extension Manager is set to
offline mode. Downloading extensions from TER and uploading extension
files is disabled.

Resolves: #70605
Releases: master
Change-Id: Idb116d7b4b0b9cafa625116e9caadd4c7c37b922
Reviewed-on: http://review.typo3.org/44025
Reviewed-by: Stephan Großberndt <stephan@grossberndt.de>
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Daniel Maier <dani-maier@gmx.de>
Tested-by: Daniel Maier <dani-maier@gmx.de>
Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org>
Tested-by: Helmut Hummel <helmut.hummel@typo3.org>
---
 .../Classes/Controller/ListController.php      |  3 +++
 .../UploadExtensionFileController.php          | 13 +++++++++++++
 .../Classes/Utility/Connection/TerUtility.php  |  6 +++++-
 .../Resources/Private/Language/locallang.xlf   |  2 +-
 .../Resources/Private/Layouts/Main.html        | 18 +++++++++++-------
 .../Private/Templates/List/Index.html          | 14 +++++++++-----
 .../Resources/Private/Templates/List/Ter.html  | 14 +++++++++-----
 7 files changed, 51 insertions(+), 19 deletions(-)

diff --git a/typo3/sysext/extensionmanager/Classes/Controller/ListController.php b/typo3/sysext/extensionmanager/Classes/Controller/ListController.php
index 9a79afc53d34..570dc08a6ac9 100644
--- a/typo3/sysext/extensionmanager/Classes/Controller/ListController.php
+++ b/typo3/sysext/extensionmanager/Classes/Controller/ListController.php
@@ -102,6 +102,9 @@ class ListController extends AbstractController
         if ($this->configurationUtility->getCurrentConfiguration('extensionmanager')['offlineMode']['value']) {
             $this->settings['offlineMode'] = true;
         }
+        if (Bootstrap::usesComposerClassLoading()) {
+            $this->settings['composerMode'] = true;
+        }
     }
 
     /**
diff --git a/typo3/sysext/extensionmanager/Classes/Controller/UploadExtensionFileController.php b/typo3/sysext/extensionmanager/Classes/Controller/UploadExtensionFileController.php
index 49f73bed962e..fc4ff3c8222b 100644
--- a/typo3/sysext/extensionmanager/Classes/Controller/UploadExtensionFileController.php
+++ b/typo3/sysext/extensionmanager/Classes/Controller/UploadExtensionFileController.php
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Extensionmanager\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Bootstrap;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extensionmanager\Exception\DependencyConfigurationNotFoundException;
@@ -115,6 +116,12 @@ class UploadExtensionFileController extends AbstractController
      */
     public function formAction()
     {
+        if (Bootstrap::usesComposerClassLoading()) {
+            throw new ExtensionManagerException(
+                'Composer mode is active. You are not allowed to upload any extension file.',
+                1444725828821
+            );
+        }
     }
 
     /**
@@ -126,6 +133,12 @@ class UploadExtensionFileController extends AbstractController
      */
     public function extractAction($overwrite = false)
     {
+        if (Bootstrap::usesComposerClassLoading()) {
+            throw new ExtensionManagerException(
+                'Composer mode is active. You are not allowed to upload any extension file.',
+                1444725853814
+            );
+        }
         $file = $_FILES['tx_extensionmanager_tools_extensionmanagerextensionmanager'];
         $fileName = pathinfo($file['name']['extensionFile'], PATHINFO_BASENAME);
         try {
diff --git a/typo3/sysext/extensionmanager/Classes/Utility/Connection/TerUtility.php b/typo3/sysext/extensionmanager/Classes/Utility/Connection/TerUtility.php
index 17db960ddf89..a24913f28625 100644
--- a/typo3/sysext/extensionmanager/Classes/Utility/Connection/TerUtility.php
+++ b/typo3/sysext/extensionmanager/Classes/Utility/Connection/TerUtility.php
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Extensionmanager\Utility\Connection;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Bootstrap;
 use TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException;
 
 /**
@@ -53,7 +54,10 @@ class TerUtility
      */
     public function fetchExtension($extensionKey, $version, $expectedMd5, $mirrorUrl)
     {
-        if (!empty($this->configurationUtility->getCurrentConfiguration('extensionmanager')['offlineMode']['value'])) {
+        if (
+            !empty($this->configurationUtility->getCurrentConfiguration('extensionmanager')['offlineMode']['value'])
+            || Bootstrap::usesComposerClassLoading()
+        ) {
             throw new ExtensionManagerException('Extension Manager is in offline mode. No TER connection available.', 1437078620);
         }
         $extensionPath = \TYPO3\CMS\Core\Utility\GeneralUtility::strtolower($extensionKey);
diff --git a/typo3/sysext/extensionmanager/Resources/Private/Language/locallang.xlf b/typo3/sysext/extensionmanager/Resources/Private/Language/locallang.xlf
index 91da95c25f99..fb92dc2291c9 100644
--- a/typo3/sysext/extensionmanager/Resources/Private/Language/locallang.xlf
+++ b/typo3/sysext/extensionmanager/Resources/Private/Language/locallang.xlf
@@ -16,7 +16,7 @@
 				<source>Composer mode</source>
 			</trans-unit>
 			<trans-unit id="composerMode.message">
-				<source>The system is set to composer mode. Please notice that it might break if you try to add an extension with the Extension Manager. You should rather use composer to add further extensions to your system.</source>
+				<source>The system is set to composer mode. Please notice that it is not possible to add an extension with the Extension Manager. You have to use composer to add further extensions to your system.</source>
 			</trans-unit>
 			<trans-unit id="installedExtensions">
 				<source>Installed Extensions</source>
diff --git a/typo3/sysext/extensionmanager/Resources/Private/Layouts/Main.html b/typo3/sysext/extensionmanager/Resources/Private/Layouts/Main.html
index 29d81058ed35..664d4f1bc861 100644
--- a/typo3/sysext/extensionmanager/Resources/Private/Layouts/Main.html
+++ b/typo3/sysext/extensionmanager/Resources/Private/Layouts/Main.html
@@ -19,14 +19,18 @@
 		<div class="typo3-docheader-functions">
 			<f:be.menus.actionMenu>
 				<f:be.menus.actionMenuItem label="{f:translate(key: 'installedExtensions')}" controller="List" action="index" />
-				<f:if condition="{settings.offlineMode}">
-					<f:else>
-						<f:be.menus.actionMenuItem label="{f:translate(key: 'getExtensions')}" controller="List" action="ter" />
-						<f:be.menus.actionMenuItem label="{f:translate(key: 'distributions')}" controller="List" action="distributions" />
-						<f:if condition="{actionName} == 'showAllVersions'">
-							<f:be.menus.actionMenuItem label="{f:translate(key: 'showAllVersions')} {extensionKey}" controller="List" action="showAllVersions" />
+				<f:if condition="{settings.offlineMode} == 0">
+					<f:then>
+						<f:if condition="{settings.composerMode} == 0">
+							<f:then>
+								<f:be.menus.actionMenuItem label="{f:translate(key: 'getExtensions')}" controller="List" action="ter" />
+								<f:be.menus.actionMenuItem label="{f:translate(key: 'distributions')}" controller="List" action="distributions" />
+								<f:if condition="{actionName} == 'showAllVersions'">
+									<f:be.menus.actionMenuItem label="{f:translate(key: 'showAllVersions')} {extensionKey}" controller="List" action="showAllVersions" />
+								</f:if>
+							</f:then>
 						</f:if>
-					</f:else>
+					</f:then>
 				</f:if>
 			</f:be.menus.actionMenu>
 		</div>
diff --git a/typo3/sysext/extensionmanager/Resources/Private/Templates/List/Index.html b/typo3/sysext/extensionmanager/Resources/Private/Templates/List/Index.html
index dc813703e3da..c1a1ed4f1c3c 100644
--- a/typo3/sysext/extensionmanager/Resources/Private/Templates/List/Index.html
+++ b/typo3/sysext/extensionmanager/Resources/Private/Templates/List/Index.html
@@ -4,11 +4,15 @@
 <f:layout name="main" />
 
 <f:section name="docheader-buttons">
-	<div id="upload-button-wrap">
-		<a href="{f:uri.action(action:'form',controller:'UploadExtensionFile')}" title="{f:translate(key:'extensionList.uploadExtension')}">
-			<core:icon identifier="actions-edit-upload" />
-		</a>
-	</div>
+	<f:if condition="{settings.composerMode} == 0">
+		<f:then>
+			<div id="upload-button-wrap">
+				<a href="{f:uri.action(action:'form',controller:'UploadExtensionFile')}" title="{f:translate(key:'extensionList.uploadExtension')}">
+					<core:icon identifier="actions-edit-upload" />
+				</a>
+			</div>
+		</f:then>
+	</f:if>
 </f:section>
 
 <f:section name="module-headline">
diff --git a/typo3/sysext/extensionmanager/Resources/Private/Templates/List/Ter.html b/typo3/sysext/extensionmanager/Resources/Private/Templates/List/Ter.html
index f7d2f920183f..c3b6d1b8dc1c 100644
--- a/typo3/sysext/extensionmanager/Resources/Private/Templates/List/Ter.html
+++ b/typo3/sysext/extensionmanager/Resources/Private/Templates/List/Ter.html
@@ -3,11 +3,15 @@
 <f:layout name="main"/>
 
 <f:section name="docheader-buttons">
-	<div id="upload-button-wrap">
-		<a href="{f:uri.action(action:'form',controller:'UploadExtensionFile')}" title="{f:translate(key:'extensionList.uploadExtension')}">
-			<core:icon identifier="actions-edit-upload" />
-		</a>
-	</div>
+	<f:if condition="{settings.composerMode} == 0">
+		<f:then>
+			<div id="upload-button-wrap">
+				<a href="{f:uri.action(action:'form',controller:'UploadExtensionFile')}" title="{f:translate(key:'extensionList.uploadExtension')}">
+					<core:icon identifier="actions-edit-upload" />
+				</a>
+			</div>
+		</f:then>
+	</f:if>
 </f:section>
 
 <f:section name="module-headline">
-- 
GitLab