Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
 /**
  * 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 '';
 }