/** * Update an extension. Makes no sanity check but directly searches highest * available version from TER and updates. Update check is done by the list * already. This method should only be called if we are sure that there is * an update. * * @return void */ protected function updateExtensionAction() { $extensionKey = $this->request->getArgument('extension'); /** @var $highestTerVersionExtension \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */ $highestTerVersionExtension = $this->extensionRepository->findHighestAvailableVersion($extensionKey); $this->prepareExtensionForImport($highestTerVersionExtension); $result = $this->managementService->resolveDependenciesAndInstall($highestTerVersionExtension); $this->view->assign('result', $result)->assign('extension', $highestTerVersionExtension); }
/** * Checks if an update for an extension is available * * @internal * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionData * @return boolean */ public function isUpdateAvailable(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionData) { // Only check for update for TER extensions $version = $extensionData->getIntegerVersion(); /** @var $highestTerVersionExtension \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */ $highestTerVersionExtension = $this->extensionRepository->findHighestAvailableVersion($extensionData->getExtensionKey()); if ($highestTerVersionExtension instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension) { $highestVersion = $highestTerVersionExtension->getIntegerVersion(); if ($highestVersion > $version) { return TRUE; } } return FALSE; }
/** * Update an extension. Makes no sanity check but directly searches highest * available version from TER and updates. Update check is done by the list * already. This method should only be called if we are sure that there is * an update. * * @return void */ protected function updateExtensionAction() { $hasErrors = FALSE; $errorMessage = ''; $extensionKey = $this->request->getArgument('extension'); $highestTerVersionExtension = $this->extensionRepository->findHighestAvailableVersion($extensionKey); try { $this->managementService->downloadMainExtension($highestTerVersionExtension); } catch (\Exception $e) { $hasErrors = TRUE; $errorMessage = $e->getMessage(); } $this->view->assign('extension', $highestTerVersionExtension)->assign('hasErrors', $hasErrors)->assign('errorMessage', $errorMessage); }
/** * Fetch an extension from TER. * * @param string $extensionKey The extension key * @param string $location Where to import the extension. System = typo3/sysext, Global = typo3/ext, Local = typo3conf/ext * @param bool $overwrite Overwrite the extension if it already exists * @param int $mirror The mirror to fetch the extension from * * @throws \RuntimeException * @throws \InvalidArgumentException * @return array */ public function fetchExtension($extensionKey, $version = '', $location = 'Local', $overwrite = FALSE, $mirror = -1) { if (!is_numeric($mirror)) { throw new InvalidArgumentException('Option --mirror must be a number. Run the command extensionapi:listmirrors to get the list of all available repositories'); } if ($version === '') { $extension = $this->extensionRepository->findHighestAvailableVersion($extensionKey); if ($extension === NULL) { throw new InvalidArgumentException(sprintf('Extension "%s" was not found on TER', $extensionKey)); } } else { $extension = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $version); if ($extension === NULL) { throw new InvalidArgumentException(sprintf('Version %s of extension "%s" does not exist', $version, $extensionKey)); } } if (!$overwrite) { $comingExtPath = $this->fileHandlingUtility->getExtensionDir($extensionKey, $location); if (@is_dir($comingExtPath)) { throw new InvalidArgumentException(sprintf('Extension "%s" already exists at "%s"!', $extensionKey, $comingExtPath)); } } $mirrors = $this->repositoryHelper->getMirrors(); if ($mirrors === NULL) { throw new RuntimeException('No mirrors found!'); } if ($mirror === -1) { $mirrors->setSelect(); } elseif ($mirror > 0 && $mirror <= count($mirrors->getMirrors())) { $mirrors->setSelect($mirror); } else { throw new InvalidArgumentException(sprintf('Mirror "%s" does not exist', $mirror)); } /** * @var \TYPO3\CMS\Extensionmanager\Utility\DownloadUtility $downloadUtility */ $downloadUtility = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility'); $downloadUtility->setDownloadPath($location); $this->extensionManagementService->downloadMainExtension($extension); $return = array(); $extensionDir = $this->fileHandlingUtility->getExtensionDir($extensionKey, $location); if (is_dir($extensionDir)) { $return['main']['extKey'] = $extension->getExtensionKey(); $return['main']['version'] = $extension->getVersion(); } else { throw new RuntimeException(sprintf('Extension "%s" version %s could not installed!', $extensionKey, $extension->getVersion())); } return $return; }
/** * Adds the information from the emconf array to the extension information * * @param array $extensions * @return array */ public function enrichExtensionsWithEmConfAndTerInformation(array $extensions) { foreach ($extensions as $extensionKey => $properties) { $emconf = $this->emConfUtility->includeEmConf($properties); if ($emconf) { $extensions[$extensionKey] = array_merge($emconf, $properties); $terObject = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $extensions[$extensionKey]['version']); if ($terObject instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension) { $extensions[$extensionKey]['terObject'] = $terObject; $extensions[$extensionKey]['updateAvailable'] = $this->installUtility->isUpdateAvailable($terObject); $extensions[$extensionKey]['updateToVersion'] = $this->extensionRepository->findHighestAvailableVersion($extensionKey); } } else { unset($extensions[$extensionKey]); } } return $extensions; }
/** * Tries to find given extension with given version in TER data. * If extension is found but not the given version, we return TER data from highest version with version data set to * given one. * * @param string $extensionKey Key of the extension * @param string $version String representation of version number * @return Extension|NULL Extension TER object or NULL if nothing found */ protected function getExtensionTerData($extensionKey, $version) { $terObject = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $version); if (!$terObject instanceof Extension) { // Version unknown in TER data, try to find extension $terObject = $this->extensionRepository->findHighestAvailableVersion($extensionKey); if ($terObject instanceof Extension) { // Found in TER now, set version information to the known ones, so we can look if there is a newer one // Use a cloned object, otherwise wrong information is stored in persistenceManager $terObject = clone $terObject; $terObject->setVersion($version); $terObject->setIntegerVersion(VersionNumberUtility::convertVersionNumberToInteger($terObject->getVersion())); } else { $terObject = NULL; } } return $terObject; }
/** * Checks if an update for an extension is available * * @internal * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionData * @return boolean */ public function isUpdateAvailable(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionData) { $isUpdateAvailable = FALSE; // Only check for update for TER extensions $version = $extensionData->getIntegerVersion(); /** @var $highestTerVersionExtension \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */ $highestTerVersionExtension = $this->extensionRepository->findHighestAvailableVersion($extensionData->getExtensionKey()); if ($highestTerVersionExtension instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension) { $highestVersion = $highestTerVersionExtension->getIntegerVersion(); if ($highestVersion > $version) { $this->dependencyUtility->checkDependencies($highestTerVersionExtension); if (!$this->dependencyUtility->hasDependencyErrors()) { $isUpdateAvailable = TRUE; } } } return $isUpdateAvailable; }
/** * Update an extension. Makes no sanity check but directly searches highest * available version from TER and updates. Update check is done by the list * already. This method should only be called if we are sure that there is * an update. * * @return string */ protected function updateExtensionAction() { $extensionKey = $this->request->getArgument('extension'); $version = $this->request->getArgument('version'); $extension = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $version); if (!$extension instanceof Extension) { $extension = $this->extensionRepository->findHighestAvailableVersion($extensionKey); } $installedExtensions = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getLoadedExtensionListArray(); try { if (in_array($extensionKey, $installedExtensions, TRUE)) { // To resolve new dependencies the extension is installed again $this->managementService->installExtension($extension); } else { $this->managementService->downloadMainExtension($extension); } $this->addFlashMessage(htmlspecialchars($this->translate('extensionList.updateFlashMessage.body', array($extensionKey))), $this->translate('extensionList.updateFlashMessage.title')); } catch (\Exception $e) { $this->addFlashMessage(htmlspecialchars($e->getMessage()), '', FlashMessage::ERROR); } return ''; }