[TASK] Include suggest info into package metadata 15/30015/3
authorMarkus Klein <klein.t3@mfc-linz.at>
Sun, 11 May 2014 21:30:37 +0000 (23:30 +0200)
committerXavier Perseguers <xavier@typo3.org>
Tue, 10 Jun 2014 09:57:10 +0000 (11:57 +0200)
Enhance the Package metadata with information about suggested packages.
This information may be loaded from composer.json or ext_emconf.php.

Resolves: #58701
Releases: 6.2
Change-Id: Ie7415ebe60d2c6164ccc52976a666fe07fd4afe0
Reviewed-on: https://review.typo3.org/30015
Reviewed-by: Thomas Maroschik
Tested-by: Fabien Udriot
Reviewed-by: Fabien Udriot
Reviewed-by: Stefan Neufeind
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
typo3/sysext/core/Classes/Package/Package.php
typo3/sysext/core/Classes/Package/PackageManager.php

index 5b08186..3fcb646 100644 (file)
@@ -180,7 +180,41 @@ class Package extends \TYPO3\Flow\Package\Package implements PackageInterface {
                                        }
                                }
                        }
+                       if (isset($extensionManagerConfiguration['constraints']['suggests']) && is_array($extensionManagerConfiguration['constraints']['conflicts'])) {
+                               $composerManifest->suggest = new \stdClass();
+                               foreach ($extensionManagerConfiguration['constraints']['suggests'] as $conflictingPackageKey => $conflictingPackageVersion) {
+                                       if (!empty($conflictingPackageKey)) {
+                                               $composerManifest->suggest->$conflictingPackageKey = $conflictingPackageVersion;
+                                       } else {
+                                               // TODO: throw meaningful exception or fail silently?
+                                       }
+                               }
+                       }
+               }
+       }
+
+       /**
+        * Returns the package meta data object of this package.
+        *
+        * @return \TYPO3\Flow\Package\MetaData
+        */
+       public function getPackageMetaData() {
+               if ($this->packageMetaData === NULL) {
+                       parent::getPackageMetaData();
+                       $suggestions = $this->getComposerManifest('suggest');
+                       if ($suggestions !== NULL) {
+                               foreach ($suggestions as $suggestion => $version) {
+                                       if ($this->packageRequirementIsComposerPackage($suggestion) === FALSE) {
+                                               // Skip non-package requirements
+                                               continue;
+                                       }
+                                       $packageKey = $this->packageManager->getPackageKeyFromComposerName($suggestion);
+                                       $constraint = new \TYPO3\Flow\Package\MetaData\PackageConstraint(\TYPO3\Flow\Package\MetaDataInterface::CONSTRAINT_TYPE_SUGGESTS, $packageKey);
+                                       $this->packageMetaData->addConstraint($constraint);
+                               }
+                       }
                }
+               return $this->packageMetaData;
        }
 
        /**
index f2ee65c..fb713d1 100644 (file)
@@ -708,6 +708,43 @@ class PackageManager extends \TYPO3\Flow\Package\PackageManager implements \TYPO
        }
 
        /**
+        * Resolves the dependent packages from the meta data of all packages recursively. The
+        * resolved direct or indirect dependencies of each package will put into the package
+        * states configuration array.
+        *
+        * @return void
+        */
+       protected function resolvePackageDependencies() {
+               parent::resolvePackageDependencies();
+               foreach ($this->packages as $packageKey => $package) {
+                       $this->packageStatesConfiguration['packages'][$packageKey]['suggestions'] = $this->getSuggestionArrayForPackage($packageKey);
+               }
+       }
+
+       /**
+        * Returns an array of suggested package keys for the given package.
+        *
+        * @param string $packageKey The package key to fetch the suggestions for
+        * @return array|NULL An array of directly suggested packages
+        */
+       protected function getSuggestionArrayForPackage($packageKey) {
+               if (!isset($this->packages[$packageKey])) {
+                       return NULL;
+               }
+               $suggestedPackageKeys = array();
+               $suggestedPackageConstraints = $this->packages[$packageKey]->getPackageMetaData()->getConstraintsByType(\TYPO3\Flow\Package\MetaDataInterface::CONSTRAINT_TYPE_SUGGESTS);
+               foreach ($suggestedPackageConstraints as $constraint) {
+                       if ($constraint instanceof \TYPO3\Flow\Package\MetaData\PackageConstraint) {
+                               $suggestedPackageKey = $constraint->getValue();
+                               if (isset($this->packages[$suggestedPackageKey])) {
+                                       $suggestedPackageKeys[] = $suggestedPackageKey;
+                               }
+                       }
+               }
+               return array_reverse($suggestedPackageKeys);
+       }
+
+       /**
         * Saves the current content of $this->packageStatesConfiguration to the
         * PackageStates.php file.
         *