Esempio n. 1
0
 /**
  * Main controlling function for checking dependencies
  * Dependency check is done in the following way:
  * - installed extension in matching version ? - return true
  * - available extension in matching version ? - mark for installation
  * - remote (TER) extension in matching version? - mark for download
  *
  * @todo handle exceptions / markForUpload
  * @param Dependency $dependency
  * @throws Exception\MissingVersionDependencyException
  * @return bool
  */
 protected function checkExtensionDependency(Dependency $dependency)
 {
     $extensionKey = $dependency->getIdentifier();
     $extensionIsLoaded = $this->isDependentExtensionLoaded($extensionKey);
     if ($extensionIsLoaded === true) {
         $isLoadedVersionCompatible = $this->isLoadedVersionCompatible($dependency);
         if ($isLoadedVersionCompatible === true || $this->skipDependencyCheck) {
             return true;
         }
         $extension = $this->listUtility->getExtension($extensionKey);
         $loadedVersion = $extension->getPackageMetaData()->getVersion();
         if (version_compare($loadedVersion, $dependency->getHighestVersion()) === -1) {
             try {
                 $this->getExtensionFromRepository($extensionKey, $dependency);
             } catch (Exception\UnresolvedDependencyException $e) {
                 throw new Exception\MissingVersionDependencyException('The extension ' . $extensionKey . ' is installed in version ' . $loadedVersion . ' but needed in version ' . $dependency->getLowestVersion() . ' - ' . $dependency->getHighestVersion() . ' and could not be fetched from TER', 1396302624);
             }
         } else {
             throw new Exception\MissingVersionDependencyException('The extension ' . $extensionKey . ' is installed in version ' . $loadedVersion . ' but needed in version ' . $dependency->getLowestVersion() . ' - ' . $dependency->getHighestVersion(), 1430561927);
         }
     } else {
         $extensionIsAvailable = $this->isDependentExtensionAvailable($extensionKey);
         if ($extensionIsAvailable === true) {
             $isAvailableVersionCompatible = $this->isAvailableVersionCompatible($dependency);
             if ($isAvailableVersionCompatible) {
                 $unresolvedDependencyErrors = $this->dependencyErrors;
                 $this->managementService->markExtensionForInstallation($extensionKey);
                 $this->dependencyErrors = array_merge($unresolvedDependencyErrors, $this->dependencyErrors);
             } else {
                 $extension = $this->listUtility->getExtension($extensionKey);
                 $availableVersion = $extension->getPackageMetaData()->getVersion();
                 if (version_compare($availableVersion, $dependency->getHighestVersion()) === -1) {
                     try {
                         $this->getExtensionFromRepository($extensionKey, $dependency);
                     } catch (Exception\MissingExtensionDependencyException $e) {
                         if (!$this->skipDependencyCheck) {
                             throw new Exception\MissingVersionDependencyException('The extension ' . $extensionKey . ' is available in version ' . $availableVersion . ' but is needed in version ' . $dependency->getLowestVersion() . ' - ' . $dependency->getHighestVersion() . ' and could not be fetched from TER', 1430560390);
                         }
                     }
                 } else {
                     if (!$this->skipDependencyCheck) {
                         throw new Exception\MissingVersionDependencyException('The extension ' . $extensionKey . ' is available in version ' . $availableVersion . ' but is needed in version ' . $dependency->getLowestVersion() . ' - ' . $dependency->getHighestVersion(), 1430562374);
                     }
                     // Dependency check is skipped and the local version has to be installed
                     $this->managementService->markExtensionForInstallation($extensionKey);
                 }
             }
         } else {
             $unresolvedDependencyErrors = $this->dependencyErrors;
             $this->getExtensionFromRepository($extensionKey, $dependency);
             $this->dependencyErrors = array_merge($unresolvedDependencyErrors, $this->dependencyErrors);
         }
     }
     return false;
 }