[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX][TRA] GetStrings: handle missing custom language directories and skip generated files

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a9059e0cc266_3818dc386523d@gitlab-sidekiq-low-urgency-cpu-bound-v2-6ffbbc95d9-cwm78.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
aae770dd by MAGENE Sem Joel at 2026-08-27T15:21:34+00:00
[FIX][TRA] GetStrings: handle missing custom language directories and skip generated files
---
* [FIX][TRA] GetStrings: handle missing custom language directories and skip generated files

See merge request tikiwiki/tiki!11075

- - - - -


5 changed files:

- lib/core/Tiki/Command/GetStringsCommand.php
- lib/language/CollectFiles.php
- lib/language/GetStrings.php
- lib/test/language/CollectFilesTest.php
- lib/test/language/GetStringsTest.php


Changes:

=====================================
lib/core/Tiki/Command/GetStringsCommand.php
=====================================
@@ -154,7 +154,8 @@ class GetStringsCommand extends Command
                     TIKI_CUSTOMIZATIONS_SRC_PATH, EXPORT_DUMP_PATH, STATIC_IMG_PATH, LANG_SRC_PATH, BIN_PATH,
                     TIKI_UPGRADE_SQL_SCHEMA_PATH, TIKI_VENDOR_BUNDLED_TOPLEVEL_PATH, TIKI_VENDOR_NONBUNDLED_PATH,
                     TIKI_VENDOR_CUSTOM_PATH, 'lib/test', TEMP_PATH, PERMISSIONCHECK_PATH,
-                    DEPRECATED_STORAGE_PATH, TIKI_TESTS_PATH, DEPRECATED_DEVTOOLS_PATH, TIKI_CONFIG_PATH, 'lib/openlayers', TESTS_PATH
+                    DEPRECATED_STORAGE_PATH, TIKI_TESTS_PATH, DEPRECATED_DEVTOOLS_PATH, TIKI_CONFIG_PATH, 'lib/openlayers',
+                    TESTS_PATH, 'node_modules', PUBLIC_GENERATED_PATH
                 ], 'is_dir');
                 // Files are processed after the base directory, so adding a file here allows to scan it even if its directory was excluded.
                 $includeFiles = $include ?? ['./' . LANG_PATH_FRAGMENT . '/langmapping.php', './' . IMG_FLAGNAMES_FILE];
@@ -179,7 +180,7 @@ class GetStringsCommand extends Command
                 $customOptions['includeDatabase'] = true;
 
                 // Do not scan the generated language files themselves
-                $customExcludeDirs = $exclude ?? [$customOptions['langDir']];
+                $customExcludeDirs = $exclude ?? array_filter([$customOptions['langDir']], 'is_dir');
                 $customIncludeFiles = $include ?? [];
 
                 $result = $this->runPass($output, $customOptions, $customExcludeDirs, $customIncludeFiles, $onlyCustom);


=====================================
lib/language/CollectFiles.php
=====================================
@@ -150,10 +150,10 @@ class Language_CollectFiles
                 continue;
             }
 
-            if (preg_match($pattern, $file)) {
-                $files[] = $path;
-            } elseif (is_dir($path)) {
+            if (is_dir($path)) {
                 $files = array_merge($files, $this->scanDir($path));
+            } elseif (preg_match($pattern, $file)) {
+                $files[] = $path;
             }
         }
 


=====================================
lib/language/GetStrings.php
=====================================
@@ -492,7 +492,15 @@ class Language_GetStrings
     protected function getAllLanguages()
     {
         $languages = [];
+
+        if (! is_dir($this->langDir)) {
+            return $languages;
+        }
+
         $dirs = dir($this->langDir);
+        if ($dirs === false) {
+            return $languages;
+        }
 
         while (false !== ($entry = $dirs->read())) {
             if ($entry == '.' || $entry == '..') {


=====================================
lib/test/language/CollectFilesTest.php
=====================================
@@ -83,6 +83,17 @@ class Language_CollectFilesTest extends TikiTestCase
         $this->assertEquals($expectedResult, $this->obj->scanDir(vfsStream::url('root')));
     }
 
+    public function testScanDirShouldTraverseDirectoryNamedLikeAFile(): void
+    {
+        vfsStream::setup('root', null, [
+            'package.js' => ['translations.php' => ''],
+        ]);
+
+        $files = $this->obj->scanDir(vfsStream::url('root'));
+
+        $this->assertSame(['vfs://root/package.js/translations.php'], $files);
+    }
+
     public function testScanDirShouldIgnoreExcludedDirs(): void
     {
         $obj = $this->getMockBuilder('Language_CollectFiles')


=====================================
lib/test/language/GetStringsTest.php
=====================================
@@ -271,6 +271,18 @@ class Language_GetStringsTest extends TikiTestCase
         $obj->setLanguages();
     }
 
+    public function testMissingLanguageDirectoryReturnsNoLanguages(): void
+    {
+        vfsStream::setup('root', null, ['src' => []]);
+
+        $obj = new Language_GetStrings($this->collectFiles, $this->writeFileFactory, [
+            'scanDir' => vfsStream::url('root/src'),
+            'langDir' => vfsStream::url('root/missing-lang'),
+        ]);
+
+        $this->assertSame([], $obj->getLanguages());
+    }
+
     /**
      * @throws Language_Exception
      */



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/aae770dd1351f1542c31fea39e867475afceb75f

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/aae770dd1351f1542c31fea39e867475afceb75f
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.