[BUGFIX] Extension Manager: Use JsonView directly 43/47343/5
authorBenni Mack <benni@typo3.org>
Mon, 21 Mar 2016 17:38:58 +0000 (18:38 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Mon, 21 Mar 2016 23:21:27 +0000 (00:21 +0100)
There are several problems due to the implementation of JsonView
that returns spaces around a JSON returned to the extension manager
that will update the latest extensions.

Resolves: #75214
Releases: master
Change-Id: Iee837da392f62cd1df72c03dca0a03bb763c5790
Reviewed-on: https://review.typo3.org/47343
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/extensionmanager/Classes/Controller/DownloadController.php
typo3/sysext/extensionmanager/Classes/Controller/UpdateFromTerController.php
typo3/sysext/extensionmanager/Resources/Private/Templates/Download/CheckDependencies.json [deleted file]
typo3/sysext/extensionmanager/Resources/Private/Templates/Download/UpdateCommentForUpdatableVersions.json [deleted file]
typo3/sysext/extensionmanager/Resources/Private/Templates/UpdateFromTer/UpdateExtensionListFromTer.json [deleted file]

index f7e1732..07804bd 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Extensionmanager\Controller;
  */
 
 use TYPO3\CMS\Core\Messaging\FlashMessage;
+use TYPO3\CMS\Extbase\Mvc\View\JsonView;
 use TYPO3\CMS\Extensionmanager\Domain\Model\Extension;
 
 /**
@@ -53,6 +54,11 @@ class DownloadController extends AbstractController
     protected $configurationUtility;
 
     /**
+     * @var JsonView
+     */
+    protected $defaultViewObjectName = JsonView::class;
+
+    /**
      * @param \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository
      */
     public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
@@ -101,6 +107,14 @@ class DownloadController extends AbstractController
     }
 
     /**
+     *
+     */
+    protected function initializeInstallFromTerAction()
+    {
+        $this->defaultViewObjectName = \TYPO3\CMS\Fluid\View\TemplateView::class;
+    }
+
+    /**
      * Check extension dependencies
      *
      * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
@@ -112,6 +126,7 @@ class DownloadController extends AbstractController
         $title = '';
         $hasDependencies = false;
         $hasErrors = false;
+        $dependencyTypes = null;
         if ($this->configurationUtility->getCurrentConfiguration('extensionmanager')['automaticInstallation']['value']) {
             $action = 'installFromTer';
             try {
@@ -122,11 +137,15 @@ class DownloadController extends AbstractController
                     foreach ($dependencyTypes as $dependencyType => $dependencies) {
                         $extensions = '';
                         foreach ($dependencies as $extensionKey => $dependency) {
-                            $extensions .= $this->translate('downloadExtension.dependencies.extensionWithVersion', array(
+                            $extensions .= $this->translate(
+                                'downloadExtension.dependencies.extensionWithVersion',
+                                array(
                                     $extensionKey, $dependency->getVersion()
-                                )) . '<br />';
+                                )
+                            ) . '<br />';
                         }
-                        $message .= $this->translate('downloadExtension.dependencies.typeHeadline',
+                        $message .= $this->translate(
+                            'downloadExtension.dependencies.typeHeadline',
                             array(
                                 $this->translate('downloadExtension.dependencyType.' . $dependencyType),
                                 $extensions
@@ -135,7 +154,6 @@ class DownloadController extends AbstractController
                     }
                     $title = $this->translate('downloadExtension.dependencies.resolveAutomatically');
                 }
-                $this->view->assign('dependencies', $dependencyTypes);
             } catch (\Exception $e) {
                 $hasErrors = true;
                 $title = $this->translate('downloadExtension.dependencies.errorTitle');
@@ -145,12 +163,20 @@ class DownloadController extends AbstractController
             // if automatic installation is deactivated, no dependency check is needed (download only)
             $action = 'installExtensionWithoutSystemDependencyCheck';
         }
-        $this->view->assign('extension', $extension)
-            ->assign('action', $action)
-            ->assign('hasDependencies', $hasDependencies)
-            ->assign('hasErrors', $hasErrors)
-            ->assign('message', $message)
-            ->assign('title', $title);
+
+        $url = $this->uriBuilder->uriFor(
+            $action,
+            ['extension' => $extension->getUid(), 'format' => 'json'],
+            'Download'
+        );
+        $this->view->assign('value', [
+            'dependencies' => $dependencyTypes,
+            'url' => $url,
+            'message' => $message,
+            'hasErrors' => $hasErrors,
+            'hasDependencies' => $hasDependencies,
+            'title' => $title
+        ]);
     }
 
     /**
@@ -159,7 +185,7 @@ class DownloadController extends AbstractController
      * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
      * @param string $downloadPath
      */
-    public function installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath)
+    public function installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath = 'Local')
     {
         list($result, $errorMessages) = $this->installFromTer($extension, $downloadPath);
         $emConfiguration = $this->configurationUtility->getCurrentConfiguration('extensionmanager');
@@ -296,9 +322,14 @@ class DownloadController extends AbstractController
             }
             $updateComments[$updatableVersion->getVersion()] = $updatableVersion->getUpdateComment();
         }
-        $this->view->assign('updateComments', $updateComments)
-            ->assign('extensionKey', $extensionKey)
-            ->assign('version', $highestPossibleVersion);
+
+        $this->view->assign('value', [
+            'updateComments' => $updateComments,
+            'url' => $this->uriBuilder->uriFor(
+                'updateExtension',
+                ['extension' => $extensionKey, 'version' => $highestPossibleVersion]
+            )
+        ]);
     }
 
     /**
index c57f772..ad7c3ba 100644 (file)
@@ -13,6 +13,8 @@ namespace TYPO3\CMS\Extensionmanager\Controller;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Extbase\Mvc\View\JsonView;
+use TYPO3\CMS\Lang\LanguageService;
 
 /**
  * Controller for actions relating to update of full extension list from TER
@@ -40,6 +42,11 @@ class UpdateFromTerController extends AbstractController
     protected $extensionRepository;
 
     /**
+     * @var JsonView
+     */
+    protected $defaultViewObjectName = JsonView::class;
+
+    /**
      * @param \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper $repositoryHelper
      */
     public function injectRepositoryHelper(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper $repositoryHelper)
@@ -91,8 +98,32 @@ class UpdateFromTerController extends AbstractController
         }
         /** @var $repository \TYPO3\CMS\Extensionmanager\Domain\Model\Repository */
         $repository = $this->repositoryRepository->findByUid((int)$this->settings['repositoryUid']);
-        $this->view->assign('updated', $updated)
-                ->assign('repository', $repository)
-                ->assign('errorMessage', $errorMessage);
+
+        $timeFormat = $this->getLanguageService()->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:extensionList.updateFromTer.lastUpdate.fullTimeFormat');
+        $lastUpdateTime = $repository->getLastUpdate();
+        if (null === $lastUpdateTime) {
+            $lastUpdatedSince = $this->getLanguageService()->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:extensionList.updateFromTer.never');
+            $lastUpdateTime = date($timeFormat);
+        } else {
+            $lastUpdatedSince = \TYPO3\CMS\Backend\Utility\BackendUtility::calcAge(
+                time() - $lastUpdateTime->format('U'),
+                $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')
+            );
+            $lastUpdateTime = $lastUpdateTime->format($timeFormat);
+        }
+        $this->view->assign('value', [
+            'updated' => $updated,
+            'lastUpdateTime' => $lastUpdateTime,
+            'timeSinceLastUpdate' => $lastUpdatedSince,
+            'errorMessage' => $errorMessage
+        ]);
+    }
+
+    /**
+     * @return LanguageService
+     */
+    protected function getLanguageService()
+    {
+        return $GLOBALS['LANG'];
     }
 }
diff --git a/typo3/sysext/extensionmanager/Resources/Private/Templates/Download/CheckDependencies.json b/typo3/sysext/extensionmanager/Resources/Private/Templates/Download/CheckDependencies.json
deleted file mode 100644 (file)
index ab5e0ed..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-{namespace em=TYPO3\CMS\Extensionmanager\ViewHelpers}
-<em:format.jsonEncode additionalAttributes="{dependencies:dependencies,
-url:'{f:uri.action(action:action, controller:\"Download\", arguments:\"{extension:extension.uid, format:\'json\'}\")}',
-message: '{message}',
-hasErrors: '{hasErrors}',
-hasDependencies: '{hasDependencies}',
-title: '{title}'
-}" />
diff --git a/typo3/sysext/extensionmanager/Resources/Private/Templates/Download/UpdateCommentForUpdatableVersions.json b/typo3/sysext/extensionmanager/Resources/Private/Templates/Download/UpdateCommentForUpdatableVersions.json
deleted file mode 100644 (file)
index 7c7248e..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-{namespace em=TYPO3\CMS\Extensionmanager\ViewHelpers}
-<em:format.jsonEncode additionalAttributes="{updateComments:updateComments,
-url:'{f:uri.action(action:\"updateExtension\", controller:\"Download\", arguments:\"{extension:extensionKey, version:version, format:\'json\'}\")}'
-}" />
diff --git a/typo3/sysext/extensionmanager/Resources/Private/Templates/UpdateFromTer/UpdateExtensionListFromTer.json b/typo3/sysext/extensionmanager/Resources/Private/Templates/UpdateFromTer/UpdateExtensionListFromTer.json
deleted file mode 100644 (file)
index 819d9df..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-{namespace em=TYPO3\CMS\Extensionmanager\ViewHelpers}
-<em:format.jsonEncode
-       additionalAttributes="{
-               updated: updated,
-               lastUpdateTime: '{repository.lastUpdate -> f:format.date(format: \'{f:translate(key: \\\'extensionList.updateFromTer.lastUpdate.fullTimeFormat\\\')}\')}',
-               timeSinceLastUpdate: '{em:timeSinceLastUpdate(lastUpdateTime: repository.lastUpdate)}',
-               errorMessage: errorMessage
-       }"
-/>