/**
  * Extracts a given t3x file and installs the extension
  *
  * @param string $file Path to uploaded file
  * @param bool $overwrite Overwrite existing extension if TRUE
  * @throws ExtensionManagerException
  * @throws DependencyConfigurationNotFoundException
  * @return array
  */
 protected function getExtensionFromT3xFile($file, $overwrite = false)
 {
     $fileContent = file_get_contents($file);
     if (!$fileContent) {
         throw new ExtensionManagerException('File had no or wrong content.', 1342859339);
     }
     $extensionData = $this->terUtility->decodeExchangeData($fileContent);
     if (empty($extensionData['extKey'])) {
         throw new ExtensionManagerException('Decoding the file went wrong. No extension key found', 1342864309);
     }
     $isExtensionAvailable = $this->managementService->isAvailable($extensionData['extKey']);
     if (!$overwrite && $isExtensionAvailable) {
         throw new ExtensionManagerException($this->translate('extensionList.overwritingDisabled'), 1342864310);
     }
     if ($isExtensionAvailable) {
         $this->copyExtensionFolderToTempFolder($extensionData['extKey']);
     }
     $this->removeFromOriginalPath = true;
     $extension = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionData['extKey'], $extensionData['EM_CONF']['version']);
     $this->fileHandlingUtility->unpackExtensionFromExtensionDataArray($extensionData, $extension);
     if (empty($extension) && empty($extensionData['EM_CONF']['constraints']) && !isset($extensionData['FILES']['ext_emconf.php']) && !isset($extensionData['FILES']['/ext_emconf.php'])) {
         throw new DependencyConfigurationNotFoundException('Extension cannot be installed automatically because no dependencies could be found! Please check dependencies manually (on typo3.org) before installing the extension.', 1439587168);
     }
     return $extensionData;
 }
예제 #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;
 }
예제 #3
0
 /**
  * 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);
             }
         } else {
             unset($extensions[$extensionKey]);
         }
     }
     return $extensions;
 }
예제 #4
0
 /**
  * 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;
 }
 /**
  * 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 '';
 }