[BUGFIX] Fix dependency handling of EM
authorHelmut Hummel <helmut.hummel@typo3.org>
Sun, 21 Oct 2012 12:28:55 +0000 (14:28 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Mon, 22 Oct 2012 07:16:41 +0000 (09:16 +0200)
Through calculation of dependencies the dependency
utility swapped lowest and highest constraint.

Fix that and also make the dialogue work again
when installing an extension with dependencies.

Fixes: #42245
Releases: 6.0

Change-Id: I1701b966bbb0c9768992e5e8a9a6a88ae4917ce6
Reviewed-on: http://review.typo3.org/15862
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/extensionmanager/Classes/Controller/DownloadController.php
typo3/sysext/extensionmanager/Classes/Domain/Repository/ExtensionRepository.php
typo3/sysext/extensionmanager/Classes/Utility/DependencyUtility.php
typo3/sysext/extensionmanager/Resources/Private/Language/locallang.xlf
typo3/sysext/extensionmanager/Resources/Private/Templates/Download/CheckDependencies.json
typo3/sysext/extensionmanager/Resources/Public/JavaScript/ter.js
typo3/sysext/extensionmanager/Tests/Unit/Utility/DependencyUtilityTest.php

index 500e496..a5c4a89 100644 (file)
@@ -109,20 +109,40 @@ class DownloadController extends \TYPO3\CMS\Extensionmanager\Controller\Abstract
         * @throws \Exception
         */
        public function checkDependenciesAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
-               $dependencyTypes = $this->managementService->getAndResolveDependencies($extension);
                $message = '';
-               if (count($dependencyTypes) > 0) {
-                       // @todo translate and beautify
-                       $message = 'The following dependencies have to be resolved before installation:<br /><br />';
-                       foreach ($dependencyTypes as $dependencyType => $dependencies) {
-                               $message .= '<h3>Extensions marked for ' . $dependencyType . ':</h3>';
-                               foreach ($dependencies as $extensionKey => $dependency) {
-                                       $message .= $extensionKey . '<br />';
+               $title = '';
+               $hasDependiencies = FALSE;
+               $hasErrors = FALSE;
+               try {
+                       $dependencyTypes = $this->managementService->getAndResolveDependencies($extension);
+                       if (count($dependencyTypes) > 0) {
+                               $hasDependiencies = TRUE;
+                               $message = $this->translate('downloadExtension.dependencies.headline');
+                               foreach ($dependencyTypes as $dependencyType => $dependencies) {
+                                       $extensions = '';
+                                       foreach ($dependencies as $extensionKey => $dependency) {
+                                               $extensions .= htmlspecialchars($extensionKey) . '<br />';
+                                       }
+                                       $message .= $this->translate('downloadExtension.dependencies.typeHeadline',
+                                               array(
+                                                       $this->translate('downloadExtension.dependencyType.' . $dependencyType),
+                                                       $extensions
+                                               )
+                                       );
                                }
-                               $message .= 'Shall these dependencies be resolved automatically?';
+                               $title = $this->translate('downloadExtension.dependencies.reloveAutomatically');
                        }
+                       $this->view->assign('dependencies', $dependencyTypes);
+               } catch (\Exception $e) {
+                       $hasErrors = TRUE;
+                       $title = $this->translate('downloadExtension.dependencies.errorTitle');
+                       $message = $e->getMessage();
                }
-               $this->view->assign('dependencies', $dependencyTypes)->assign('extension', $extension)->assign('message', $message);
+               $this->view->assign('extension', $extension)
+                               ->assign('hasDependencies', $hasDependiencies)
+                               ->assign('hasErrors', $hasErrors)
+                               ->assign('message', $message)
+                               ->assign('title', $title);
        }
 
        /**
@@ -203,6 +223,14 @@ class DownloadController extends \TYPO3\CMS\Extensionmanager\Controller\Abstract
                $this->view->assign('updateComments', $updateComments)->assign('extensionKey', $extensionKey);
        }
 
+       /**
+        * @param $key
+        * @return NULL|string
+        */
+       protected function translate($key, $arguments = NULL) {
+               return \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, 'extensionmanager', $arguments);
+       }
+
 }
 
 
index 2114dcc..a1ca137 100644 (file)
@@ -143,9 +143,11 @@ class ExtensionRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
                                        OR
                                        extension_key LIKE ' . $quotedSearchStringForLike . '
                                        OR
+                                       title LIKE ' . $quotedSearchStringForLike . '
+                                       OR
                                        description LIKE ' . $quotedSearchStringForLike . '
                                        OR
-                                       title LIKE ' . $quotedSearchStringForLike . '
+                                       author_name LIKE ' . $quotedSearchStringForLike . '
                                )
                                AND current_version=1 AND review_state >= 0
                                HAVING position > 0';
index 1b827b2..6ba3d4d 100644 (file)
@@ -139,7 +139,13 @@ class DependencyUtility implements \TYPO3\CMS\Core\SingletonInterface {
                foreach ($unserializedDependencies as $dependencyType => $dependencyValues) {
                        foreach ($dependencyValues as $dependency => $versions) {
                                if ($dependencyType && $dependency) {
-                                       list($highest, $lowest) = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionsStringToVersionNumbers($versions);
+                                       $versionNumbers = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionsStringToVersionNumbers($versions);
+                                       $lowest = $versionNumbers[0];
+                                       if (count($versionNumbers) === 2) {
+                                               $highest = $versionNumbers[1];
+                                       } else {
+                                               $highest = '';
+                                       }
                                        /** @var $dependencyObject \TYPO3\CMS\Extensionmanager\Domain\Model\Dependency */
                                        $dependencyObject = $this->objectManager->create('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency');
                                        $dependencyObject->setType($dependencyType);
@@ -287,7 +293,7 @@ class DependencyUtility implements \TYPO3\CMS\Core\SingletonInterface {
                                                $this->managementService->markExtensionForDownload($latestCompatibleExtensionByIntegerVersionDependency);
                                        }
                                } else {
-                                       throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Something went wrong.');
+                                       throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Could not resolve dependency for "' . $dependency->getIdentifier() . '"');
                                }
                        } else {
                                throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('No compatible version found for extension ' . $extensionKey);
index 237a04a..0294ed1 100644 (file)
                        <trans-unit id="extensionList.removalConfirmation.question" xml:space="preserve">
                                <source>Are you sure you want to remove the extension?</source>
                        </trans-unit>
-                       <trans-unit id="extensionList.dependencies.title" xml:space="preserve">
-                               <source>Dependencies</source>
+                       <trans-unit id="downloadExtension.dependencies.headline" xml:space="preserve">
+                               <source>The following dependencies have to be resolved before installation:
+
+
+                               </source>
+                       </trans-unit>
+                       <trans-unit id="downloadExtension.dependencies.typeHeadline" xml:space="preserve">
+                               <source>&lt;h3&gt;Extensions marked for %s:&lt;/h3&gt;
+%s
+
+
+                               </source>
+                       </trans-unit>
+                       <trans-unit id="downloadExtension.dependencies.reloveAutomatically" xml:space="preserve">
+                               <source>Shall these dependencies be resolved automatically?</source>
+                       </trans-unit>
+                       <trans-unit id="downloadExtension.dependencies.errorTitle" xml:space="preserve">
+                               <source>Dependencies could not be resolved</source>
+                       </trans-unit>
+                       <trans-unit id="downloadExtension.dependencies.errorMessage" xml:space="preserve">
+                               <source>The dependencies of the following Extensions could not be resolved:</source>
+                       </trans-unit>
+                       <trans-unit id="downloadExtension.dependencyType.download" xml:space="preserve">
+                               <source>download</source>
+                       </trans-unit>
+                       <trans-unit id="downloadExtension.dependencyType.install" xml:space="preserve">
+                               <source>install</source>
                        </trans-unit>
                        <trans-unit id="extensionList.dependenciesResolveDownloadError.title" xml:space="preserve">
                                <source>Download Error</source>
index 4958c94..2a4742d 100644 (file)
@@ -1,5 +1,8 @@
 {namespace em=TYPO3\CMS\Extensionmanager\ViewHelpers}
 <em:format.jsonEncode additionalAttributes="{dependencies:dependencies,
 url:'{f:uri.action(action:\"installFromTer\", controller:\"Download\", arguments:\"{extension:extension.uid, format:\'json\'}\")}',
-message: '{message}'
+message: '{message}',
+hasErrors: '{hasErrors}',
+hasDependencies: '{hasDependencies}',
+title: '{title}'
 }" />
index 571bccc..aed8654 100644 (file)
@@ -38,36 +38,38 @@ jQuery(document).ready(function() {
 });
 
 function bindDownload() {
-       jQuery('.downloadFromTer form').each(function() {
-               jQuery(this).submit(function(){
-                       var url = jQuery(this).attr('href');
-                               // do this because else form gets send twice - why?
-                       jQuery(this).attr('href', 'javascript:void();');
-                       downloadPath = jQuery(this).find('input.downloadPath:checked').val();
-                       jQuery.ajax({
-                               url: url,
-                               dataType: 'json',
-                               success: getDependencies
-                       });
-                       return false;
+       var installButtons = jQuery('.downloadFromTer form.download input[type=submit]');
+       installButtons.off('click');
+       installButtons.on('click', function(event) {
+               event.preventDefault();
+               var url = jQuery(event.currentTarget.form).attr('href');
+               downloadPath = jQuery(event.currentTarget.form).find('input.downloadPath:checked').val();
+               jQuery.ajax({
+                       url: url,
+                       dataType: 'json',
+                       success: getDependencies
                });
        });
 }
 
 function getDependencies(data) {
-       if (data.dependencies.length) {
+       if (data.hasDependencies) {
                TYPO3.Dialog.QuestionDialog({
-                       title: TYPO3.l10n.localize('extensionList.dependencies.title'),
+                       title: data.title,
                        msg: data.message,
                        url: data.url + '&tx_extensionmanager_tools_extensionmanagerextensionmanager[downloadPath]=' + downloadPath,
                        fn: getResolveDependenciesAndInstallResult
                });
        } else {
-               var button = 'yes';
-               var dialog = new Array();
-               var dummy = '';
-               dialog['url'] = data.url + '&tx_extensionmanager_tools_extensionmanagerextensionmanager[downloadPath]=' + downloadPath;
-               getResolveDependenciesAndInstallResult(button, dummy, dialog)
+               if(data.hasErrors) {
+                       TYPO3.Flashmessage.display(TYPO3.Severity.error, data.title, data.message, 10);
+               } else {
+                       var button = 'yes';
+                       var dialog = [];
+                       var dummy = '';
+                       dialog['url'] = data.url + '&tx_extensionmanager_tools_extensionmanagerextensionmanager[downloadPath]=' + downloadPath;
+                       getResolveDependenciesAndInstallResult(button, dummy, dialog)
+               }
        }
        return false;
 }
index 00af3cc..fe2c673 100644 (file)
@@ -115,7 +115,18 @@ class DependencyUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                                        '',
                                        '4.4.99'
                                )
-                       )
+                       ),
+                       'only one value' => array(
+                               array(
+                                       'depends' => array(
+                                               'typo3' => '4.4.99'
+                                       )
+                               ),
+                               array(
+                                       '4.4.99',
+                                       '',
+                               )
+                       ),
                );
        }
 
@@ -134,8 +145,8 @@ class DependencyUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('setHighestVersion', 'setLowestVersion'));
                $objectManagerMock->expects($this->any())->method('create')->will($this->returnValue($dependencyModelMock));
                $dependencyUtility->_set('objectManager', $objectManagerMock);
-               $dependencyModelMock->expects($this->atLeastOnce())->method('setHighestVersion')->with($returnValue[0]);
-               $dependencyModelMock->expects($this->atLeastOnce())->method('setLowestVersion')->with($returnValue[1]);
+               $dependencyModelMock->expects($this->atLeastOnce())->method('setLowestVersion')->with($this->identicalTo($returnValue[0]));
+               $dependencyModelMock->expects($this->atLeastOnce())->method('setHighestVersion')->with($this->identicalTo($returnValue[1]));
                $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
        }