From d4e12a3683ff7f1496a47b54f3c596cdd2eb54d5 Mon Sep 17 00:00:00 2001 From: christianbeeznst Date: Wed, 27 Mar 2024 19:34:41 -0500 Subject: [PATCH] Migration: Remove lang 'import' directory and fix quechua sublanguage --- .../Schema/V200/Version20240122221400.php | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20240122221400.php b/src/CoreBundle/Migrations/Schema/V200/Version20240122221400.php index 14a20bc235..4449dae8ce 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20240122221400.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20240122221400.php @@ -30,7 +30,7 @@ final class Version20240122221400 extends AbstractMigrationChamilo $connection = $em->getConnection(); // Default sublanguages to be excluded from the update. - $defaultSubLanguages = ['ast', 'ast_ES', 'ca', 'ca_ES', 'eo', 'gl', 'qu', 'quz_PE', 'zh-TW', 'zh_TW', 'pt-BR', 'pt_PT', 'fur', 'fur_IT', 'oc', 'oc_FR']; + $defaultSubLanguages = ['ast', 'ast_ES', 'ca', 'ca_ES', 'eo', 'gl', 'qu', 'quz_PE', 'qu_PE', 'zh-TW', 'zh_TW', 'pt-BR', 'pt_PT', 'fur', 'fur_IT', 'oc', 'oc_FR']; // Fetching sublanguages from the database. $sql = "SELECT * FROM language WHERE parent_id IS NOT NULL AND isocode NOT IN('".implode("', '", $defaultSubLanguages)."')"; @@ -43,6 +43,9 @@ final class Version20240122221400 extends AbstractMigrationChamilo // Update Vue translations after processing all sublanguages. $this->executeVueTranslationsUpdate(); + + // Delete the 'import' folder at the end of the process. + $this->deleteImportFolder(); } private function updateAndGenerateSubLanguage(array $sublanguage, Connection $connection): string @@ -183,5 +186,28 @@ final class Version20240122221400 extends AbstractMigrationChamilo return substr($parentCode.'_'.$variantCode, 0, $maxLength); } + private function deleteImportFolder(): void + { + $container = $this->getContainer(); + $kernel = $container->get('kernel'); + $rootPath = $kernel->getProjectDir(); + $importPath = $rootPath . '/var/translations/import/'; + + $this->recursiveRemoveDirectory($importPath); + } + + private function recursiveRemoveDirectory($directory): void + { + foreach(glob("{$directory}/*") as $file) + { + if(is_dir($file)) { + $this->recursiveRemoveDirectory($file); + } else { + unlink($file); + } + } + rmdir($directory); + } + public function down(Schema $schema): void {} }