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
eefd1188
Commit
eefd1188
authored
Jan 27, 2017
by
Carsten Rose
Browse files
delete.php, QuickFormQuery.php: Error handling improved.
parent
794aa0c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
extension/qfq/api/delete.php
View file @
eefd1188
...
...
@@ -13,6 +13,7 @@ use qfq;
require_once
(
__DIR__
.
'/../qfq/QuickFormQuery.php'
);
require_once
(
__DIR__
.
'/../qfq/store/Store.php'
);
require_once
(
__DIR__
.
'/../qfq/Constants.php'
);
require_once
(
__DIR__
.
'/../qfq/exceptions/CodeException.php'
);
/**
...
...
@@ -47,14 +48,20 @@ require_once(__DIR__ . '/../qfq/Constants.php');
$answer
=
array
();
$answer
[
API_REDIRECT
]
=
API_ANSWER_REDIRECT_NO
;
$answer
[
API_MESSAGE
]
=
'
Something failed
'
;
$answer
[
API_MESSAGE
]
=
''
;
$answer
[
API_STATUS
]
=
API_ANSWER_STATUS_ERROR
;
$result
[
MSG_HEADER
]
=
''
;
$result
[
MSG_CONTENT
]
=
''
;
$modeAnswer
=
false
;
$flagSuccess
=
false
;
try
{
$qfq
=
new
\
qfq\QuickFormQuery
([
'bodytext'
=>
''
]);
$qfq
->
delete
();
$flagSuccess
=
$qfq
->
delete
();
$targetUrl
=
Store
::
getVar
(
SIP_TARGET_URL
,
STORE_SIP
);
$modeAnswer
=
Store
::
getVar
(
SIP_MODE_ANSWER
,
STORE_SIP
);
...
...
@@ -65,21 +72,14 @@ try {
$answer
[
API_MESSAGE
]
=
'delete: success'
;
$answer
[
API_REDIRECT
]
=
API_ANSWER_REDIRECT_CLIENT
;
$answer
[
API_STATUS
]
=
API_ANSWER_STATUS_SUCCESS
;
$result
[
MSG_HEADER
]
=
"Content-Type: application/json"
;
$result
[
MSG_CONTENT
]
=
json_encode
(
$answer
);
break
;
case
MODE_HTML
:
if
(
$targetUrl
===
false
||
$targetUrl
===
''
)
{
$result
[
MSG_CONTENT
]
=
'Missing target URL. '
.
ERROR_MISSING_VALUE
;
}
else
{
$result
[
MSG_CONTENT
]
=
''
;
throw
new
CodeException
(
'Missing target URL'
,
ERROR_MISSING_VALUE
);
}
$result
[
MSG_HEADER
]
=
"Location:
$targetUrl
"
;
break
;
default
:
...
...
@@ -100,8 +100,6 @@ try {
$answer
[
API_FIELD_MESSAGE
]
=
$val
;
}
$result
[
MSG_CONTENT
]
=
json_encode
(
$answer
);
}
catch
(
qfq\CodeException
$e
)
{
$answer
[
API_MESSAGE
]
=
$e
->
formatMessage
();
}
catch
(
qfq\DbException
$e
)
{
...
...
@@ -110,13 +108,27 @@ try {
$answer
[
API_MESSAGE
]
=
"Generic Exception: "
.
$e
->
getMessage
();
}
// Fallbak. in case an exception has been thrown and $result is not filled.
if
(
!
isset
(
$result
[
MSG_HEADER
])
&&
!
isset
(
$result
[
MSG_CONTENT
]))
{
// In case $modeAnswer is still missing: try to get it again - maybe the SIP store has been initialized before the exception has been thrown.
if
(
$modeAnswer
===
false
)
{
$modeAnswer
=
Store
::
getVar
(
SIP_MODE_ANSWER
,
STORE_SIP
);
}
if
(
$modeAnswer
===
MODE_JSON
)
{
// JSON
$result
[
MSG_HEADER
]
=
"Content-Type: application/json"
;
$result
[
MSG_CONTENT
]
=
json_encode
(
$answer
);
}
else
{
// HTML
if
(
!
$flagSuccess
)
{
$result
[
MSG_CONTENT
]
=
"<p>"
.
$answer
[
API_MESSAGE
]
.
"</p>"
;
if
(
isset
(
$answer
[
API_FIELD_NAME
]))
{
$result
[
MSG_CONTENT
]
.
=
"<p>"
.
$answer
[
API_FIELD_NAME
]
.
" : "
.
$answer
[
API_FIELD_MESSAGE
]
.
"</p>"
;
}
}
}
if
(
isset
(
$result
[
MSG_HEADER
])
&&
$result
[
MSG_HEADER
]
!==
''
)
{
// Sent header, if given.
if
(
$result
[
MSG_HEADER
]
!==
''
)
{
header
(
$result
[
MSG_HEADER
]);
}
...
...
extension/qfq/qfq/QuickFormQuery.php
View file @
eefd1188
...
...
@@ -236,7 +236,7 @@ class QuickFormQuery {
// FORM_DELETE without a form definition: Fake the form wiht only a tableName.
$table
=
$this
->
store
->
getVar
(
SIP_TABLE
,
STORE_SIP
);
if
(
$table
===
false
)
{
return
''
;
throw
new
UserFormException
(
"No 'form' and no 'table' definition found."
,
ERROR_MISSING_VALUE
)
;
}
$sipFound
=
true
;
$this
->
formSpec
[
F_NAME
]
=
''
;
...
...
@@ -655,11 +655,14 @@ class QuickFormQuery {
/**
* Delete a record (tablename and recordid are given) or process a 'delete form'
*
* @return bool
* @throws CodeException
*/
public
function
delete
()
{
$this
->
doForm
(
FORM_DELETE
);
return
true
;
}
/**
...
...
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