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
a6e1e072
Commit
a6e1e072
authored
Jul 23, 2017
by
Carsten Rose
Browse files
recordLocking
Dirty.php: add comments. Add timeout checking
parent
ecce620b
Changes
3
Hide whitespace changes
Inline
Side-by-side
extension/qfq/qfq/Constants.php
View file @
a6e1e072
...
...
@@ -213,7 +213,7 @@ const ERROR_UPLOAD = 1500;
const
ERROR_UPLOAD_TOO_BIG
=
1501
;
const
ERROR_UPLOAD_FILE_TYPE
=
1502
;
const
ERROR_UPLOAD_GET_MIME_TYPE
=
1503
;
const
ERROR_UNKNOWN_ACTION
=
1504
;
const
ERROR_
UPLOAD_
UNKNOWN_ACTION
=
1504
;
const
ERROR_NO_TARGET_PATH_FILE_NAME
=
1505
;
// LDAP
...
...
@@ -255,8 +255,9 @@ const ERROR_DB_MULTI_QUERY_FAILED = 2016;
const
ERROR_SUBSTITUTE_FOUND
=
2100
;
// Dirty
const
ERROR_MISSING_FORM_IN_SIP
=
2200
;
const
ERROR_DELETE_DIRTY_RECORD
=
2201
;
const
ERROR_DIRTY_MISSING_FORM_IN_SIP
=
2200
;
const
ERROR_DIRTY_DELETE_RECORD
=
2201
;
const
ERROR_DIRTY_UNKNOWN_ACTION
=
2202
;
//
// Store Names: Identifier
...
...
extension/qfq/qfq/File.php
View file @
a6e1e072
...
...
@@ -67,7 +67,7 @@ class File {
$this
->
doDelete
(
$sipUpload
,
$statusUpload
);
break
;
default
:
throw
new
UserFormException
(
"Unknown FILE_ACTION:
$action
"
,
ERROR_UNKNOWN_ACTION
);
throw
new
UserFormException
(
"Unknown FILE_ACTION:
$action
"
,
ERROR_
UPLOAD_
UNKNOWN_ACTION
);
}
}
...
...
extension/qfq/qfq/form/Dirty.php
View file @
a6e1e072
...
...
@@ -15,7 +15,14 @@ require_once(__DIR__ . '/../Constants.php');
require_once
(
__DIR__
.
'/../database/Database.php'
);
require_once
(
__DIR__
.
'/../../qfq/store/Client.php'
);
/**
* Class Dirty
* Process Record locking in mode DIRTY_MODE_ADVISORY, DIRTY_MODE_EXCLUSIVE or DIRTY_MODE_NONE.
* Two entry points: process() and checkDirtyAndRelease().
* Check doc/diagram/*.png for detailed workflow.
*
* @package qfq
*/
class
Dirty
{
/**
...
...
@@ -39,7 +46,7 @@ class Dirty {
private
$lockTimeout
=
false
;
/**
*
*
Init class
*/
public
function
__construct
(
$lockTimeout
=
false
,
$phpUnit
=
false
)
{
...
...
@@ -56,13 +63,14 @@ class Dirty {
}
/**
* Handle any lock requests submitted via api/dirty.php.
*
* @return array|int
* @throws CodeException
* @throws DbException
* @throws UserFormException
*/
public
function
process
()
{
$answer
=
array
();
$tableVars
=
array
();
$sipClass
=
new
Sip
();
...
...
@@ -70,7 +78,7 @@ class Dirty {
$sipVars
=
$sipClass
->
getVarsFromSip
(
$this
->
client
[
SIP_SIP
]);
if
(
empty
(
$sipVars
[
SIP_FORM
]))
{
throw
new
CodeException
(
"Missing 'form' in SIP. There might be something broken."
,
ERROR_MISSING_FORM_IN_SIP
);
throw
new
CodeException
(
"Missing 'form' in SIP. There might be something broken."
,
ERROR_
DIRTY_
MISSING_FORM_IN_SIP
);
}
$recordId
=
empty
(
$sipVars
[
SIP_RECORD_ID
])
?
0
:
$sipVars
[
SIP_RECORD_ID
];
...
...
@@ -86,6 +94,7 @@ class Dirty {
$answer
=
$this
->
checkDirtyAndRelease
(
FORM_SAVE
,
$tableVars
[
F_DIRTY_MODE
],
$tableVars
[
F_TABLE_NAME
],
$recordId
);
break
;
default
;
throw
new
CodeException
(
"Unknown action: "
.
$this
->
client
[
API_LOCK_ACTION
],
ERROR_DIRTY_UNKNOWN_ACTION
);
}
return
$answer
;
...
...
@@ -104,8 +113,6 @@ class Dirty {
*/
private
function
acquireDirty
(
$recordId
,
array
$tableVars
)
{
$answer
=
array
();
// For r=0 (new) , 'dirty' will always succeed.
if
(
$recordId
==
0
)
{
return
[
API_STATUS
=>
'success'
,
API_MESSAGE
=>
''
];
...
...
@@ -119,6 +126,15 @@ class Dirty {
// Look for already existing dirty record.
$recordDirty
=
$this
->
getRecordDirty
(
$tableName
,
$recordId
);
// Check if the record is timed out
if
(
count
(
$recordDirty
)
!=
0
&&
$this
->
lockTimeout
>
0
)
{
$datetimeExpire
=
date_add
(
date_create
(
$recordDirty
[
COLUMN_MODIFIED
]),
date_interval_create_from_date_string
(
$this
->
lockTimeout
.
" second"
));
if
(
$datetimeExpire
<=
date_create
(
"now"
))
{
$this
->
deleteDirtyRecord
(
$recordDirty
[
COLUMN_ID
]);
$recordDirty
=
array
();
}
}
if
(
count
(
$recordDirty
)
==
0
)
{
// No dirty record found.
$answer
=
$this
->
writeDirty
(
$this
->
client
[
SIP_SIP
],
$recordId
,
$tableName
,
$formDirtyMode
,
$feUser
);
...
...
@@ -148,6 +164,7 @@ class Dirty {
}
/**
*
* @param array $recordDirty
* @param $currentFormDirtyMode
* @return array
...
...
@@ -290,7 +307,7 @@ class Dirty {
private
function
deleteDirtyRecord
(
$recordDirtyId
)
{
$cnt
=
$this
->
db
->
sql
(
'DELETE FROM Dirty WHERE id=? LIMIT 1'
,
ROW_REGULAR
,
[
$recordDirtyId
]);
if
(
$cnt
!=
1
)
{
throw
new
CodeException
(
"Failed to delete dirty record id="
.
$recordDirtyId
,
ERROR_D
ELETE_DIRTY
_RECORD
);
throw
new
CodeException
(
"Failed to delete dirty record id="
.
$recordDirtyId
,
ERROR_D
IRTY_DELETE
_RECORD
);
}
}
}
\ No newline at end of file
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