Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
typo3
qfq
Commits
c9883bf0
Commit
c9883bf0
authored
Dec 18, 2018
by
Carsten Rose
Browse files
B7455 php unit tests fail: catch exception on trying to open a non existing logfile
parent
454d7fb3
Changes
1
Hide whitespace changes
Inline
Side-by-side
extension/Source/core/helper/Logger.php
View file @
c9883bf0
...
...
@@ -8,6 +8,8 @@
namespace
qfq
;
use
Complex\Exception
;
require_once
(
__DIR__
.
'/../Constants.php'
);
require_once
(
__DIR__
.
'/../exceptions/UserFormException.php'
);
require_once
(
__DIR__
.
'/../helper/Support.php'
);
...
...
@@ -25,9 +27,12 @@ class Logger {
* @param $filename
*
* @param string $mode
* @param bool $recursion
* @throws UserFormException
*/
public
static
function
logMessage
(
$msg
,
$filename
,
$mode
=
FILE_MODE_APPEND
)
{
public
static
function
logMessage
(
$msg
,
$filename
,
$mode
=
FILE_MODE_APPEND
,
$recursion
=
false
)
{
$handle
=
false
;
if
(
$filename
==
''
)
{
return
;
...
...
@@ -35,19 +40,25 @@ class Logger {
$filename
=
self
::
relativeToT3Dir
(
$filename
);
if
(
!
$handle
=
fopen
(
$filename
,
$mode
))
{
try
{
$handle
=
fopen
(
$filename
,
$mode
);
}
catch
(
\
Exception
$e
)
{
$dummy
=
1
;
}
// If open fails, maybe the directory does not exist. Create it:
HelperFile
::
mkDirParent
(
$filename
);
if
(
$handle
===
false
)
{
// Try to open the file a second time.
if
(
!
$handle
=
fopen
(
$filename
,
$mode
))
{
if
(
$recursion
){
throw
new
UserFormException
(
json_encode
([
ERROR_MESSAGE_TO_USER
=>
'Error: cannot open file'
,
ERROR_MESSAGE_SUPPORT
=>
"Error - cannot open. File: "
.
$filename
.
" ( CWD: "
.
getcwd
()
.
") - "
.
HelperFile
::
errorGetLastAsString
()]),
ERROR_IO_OPEN
);
}
// If open fails, maybe the directory does not exist. Create it:
HelperFile
::
mkDirParent
(
$filename
);
self
::
logMessage
(
$msg
,
$filename
,
$mode
,
true
);
}
if
(
fwrite
(
$handle
,
$msg
.
PHP_EOL
)
===
false
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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