Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Marcin Sągol
lfeditor
Commits
1e624594
Commit
1e624594
authored
Nov 13, 2015
by
Fabian Galinski
😾
Browse files
[BUGFIX] Errors can appear for the first usage of a language file with <CDATA[]]> values
parent
7a8433aa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Classes/Service/FileBaseService.php
View file @
1e624594
...
...
@@ -87,6 +87,8 @@ abstract class FileBaseService extends FileService {
$this
->
setWorkspace
(
'base'
);
parent
::
init
(
$file
,
$path
);
$this
->
prepareLanguageFilesForFirstUsage
();
}
/**
...
...
@@ -141,6 +143,55 @@ abstract class FileBaseService extends FileService {
$this
->
localLang
=
$localLang
;
$this
->
originLang
=
$originLang
;
}
/**
* Prepares this language file and it's translations for the first usage.
*
* @throws LFException
* @return void
*/
protected
function
prepareLanguageFilesForFirstUsage
()
{
$adaptedContent
=
$this
->
checkFileForFirstImport
(
$this
->
absFile
);
if
(
$adaptedContent
)
{
$files
=
[];
$files
[
$this
->
absFile
]
=
$adaptedContent
;
$languages
=
SgLib
::
getSystemLanguages
();
foreach
(
$languages
as
$lang
)
{
if
(
$lang
===
'default'
)
{
continue
;
}
$file
=
dirname
(
$this
->
absFile
)
.
'/'
.
$this
->
nameLocalizedFile
(
$lang
);
if
(
file_exists
(
$file
)
&&
$this
->
checkLocalizedFile
(
basename
(
$file
),
$lang
))
{
$adaptedContent
=
$this
->
checkFileForFirstImport
(
$file
);
if
(
$adaptedContent
)
{
$files
[
$file
]
=
$adaptedContent
;
}
}
}
$this
->
writeFilesWithContent
(
$files
);
}
}
/**
* Checks if the given file is generated by this extension, if not the data will be prepared and returned.
*
* @param string $file
* @return bool|string
*/
protected
function
checkFileForFirstImport
(
$file
)
{
$fileContent
=
file_get_contents
(
$file
);
if
(
strpos
(
$fileContent
,
'<generator>LFEditor</generator>'
)
===
FALSE
)
{
$fileContent
=
str_replace
(
'<![CDATA['
,
'<![CDATA['
,
$fileContent
);
$fileContent
=
str_replace
(
']]>'
,
']]>'
,
$fileContent
);
}
else
{
return
FALSE
;
}
return
$fileContent
;
}
}
?>
\ No newline at end of file
Classes/Service/FileService.php
View file @
1e624594
...
...
@@ -277,16 +277,32 @@ abstract class FileService extends AbstractService {
public
function
writeFile
(
$editedLanguages
=
NULL
)
{
// get prepared language files
$languageFiles
=
$this
->
prepareFileContents
(
$editedLanguages
);
$this
->
writeFilesWithContent
(
$languageFiles
);
}
/**
* Writes the given files with the given content.
*
* Array structure:
* array (
* '/var/www/file.xlf' => 'My content',
* ...
* )
*
* @param array $files
* @throws LFException
* @return void
*/
public
function
writeFilesWithContent
(
array
$files
=
[])
{
// check write permissions of all files
foreach
(
$
languageF
iles
as
$file
=>
$content
)
{
foreach
(
$
f
iles
as
$file
=>
$content
)
{
if
(
!
SgLib
::
checkWritePerms
(
$file
))
{
throw
new
LFException
(
'failure.file.badPermissions'
);
}
}
// write files
foreach
(
$
languageF
iles
as
$file
=>
$content
)
{
foreach
(
$
f
iles
as
$file
=>
$content
)
{
if
(
!
GeneralUtility
::
writeFile
(
$file
,
$content
))
{
throw
new
LFException
(
'failure.file.notWritten'
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment