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
f5013b3b
Commit
f5013b3b
authored
Aug 27, 2020
by
Carsten Rose
Browse files
Merge branch 'F10979AjaxCallsAnAPI-DataReport' into 'develop'
F10979 ajax calls an api data report See merge request
!277
parents
44c8b761
1ed25e87
Pipeline
#3727
passed with stages
in 3 minutes and 57 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
extension/Classes/Api/dataReport.php
0 → 100644
View file @
f5013b3b
<?php
/**
* Created by PhpStorm.
* User: crose
* Date: 08/09/20
* Time: 6:17 PM
*/
namespace
IMATHUZH\Qfq\Api
;
require_once
(
__DIR__
.
'/../../vendor/autoload.php'
);
use
IMATHUZH\Qfq\Core\QuickFormQuery
;
/**
* Return JSON encoded answer
*
* status: success|error
* message: <message>
* redirect: client|url|no
* redirect-url: <url>
*
* Description:
*
* Save successful.
*
*/
$answer
=
array
();
$answer
[
API_REDIRECT
]
=
API_ANSWER_REDIRECT_NO
;
$answer
[
API_STATUS
]
=
API_ANSWER_STATUS_ERROR
;
$answer
[
API_MESSAGE
]
=
''
;
$status
=
HTTP_400_BAD_REQUEST
;
try
{
try
{
$qfq
=
new
QuickFormQuery
([
'bodytext'
=>
''
]);
$data
=
$qfq
->
dataReport
();
$status
=
HTTP_200_OK
;
}
catch
(
\
UserReportException
$e
)
{
$answer
[
API_MESSAGE
]
=
$e
->
formatMessage
();
}
catch
(
\
CodeException
$e
)
{
$answer
[
API_MESSAGE
]
=
$e
->
formatMessage
();
}
catch
(
\
DbException
$e
)
{
$answer
[
API_MESSAGE
]
=
$e
->
formatMessage
();
}
}
catch
(
\
Exception
$e
)
{
$answer
[
API_MESSAGE
]
=
"Generic Exception: "
.
$e
->
getMessage
();
}
//header('HTTP/1.0 ' . $status);
//header("Content-Type: application/json");
//echo json_encode($answer);
echo
$data
;
\ No newline at end of file
extension/Classes/Core/Database/Database.php
View file @
f5013b3b
...
...
@@ -175,13 +175,13 @@ class Database {
* Else an exception. ROW_EXPECT_GE_1: Like 'ROW_REGULAR'. Throws an exception if there is an empty resultset.
* ROW_KEYS: Return 2-dimensional num(!) array. Every query row is one array row. $keys are the column names.
*
* @param
$sql
* @param
string
$sql
* @param string $mode
* @param array $parameterArray
* @param string $specificMessage
* @param array $keys
* @param array $stat DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
* @param array $skipErrno
* @param array $skipErrno
Array of ERRNO numbers, which should be skipped and not throw an error.
*
* @return array|int
* SELECT | SHOW | DESCRIBE | EXPLAIN: see $mode
...
...
@@ -349,7 +349,7 @@ class Database {
* the query.
* @param array $stat DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
* @param string $specificMessage
* @param array $skipErrno
* @param array $skipErrno
Array of ERRNO numbers, which should be skipped and not throw an error.
*
* @return int|mixed
* @throws \CodeException
...
...
@@ -360,8 +360,6 @@ class Database {
$sqlLogMode
=
$this
->
isSqlModify
(
$sql
)
?
SQL_LOG_MODE_MODIFY
:
SQL_LOG_MODE_ALL
;
$errno
=
0
;
$result
=
0
;
$stat
=
array
();
$errorMsg
[
ERROR_MESSAGE_TO_USER
]
=
empty
(
$specificMessage
)
?
'SQL error'
:
$specificMessage
;
...
...
@@ -370,53 +368,44 @@ class Database {
$this
->
store
->
setVar
(
SYSTEM_SQL_PARAM_ARRAY
,
$parameterArray
,
STORE_SYSTEM
);
}
// if ($specificMessage !== '') {
// $specificMessage = ' - ' . $specificMessage;
// }
// Logfile
$this
->
dbLog
(
$sqlLogMode
,
$sql
,
$parameterArray
);
if
(
false
===
(
$this
->
mysqli_stmt
=
$this
->
mysqli
->
prepare
(
$sql
)))
{
if
(
$skipErrno
===
array
()
&&
false
===
array_search
(
$
this
->
mysqli
->
errno
,
$skipErrno
))
{
$errno
=
$this
->
mysqli
->
errno
;
if
(
$skipErrno
===
array
()
&&
false
===
array_search
(
$errno
,
$skipErrno
))
{
$this
->
dbLog
(
SQL_LOG_MODE_ERROR
,
$sql
,
$parameterArray
);
$errorMsg
[
ERROR_MESSAGE_TO_DEVELOPER
]
=
$this
->
getSqlHint
(
$sql
,
$this
->
mysqli
->
error
);
$errorMsg
[
ERROR_MESSAGE_OS
]
=
'[ mysqli: '
.
$
this
->
mysqli
->
errno
.
' ] '
.
$this
->
mysqli
->
error
;
$errorMsg
[
ERROR_MESSAGE_OS
]
=
'[ mysqli: '
.
$errno
.
' ] '
.
$this
->
mysqli
->
error
;
throw
new
\
DbException
(
json_encode
(
$errorMsg
),
ERROR_DB_PREPARE
);
}
else
{
$errno
=
$this
->
mysqli
->
errno
;
}
}
if
(
count
(
$parameterArray
)
>
0
)
{
if
(
false
===
$this
->
prepareBindParam
(
$parameterArray
))
{
if
(
$skipErrno
!==
array
()
&&
false
===
array_search
(
$this
->
mysqli
->
errno
,
$skipErrno
))
{
$errno
=
$this
->
mysqli_stmt
->
errno
;
if
(
$skipErrno
===
array
()
&&
false
===
array_search
(
$errno
,
$skipErrno
))
{
$this
->
dbLog
(
SQL_LOG_MODE_ERROR
,
$sql
,
$parameterArray
);
$errorMsg
[
ERROR_MESSAGE_TO_DEVELOPER
]
=
$this
->
getSqlHint
(
$sql
,
$this
->
mysqli
->
error
);
$errorMsg
[
ERROR_MESSAGE_OS
]
=
'[ mysqli: '
.
$
this
->
mysqli_stmt
->
errno
.
' ] '
.
$this
->
mysqli_stmt
->
error
;
$errorMsg
[
ERROR_MESSAGE_OS
]
=
'[ mysqli: '
.
$errno
.
' ] '
.
$this
->
mysqli_stmt
->
error
;
throw
new
\
DbException
(
json_encode
(
$errorMsg
),
ERROR_DB_BIND
);
}
else
{
$errno
=
$this
->
mysqli
->
errno
;
}
}
}
if
(
false
===
$this
->
mysqli_stmt
->
execute
())
{
if
(
$skipErrno
!==
array
()
&&
false
===
array_search
(
$this
->
mysqli
->
errno
,
$skipErrno
))
{
$errno
=
$this
->
mysqli
->
errno
;
if
(
$skipErrno
===
array
()
||
false
===
array_search
(
$errno
,
$skipErrno
))
{
$this
->
dbLog
(
SQL_LOG_MODE_ERROR
,
$sql
,
$parameterArray
);
$errorMsg
[
ERROR_MESSAGE_TO_DEVELOPER
]
=
$this
->
getSqlHint
(
$sql
,
$this
->
mysqli
->
error
);
$errorMsg
[
ERROR_MESSAGE_OS
]
=
'[ mysqli: '
.
$this
->
mysqli_stmt
->
errno
.
' ] '
.
$this
->
mysqli_stmt
->
error
;
throw
new
\
DbException
(
json_encode
(
$errorMsg
),
ERROR_DB_EXECUTE
);
}
else
{
$errno
=
$this
->
mysqli
->
errno
;
}
}
$msg
=
''
;
$count
=
0
;
if
(
$errno
===
0
)
{
$command
=
strtoupper
(
explode
(
' '
,
$sql
,
2
)[
0
]);
}
else
{
...
...
extension/Classes/Core/QuickFormQuery.php
View file @
f5013b3b
...
...
@@ -1939,6 +1939,55 @@ class QuickFormQuery {
}
}
/**
* Process given tt-content record triggered by AJAX Call
*
* @return string
* @throws \CodeException
* @throws \DbException
* @throws \DownloadException
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
* @throws \UserFormException
* @throws \UserReportException
*/
public
function
dataReport
()
{
$uid
=
Store
::
getVar
(
NAME_UID
,
STORE_SIP
.
STORE_CLIENT
.
STORE_ZERO
,
SANITIZE_ALLOW_DIGIT
);
return
$this
->
getEvaluatedBodyText
(
$uid
);
}
/**
* @param $uid
*
* @return string
* @throws \CodeException
* @throws \DbException
* @throws \DownloadException
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
* @throws \UserFormException
* @throws \UserReportException
*/
private
function
getEvaluatedBodyText
(
$uid
)
{
$dbT3
=
$this
->
store
->
getVar
(
SYSTEM_DB_NAME_T3
,
STORE_SYSTEM
);
$sql
=
"SELECT `bodytext` FROM `
$dbT3
`.`tt_content` WHERE `uid` = ?"
;
$tt_content
=
$this
->
dbArray
[
$this
->
dbIndexQfq
]
->
sql
(
$sql
,
ROW_EXPECT_1
,
[
$uid
]);
$qfq
=
new
QuickFormQuery
([
T3DATA_BODYTEXT
=>
$tt_content
[
T3DATA_BODYTEXT
]],
false
,
false
);
return
$qfq
->
process
();
}
/**
* Delete a record (tablename and recordid are given) or process a 'delete form'
*
...
...
@@ -1956,7 +2005,6 @@ class QuickFormQuery {
* @throws \UserReportException
*/
public
function
delete
()
{
return
$this
->
doForm
(
FORM_DELETE
);
}
...
...
extension/Classes/Core/Report/Download.php
View file @
f5013b3b
...
...
@@ -461,7 +461,7 @@ class Download {
* @throws \UserFormException
* @throws \UserReportException
*/
private
function
getEvaluatedBodyText
(
$uid
,
$urlParam
)
{
private
function
getEvaluatedBodyText
(
$uid
,
array
$urlParam
)
{
foreach
(
$urlParam
as
$key
=>
$paramValue
)
{
$this
->
store
->
setVar
(
$key
,
$paramValue
,
STORE_SIP
);
}
...
...
extension/Tests/Unit/Core/Database/DatabaseTest.php
View file @
f5013b3b
...
...
@@ -242,6 +242,17 @@ class DatabaseTest extends AbstractDatabaseTest {
$this
->
dbArray
[
DB_INDEX_DEFAULT
]
->
sql
(
'some garbage'
);
}
/**
* @expectedException DbException
*
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
*/
public
function
testReportException
()
{
$this
->
dbArray
[
DB_INDEX_DEFAULT
]
->
sql
(
"INSERT INTO Person (`id`,`name`) VALUES (1,'test')"
);
}
/**
* Check to skip mysqli errno 1060
*
...
...
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