[TikiWiki-commits] [Git][tikiwiki/tiki][27.x] [BP][FIX][TRA] GetStrings: handle missing custom language directories and skip generated files
"MAGENE Sem Joel \(@Jomagene\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a916d34ce064_3a23376b840884@gitlab-sidekiq-low-urgency-cpu-bound-v2-85746979f6-284rz.mail> |
MAGENE Sem Joel pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki
Commits:
a04e37f4 by MAGENE Sem Joel at 2026-08-28T11:04:36+00:00
[BP][FIX][TRA] GetStrings: handle missing custom language directories and skip generated files
---
* [BP][FIX][TRA] GetStrings: handle missing custom language directories and skip generated files
---
* [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
(cherry picked from commit aae770dd1351f1542c31fea39e867475afceb75f)
See merge request tikiwiki/tiki!11080
(cherry picked from commit 7cda692023193303b32ca4b46b1c3c9b124d9ddc)
See merge request tikiwiki/tiki!11081
- - - - -
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
=====================================
@@ -153,7 +153,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];
@@ -178,7 +179,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
=====================================
@@ -84,6 +84,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
=====================================
@@ -277,6 +277,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/a04e37f422e23c781d70e22c1c4bc34ee696adf5
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/a04e37f422e23c781d70e22c1c4bc34ee696adf5
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