diff --git a/lib/Command/ExApp/Register.php b/lib/Command/ExApp/Register.php index 2063e9ad..4035192c 100644 --- a/lib/Command/ExApp/Register.php +++ b/lib/Command/ExApp/Register.php @@ -72,9 +72,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 3; } - $extractedDir = ''; $appInfo = $this->exAppService->getAppInfo( - $appId, $input->getOption('info-xml'), $input->getOption('json-info'), $extractedDir + $appId, $input->getOption('info-xml'), $input->getOption('json-info') ); if (isset($appInfo['error'])) { $this->logger->error($appInfo['error']); @@ -175,13 +174,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - if ($daemonConfig->getAcceptsDeployId() !== $this->manualActions->getAcceptsDeployId()) { - $result = $this->exAppArchiveFetcher->installTranslations($appId, $extractedDir); + if (!empty($appInfo['external-app']['translations_folder'])) { + $result = $this->exAppArchiveFetcher->installTranslations($appId, $appInfo['external-app']['translations_folder']); if ($result) { $this->logger->error(sprintf('Failed to install translations for %s. Reason: %s', $appId, $result)); if ($outputConsole) { $output->writeln(sprintf('Failed to install translations for %s. Reason: %s', $appId, $result)); } + $this->exAppService->unregisterExApp($appId); + return 3; } } diff --git a/lib/Command/ExApp/Update.php b/lib/Command/ExApp/Update.php index 3b004798..e6f83e24 100644 --- a/lib/Command/ExApp/Update.php +++ b/lib/Command/ExApp/Update.php @@ -56,9 +56,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $outputConsole = !$input->getOption('silent'); $appId = $input->getArgument('appid'); - $extractedDir = ''; $appInfo = $this->exAppService->getAppInfo( - $appId, $input->getOption('info-xml'), $input->getOption('json-info'), $extractedDir + $appId, $input->getOption('info-xml'), $input->getOption('json-info') ); if (isset($appInfo['error'])) { $this->logger->error($appInfo['error']); @@ -121,8 +120,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - if ($daemonConfig->getAcceptsDeployId() !== $this->manualActions->getAcceptsDeployId()) { - $result = $this->exAppArchiveFetcher->installTranslations($appId, $extractedDir); + if (!empty($appInfo['external-app']['translations_folder'])) { + $result = $this->exAppArchiveFetcher->installTranslations($appId, $appInfo['external-app']['translations_folder']); if ($result) { $this->logger->error(sprintf('Failed to install translations for %s. Reason: %s', $appId, $result)); if ($outputConsole) { diff --git a/lib/Fetcher/ExAppArchiveFetcher.php b/lib/Fetcher/ExAppArchiveFetcher.php index 7a1ed8c9..f7cf022e 100644 --- a/lib/Fetcher/ExAppArchiveFetcher.php +++ b/lib/Fetcher/ExAppArchiveFetcher.php @@ -74,24 +74,20 @@ public function downloadInfoXml(array $exAppAppstoreData, string &$extractedDir) return $infoXml; } - public function installTranslations(string $appId, string $extractedDir): string { - if (!$extractedDir) { - return ''; - } - if (!file_exists($extractedDir)) { - return 'Missing temp directory with ExApp files'; + public function installTranslations(string $appId, string $dirTranslations): string { + if (!file_exists($dirTranslations)) { + return sprintf('Can not access directory: %s', $dirTranslations); } $writableAppPath = $this->getExAppFolder($appId); if (!$writableAppPath) { - return 'Can not find writable apps path to perform install.'; + return 'Can not find writable apps path to perform installation.'; } - $installL10NPath = $writableAppPath . '/' . $appId . '/l10n'; + $installL10NPath = $writableAppPath . '/l10n'; if (file_exists($installL10NPath)) { $this->rmdirr($installL10NPath); // Remove old l10n folder and files if exists } - // Move l10n folder from extracted temp to the app folder - rename($extractedDir . '/l10n', $installL10NPath); + $this->copyr($dirTranslations, $installL10NPath); return ''; } @@ -214,14 +210,7 @@ private function splitCerts(string $cert): array { return $matches[0]; } - /** - * Recursive deletion of folders - * - * @param string $dir path to the folder - * @param bool $deleteSelf if set to false only the content of the folder will be deleted - * @return bool - */ - public static function rmdirr(string $dir, bool $deleteSelf = true): bool { + public function rmdirr(string $dir, bool $deleteSelf = true): bool { if (is_dir($dir)) { $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), @@ -251,4 +240,20 @@ public static function rmdirr(string $dir, bool $deleteSelf = true): bool { return !file_exists($dir); } + + public function copyr(string $src, string $dest): void { + if (is_dir($src)) { + if (!is_dir($dest)) { + mkdir($dest); + } + $files = scandir($src); + foreach ($files as $file) { + if ($file != "." && $file != "..") { + self::copyr("$src/$file", "$dest/$file"); + } + } + } elseif (file_exists($src)) { + copy($src, $dest); + } + } } diff --git a/lib/Middleware/ExAppUIL10NMiddleware.php b/lib/Middleware/ExAppUIL10NMiddleware.php index 35876307..bc02fe92 100644 --- a/lib/Middleware/ExAppUIL10NMiddleware.php +++ b/lib/Middleware/ExAppUIL10NMiddleware.php @@ -58,7 +58,7 @@ public function beforeOutput(Controller $controller, string $methodName, string $nonce = $this->nonceManager->getNonce(); $output = substr_replace($output, '', $headPos, 0); } catch (AppPathNotFoundException) { - $this->logger->error(sprintf('Can not find translations for %s ExApp.', $appId)); + $this->logger->debug(sprintf('Can not find translations for %s ExApp.', $appId)); } } } diff --git a/lib/Middleware/ExAppUiMiddleware.php b/lib/Middleware/ExAppUiMiddleware.php index a91a646f..407a23f1 100644 --- a/lib/Middleware/ExAppUiMiddleware.php +++ b/lib/Middleware/ExAppUiMiddleware.php @@ -54,7 +54,7 @@ public function beforeOutput(Controller $controller, string $methodName, string $nonce = $this->nonceManager->getNonce(); $output = substr_replace($output, '', $headPos, 0); } catch (AppPathNotFoundException) { - $this->logger->error(sprintf('Can not find translations for %s ExApp.', $appId)); + $this->logger->debug(sprintf('Can not find translations for %s ExApp.', $appId)); } } } diff --git a/lib/Service/ExAppService.php b/lib/Service/ExAppService.php index c07c8277..871e1035 100644 --- a/lib/Service/ExAppService.php +++ b/lib/Service/ExAppService.php @@ -268,13 +268,14 @@ private function resetCaches(): void { $this->settingsService->resetCacheEnabled(); } - public function getAppInfo(string $appId, ?string $infoXml, ?string $jsonInfo, string &$extractedDir): array { + public function getAppInfo(string $appId, ?string $infoXml, ?string $jsonInfo): array { + $extractedDir = ''; if ($jsonInfo !== null) { $appInfo = json_decode($jsonInfo, true); # fill 'id' if it is missing(this field was called `appid` in previous versions in json) $appInfo['id'] = $appInfo['id'] ?? $appId; # during manual install JSON can have all values at root level - foreach (['docker-install', 'scopes', 'system'] as $key) { + foreach (['docker-install', 'scopes', 'system', 'translations_folder'] as $key) { if (isset($appInfo[$key])) { $appInfo['external-app'][$key] = $appInfo[$key]; unset($appInfo[$key]); @@ -298,6 +299,13 @@ public function getAppInfo(string $appId, ?string $infoXml, ?string $jsonInfo, s if (isset($appInfo['external-app']['scopes']['value'])) { $appInfo['external-app']['scopes'] = $appInfo['external-app']['scopes']['value']; } + if ($extractedDir) { + if (file_exists($extractedDir . '/l10n')) { + $appInfo['translations_folder'] = $extractedDir . '/l10n'; + } else { + $this->logger->info(sprintf('Application %s does not support translations', $appId)); + } + } # TO-DO: remove this in AppAPI 2.3.0 if (isset($appInfo['external-app']['scopes']['required']['value'])) { $appInfo['external-app']['scopes'] = $appInfo['external-app']['scopes']['required']['value'];