Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
search_api_attachments
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
search_api_attachments
Merge requests
!8
Issue
#3255205
: Indexing fails due to missing locale
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3255205
: Indexing fails due to missing locale
issue/search_api_attachments-3255205:3255205-fallback-locale
into
8.x-1.x
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Christopher Gadd
requested to merge
issue/search_api_attachments-3255205:3255205-fallback-locale
into
8.x-1.x
3 years ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
8.x-1.x
8.x-1.x (base)
and
latest version
latest version
8d205b54
1 commit,
3 years ago
1 file
+
10
−
7
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/Plugin/search_api_attachments/TikaExtractor.php
+
10
−
7
Options
@@ -33,10 +33,14 @@ class TikaExtractor extends TextExtractorPluginBase {
$java
=
$this
->
configuration
[
'java_path'
];
// UTF-8 multibyte characters will be stripped by escapeshellargs() for the
// default C-locale.
// So temporarily set the locale to UTF-8 so that the filepath remains
// valid.
// So temporarily set the locale to UTF-8 if available so that the filepath
// remains valid.
// Attempt to use en_US.UTF-8 first, and fallback to C.UTF-8, since
// en_US.UTF-8 is more widespread, while C.UTF-8 may be present otherwwise.
$backup_locale
=
setlocale
(
LC_CTYPE
,
'0'
);
setlocale
(
LC_CTYPE
,
'en_US.UTF-8'
);
$preferred_locales
=
[
'en_US.UTF-8'
,
'C.UTF-8'
];
$new_locale
=
setlocale
(
LC_CTYPE
,
$preferred_locales
)
?:
$backup_locale
;
$param
=
''
;
if
(
$file
->
getMimeType
()
!=
'audio/mpeg'
)
{
$param
=
' -Dfile.encoding=UTF8 -cp '
.
escapeshellarg
(
$tika
);
@@ -51,12 +55,11 @@ class TikaExtractor extends TextExtractorPluginBase {
}
// Restore the locale.
setlocale
(
LC_CTYPE
,
$backup_locale
);
// Support UTF-8 commands:
// @see http://www.php.net/manual/en/function.shell-exec.php#85095
shell_exec
(
"LANG=en_US.utf-8"
);
// Support UTF-8 encoded filenames
$cmd
=
'export LANG='
.
$new_locale
.
'; '
.
$cmd
;
$output
=
shell_exec
(
$cmd
);
if
(
is_null
(
$output
))
{
throw
new
\Exception
(
'Tika Ex
c
tractor is not available.'
);
throw
new
\Exception
(
'Tika Extractor is not available.'
);
}
return
$output
;
}
Loading