/** * Add the needed JavaScript files for all actions */ public function initializeAction() { $this->pageRenderer->addInlineLanguageLabelFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf'); if ($this->configurationUtility->getCurrentConfiguration('extensionmanager')['offlineMode']['value']) { $this->settings['offlineMode'] = true; } }
/** * Extract an uploaded file and install the matching extension * * @param bool $overwrite Overwrite existing extension if TRUE * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException * @return void */ public function extractAction($overwrite = FALSE) { $file = $_FILES['tx_extensionmanager_tools_extensionmanagerextensionmanager']; $fileName = pathinfo($file['name']['extensionFile'], PATHINFO_BASENAME); try { // If the file name isn't valid an error will be thrown $this->checkFileName($fileName); if (!empty($file['tmp_name']['extensionFile'])) { $tempFile = GeneralUtility::upload_to_tempfile($file['tmp_name']['extensionFile']); } else { throw new ExtensionManagerException('Creating temporary file failed. Check your upload_max_filesize and post_max_size limits.', 1342864339); } $extensionData = $this->extractExtensionFromFile($tempFile, $fileName, $overwrite); $emConfiguration = $this->configurationUtility->getCurrentConfiguration('extensionmanager'); if (!$emConfiguration['automaticInstallation']['value']) { $this->addFlashMessage($this->translate('extensionList.uploadFlashMessage.message', array($extensionData['extKey'])), $this->translate('extensionList.uploadFlashMessage.title'), FlashMessage::OK); } else { if ($this->activateExtension($extensionData['extKey'])) { $this->addFlashMessage($this->translate('extensionList.installedFlashMessage.message', array($extensionData['extKey'])), '', FlashMessage::OK); } else { $this->redirect('unresolvedDependencies', 'List', NULL, array('extensionKey' => $extensionData['extKey'])); } } } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $exception) { throw $exception; } catch (\Exception $exception) { $this->removeExtensionAndRestoreFromBackup($fileName); $this->addFlashMessage($exception->getMessage(), '', FlashMessage::ERROR); } $this->redirect('index', 'List', NULL, array(self::TRIGGER_RefreshModuleMenu => TRUE)); }
/** * Fetches an extension from the given mirror * * @param string $extensionKey Extension Key * @param string $version Version to install * @param string $expectedMd5 Expected MD5 hash of extension file * @param string $mirrorUrl URL of mirror to use * @throws ExtensionManagerException * @return array T3X data */ public function fetchExtension($extensionKey, $version, $expectedMd5, $mirrorUrl) { if (!empty($this->configurationUtility->getCurrentConfiguration('extensionmanager')['offlineMode']['value'])) { throw new ExtensionManagerException('Extension Manager is in offline mode. No TER connection available.', 1437078620); } $extensionPath = \TYPO3\CMS\Core\Utility\GeneralUtility::strtolower($extensionKey); $mirrorUrl .= $extensionPath[0] . '/' . $extensionPath[1] . '/' . $extensionPath . '_' . $version . '.t3x'; $t3x = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($mirrorUrl, 0, array(TYPO3_user_agent)); $md5 = md5($t3x); if ($t3x === false) { throw new ExtensionManagerException(sprintf('The T3X file "%s" could not be fetched. Possible reasons: network problems, allow_url_fopen is off, cURL is not enabled in Install Tool.', $mirrorUrl), 1334426097); } if ($md5 === $expectedMd5) { // Fetch and return: $extensionData = $this->decodeExchangeData($t3x); } else { throw new ExtensionManagerException('Error: MD5 hash of downloaded file not as expected: ' . $md5 . ' != ' . $expectedMd5, 1334426098); } return $extensionData; }
/** * Renders a download link * * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension * @return string the rendered a tag */ public function render(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) { $installPaths = \TYPO3\CMS\Extensionmanager\Domain\Model\Extension::returnAllowedInstallPaths(); if (empty($installPaths)) { return ''; } $pathSelector = '<ul class="is-hidden">'; foreach ($installPaths as $installPathType => $installPath) { $pathSelector .= '<li> <input type="radio" id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '" name="' . htmlspecialchars($this->getFieldNamePrefix('downloadPath')) . '[downloadPath]" class="downloadPath" value="' . htmlspecialchars($installPathType) . '"' . ($installPathType == 'Local' ? ' checked="checked"' : '') . '/> <label for="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '">' . htmlspecialchars($installPathType) . '</label> </li>'; } $pathSelector .= '</ul>'; $uriBuilder = $this->controllerContext->getUriBuilder(); $action = 'checkDependencies'; $uriBuilder->reset(); $uriBuilder->setFormat('json'); $uri = $uriBuilder->uriFor($action, array('extension' => (int) $extension->getUid()), 'Download'); $this->tag->addAttribute('data-href', $uri); $automaticInstallation = $this->configurationUtility->getCurrentConfiguration('extensionmanager')['automaticInstallation']['value']; $labelKeySuffix = $automaticInstallation ? '' : '.downloadOnly'; $label = ' <div class="btn-group"> <button title="' . LocalizationUtility::translate('extensionList.downloadViewHelper.submit' . $labelKeySuffix, 'extensionmanager') . '" type="submit" class="btn btn-default" value="' . LocalizationUtility::translate('extensionList.downloadViewHelper.submit' . $labelKeySuffix, 'extensionmanager') . '" > <span class="t3-icon fa fa-cloud-download"></span> </button> </div>'; $this->tag->setContent($label . $pathSelector); $this->tag->addAttribute('class', 'download'); return '<div id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadFromTer" class="downloadFromTer">' . $this->tag->render() . '</div>'; }
/** * Install an extension from TER * Downloads the extension, resolves dependencies and installs it * * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension * @param string $downloadPath * @return array */ protected function installFromTer(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath = 'Local') { $result = false; $errorMessages = array(); try { $this->downloadUtility->setDownloadPath($downloadPath); $this->managementService->setAutomaticInstallationEnabled($this->configurationUtility->getCurrentConfiguration('extensionmanager')['automaticInstallation']['value']); if (($result = $this->managementService->installExtension($extension)) === false) { $errorMessages = $this->managementService->getDependencyErrors(); } } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) { $errorMessages = array($extension->getExtensionKey() => array(array('code' => $e->getCode(), 'message' => $e->getMessage()))); } return array($result, $errorMessages); }
/** * Method fetches contents from remote server and * writes them into a file in the local file system. * * @param string $remoteResource remote resource to read contents from * @param string $localResource local resource (absolute file path) to store retrieved contents to (must be within typo3temp/) * @return void * @see \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(), \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile() * @throws ExtensionManagerException */ protected function fetchFile($remoteResource, $localResource) { if ($this->configurationUtility->getCurrentConfiguration('extensionmanager')['offlineMode']['value']) { throw new ExtensionManagerException('Extension Manager is in offline mode. No TER connection available.', 1437078780); } if (is_string($remoteResource) && is_string($localResource) && !empty($remoteResource) && !empty($localResource)) { $fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($remoteResource); if ($fileContent !== false) { if (\TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir($localResource, $fileContent) !== null) { throw new ExtensionManagerException(sprintf('Could not write to file %s.', $localResource), 1342635378); } } else { throw new ExtensionManagerException(sprintf('Could not access remote resource %s.', $remoteResource), 1342635425); } } }