[FEATURE] Add possibility to disable TER download in EM 28/40428/9
authorNicole Cordes <typo3@cordes.co>
Thu, 16 Jul 2015 20:43:01 +0000 (22:43 +0200)
committerXavier Perseguers <xavier@typo3.org>
Fri, 17 Jul 2015 22:46:59 +0000 (00:46 +0200)
Currently it isn't possible to use the extension manager without any
internet connection.

This patch adds an option in the extension manager settings to switch to
an offline mode. This means, that the navigation in EM is limited to the
list view. Download of extensions and distributions is disabled.
Furthermore fetching the extension list from TER isn't possible anymore.

Resolves: #66597
Releases: master
Change-Id: I68477f2289912765aa8ae558bb7df6e550f4f813
Reviewed-on: http://review.typo3.org/40428
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Oliver Eglseder <oliver.eglseder@in2code.de>
Tested-by: Oliver Eglseder <oliver.eglseder@in2code.de>
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
typo3/sysext/extensionmanager/Classes/Controller/ListController.php
typo3/sysext/extensionmanager/Classes/Utility/Connection/TerUtility.php
typo3/sysext/extensionmanager/Classes/Utility/Repository/Helper.php
typo3/sysext/extensionmanager/Resources/Private/Language/locallang.xlf
typo3/sysext/extensionmanager/Resources/Private/Layouts/Main.html
typo3/sysext/extensionmanager/ext_conf_template.txt
typo3/sysext/extensionmanager/ext_localconf.php

index f1c4032..71b6b11 100644 (file)
@@ -50,10 +50,19 @@ class ListController extends AbstractController {
        protected $dependencyUtility;
 
        /**
+        * @var \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility
+        * @inject
+        */
+       protected $configurationUtility;
+
+       /**
         * Add the needed JavaScript files for all actions
         */
        public function initializeAction() {
                $this->pageRenderer->addInlineLanguageLabelFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
+               if ($this->configurationUtility->getCurrentConfiguration('extensionmanager')['offlineMode']['value']) {
+                       $this->settings['offlineMode'] = TRUE;
+               }
        }
 
        /**
index 95ddf4b..fd049f7 100644 (file)
@@ -29,6 +29,12 @@ class TerUtility {
        public $wsdlUrl;
 
        /**
+        * @var \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility
+        * @inject
+        */
+       protected $configurationUtility;
+
+       /**
         * Fetches an extension from the given mirror
         *
         * @param string $extensionKey Extension Key
@@ -39,12 +45,15 @@ class TerUtility {
         * @return array T3X data
         */
        public function fetchExtension($extensionKey, $version, $expectedMd5, $mirrorUrl) {
+               if (!$this->configurationUtility->getCurrentConfiguration('extensionmanager')['offlineMode']['value']) {
+                       throw new ExtensionManagerException('Extension Manager is in offline mode. No TER connection available.', 1437078620);
+               }
                $extensionPath = \TYPO3\CMS\Core\Utility\GeneralUtility::strtolower($extensionKey);
                $mirrorUrl .= $extensionPath[0] . '/' . $extensionPath[1] . '/' . $extensionPath . '_' . $version . '.t3x';
                $t3x = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($mirrorUrl, 0, array(TYPO3_user_agent));
                $md5 = md5($t3x);
                if ($t3x === FALSE) {
-                       throw new ExtensionManagerException(sprintf('The T3X file "%s" could not be fetched. Possible reasons: network problems, allow_url_fopen is off,' . ' cURL is not enabled in Install Tool.', $mirrorUrl), 1334426097);
+                       throw new ExtensionManagerException(sprintf('The T3X file "%s" could not be fetched. Possible reasons: network problems, allow_url_fopen is off, cURL is not enabled in Install Tool.', $mirrorUrl), 1334426097);
                }
                if ($md5 === $expectedMd5) {
                        // Fetch and return:
index 86f76bb..7a7cee5 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Extensionmanager\Utility\Repository;
  */
 
 use TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException;
+use TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility;
 
 /**
  * Central utility class for repository handling.
@@ -62,6 +63,11 @@ class Helper implements \TYPO3\CMS\Core\SingletonInterface {
        protected $extensionRepository;
 
        /**
+        * @var \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility
+        */
+       protected $configurationUtility;
+
+       /**
         * Class constructor.
         *
         * @access public
@@ -72,6 +78,7 @@ class Helper implements \TYPO3\CMS\Core\SingletonInterface {
                /** @var \TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository $repositoryRepository */
                $repositoryRepository = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository::class);
                $this->extensionRepository = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository::class);
+               $this->configurationUtility = $this->objectManager->get(ConfigurationUtility::class);
                /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Repository $repository */
                $repository = $repositoryRepository->findByUid(1);
                if (is_object($repository)) {
@@ -132,6 +139,9 @@ class Helper implements \TYPO3\CMS\Core\SingletonInterface {
         * @throws ExtensionManagerException
         */
        protected function fetchFile($remoteResource, $localResource) {
+               if ($this->configurationUtility->getCurrentConfiguration('extensionmanager')['offlineMode']['value']) {
+                       throw new ExtensionManagerException('Extension Manager is in offline mode. No TER connection available.', 1437078780);
+               }
                if (is_string($remoteResource) && is_string($localResource) && !empty($remoteResource) && !empty($localResource)) {
                        $fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($remoteResource, 0, array(TYPO3_user_agent));
                        if ($fileContent !== FALSE) {
index 543e078..f90e95a 100644 (file)
                        <trans-unit id="config.automaticInstallation">
                                <source>Install extensions automatically after download from TER or file upload</source>
                        </trans-unit>
+                       <trans-unit id="config.offlineMode">
+                               <source>Disable TER connection and hide menu items</source>
+                       </trans-unit>
                </body>
        </file>
 </xliff>
index 71c51ff..13b289e 100644 (file)
                <div class="typo3-docheader-functions">
                        <f:be.menus.actionMenu>
                                <f:be.menus.actionMenuItem label="{f:translate(key: 'installedExtensions')}" controller="List" action="index" />
-                               <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}">
+                                       <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>
+                                       </f:else>
                                </f:if>
                        </f:be.menus.actionMenu>
                </div>
index dc57e1d..f54445a 100644 (file)
@@ -1,2 +1,5 @@
-  # cat=basic/enable; type=boolean; label=LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:config.automaticInstallation
-automaticInstallation = 1
\ No newline at end of file
+# cat=basic/enable; type=boolean; label=LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:config.automaticInstallation
+automaticInstallation = 1
+
+# cat=basic/enable; type=boolean; label=LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:config.offlineMode
+offlineMode = 0
index c08fb7a..31d698e 100644 (file)
@@ -2,12 +2,15 @@
 defined('TYPO3_MODE') or die();
 
 // Register extension list update task
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask::class] = array(
-       'extension' => $_EXTKEY,
-       'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xlf:task.updateExtensionListTask.name',
-       'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xlf:task.updateExtensionListTask.description',
-       'additionalFields' => '',
-);
+$_EXTCONF = unserialize($_EXTCONF);
+if (empty($_EXTCONF['offlineMode'])) {
+       $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask::class] = array(
+               'extension' => $_EXTKEY,
+               'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xlf:task.updateExtensionListTask.name',
+               'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xlf:task.updateExtensionListTask.description',
+               'additionalFields' => '',
+       );
+}
 
 if (TYPO3_MODE === 'BE') {
        $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = \TYPO3\CMS\Extensionmanager\Command\ExtensionCommandController::class;