4 use Psr\Log\LoggerAwareInterface;
5 use Psr\Log\LoggerAwareTrait;
80 $this->languageService->includeLLFile(
'EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
95 $files = array_diff_key($files, array_flip($directories));
111 foreach ($files as $filePath => $file) {
112 preg_match(
'/(.*)\\//', $filePath, $matches);
113 if (!empty($matches[0])) {
114 $directories[] = $matches[0];
117 return array_unique($directories);
128 return $extensionData[
'FILES'];
140 foreach ($directories as $directory) {
154 GeneralUtility::mkdir_deep($directory);
155 }
catch (\RuntimeException $exception) {
157 sprintf($this->languageService->getLL(
'fileHandling.couldNotCreateDirectory'), $this->getRelativePath($directory)),
171 foreach ($files as $file) {
172 GeneralUtility::writeFile($rootPath . $file[
'name'], $file[
'content']);
188 if (is_dir($extDirPath)) {
207 $path = $paths[$pathType] ??
'';
208 if (!$path || !is_dir($path) || !$extensionKey) {
210 sprintf($this->languageService->getLL(
'fileHandling.installPathWasNoDirectory'), $this->getRelativePath($path)),
215 return $path . $extensionKey .
'/';
226 GeneralUtility::mkdir($extDirPath);
227 if (!is_dir($extDirPath)) {
229 sprintf($this->languageService->getLL(
'fileHandling.couldNotCreateDirectory'), $this->getRelativePath($extDirPath)),
257 return is_dir($directory);
268 $requestedDirectories = [];
269 $requestUploadFolder = isset($extension[
'uploadfolder']) ? (bool)$extension[
'uploadfolder'] :
false;
270 if ($requestUploadFolder) {
274 $requestCreateDirectories = empty($extension[
'createDirs']) ? false : (string)$extension[
'createDirs'];
275 if ($requestCreateDirectories) {
276 foreach (GeneralUtility::trimExplode(
',', $extension[
'createDirs']) as $directoryToCreate) {
281 return $requestedDirectories;
292 return 'uploads/tx_' . str_replace(
'_',
'', $extension[
'key']) .
'/';
303 $extDirPath = GeneralUtility::fixWindowsFilePath($extDirPath);
304 $extensionPathWithoutTrailingSlash = rtrim($extDirPath,
'/');
306 $result = unlink($extensionPathWithoutTrailingSlash);
308 $result = GeneralUtility::rmdir($extDirPath,
true);
310 if ($result ===
false) {
312 sprintf($this->languageService->getLL(
'fileHandling.couldNotRemoveDirectory'), $this->getRelativePath($extDirPath)),
328 $emConfFileData = [];
329 if (file_exists($rootPath .
'ext_emconf.php')) {
330 $emConfFileData = $this->emConfUtility->includeEmConf(
332 'key' => $extensionData[
'extKey'],
337 $extensionData[
'EM_CONF'] = array_replace_recursive($emConfFileData, $extensionData[
'EM_CONF']);
338 $emConfContent = $this->emConfUtility->constructEmConf($extensionData, $extension);
339 GeneralUtility::writeFile($rootPath .
'ext_emconf.php', $emConfContent);
351 foreach ($allowedPaths as $allowedPath) {
352 if (GeneralUtility::isFirstPartOfStr($path, $allowedPath)) {
368 $absolutePath = GeneralUtility::getFileAbsFileName(GeneralUtility::resolveBackPath(
Environment::getPublicPath() .
'/' . $relativePath));
369 if (empty($absolutePath)) {
372 return $absolutePath;
394 $extension = $this->installUtility->enrichExtensionWithDetails($extension);
396 return $absolutePath;
407 $extensionData = $this->installUtility->enrichExtensionWithDetails($extension);
408 $version = $extensionData[
'version'];
426 if (empty($version)) {
431 if (!@is_dir($temporaryPath)) {
432 GeneralUtility::mkdir($temporaryPath);
434 $fileName = $temporaryPath . $extension .
'_' . $version .
'_' . date(
'YmdHi',
$GLOBALS[
'EXEC_TIME']) .
'.zip';
436 $zip = new \ZipArchive();
437 $zip->open($fileName, \ZipArchive::CREATE);
439 $excludePattern =
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXT'][
'excludeForPackaging'];
442 $files = GeneralUtility::getAllFilesAndFoldersInPath(
452 $files = GeneralUtility::removePrefixPathFromList($files, $extensionPath);
455 $files = array_filter($files);
457 foreach ($files as $file) {
458 $fullPath = $extensionPath . $file;
461 if (is_dir($fullPath)) {
462 $zip->addEmptyDir($file);
464 $zip->addFile($fullPath, $file);
485 $zipService = GeneralUtility::makeInstance(ZipService::class);
486 if ($zipService->verify($file)) {
487 $zipService->extract($file, $extensionDir);
490 $this->logger->error(
'Extracting the extension archive failed', [
'exception' => $e]);
494 GeneralUtility::fixPermissions($extensionDir,
true);
505 if ($downloadName ===
'') {
508 header(
'Content-Type: application/zip');
509 header(
'Content-Length: ' . filesize($fileName));
510 header(
'Content-Disposition: attachment; filename="' . $downloadName .
'"');
521 $this->installUtility->reloadPackageInformation($extensionKey);