Commit 1c65cdf7 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Bug #4174 / record locking: error message if delete fails due to record locking

delete.php: process json answer of qfq-delete()
Dirty.php: More specific error message. In case of locking problem during form delete - return json and not an exception.
QuickFormDirty.php: Code cleanup. Interpret answer of dirty->checkDirtyAndRelease
parent 5b94bb37
......@@ -76,17 +76,24 @@ try {
$qfq = new \qfq\QuickFormQuery(['bodytext' => '']);
$flagSuccess = $qfq->delete();
$answer = $qfq->delete();
// in case everything is fine, an empty string is returned. Else an Array.
$flagSuccess = ($answer == '');
$targetUrl = Store::getVar(SIP_TARGET_URL, STORE_SIP);
$modeAnswer = Store::getVar(SIP_MODE_ANSWER, STORE_SIP);
switch ($modeAnswer) {
case MODE_JSON:
if ($flagSuccess) {
$answer[API_MESSAGE] = 'delete: success';
$answer[API_REDIRECT] = API_ANSWER_REDIRECT_CLIENT;
$answer[API_STATUS] = API_ANSWER_STATUS_SUCCESS;
} else {
$answer[API_STATUS] = API_ANSWER_STATUS_ERROR;
}
$answer[API_MESSAGE] = 'delete: success';
$answer[API_REDIRECT] = API_ANSWER_REDIRECT_CLIENT;
$answer[API_STATUS] = API_ANSWER_STATUS_SUCCESS;
break;
case MODE_HTML:
......@@ -94,7 +101,9 @@ try {
throw new CodeException('Missing target URL', ERROR_MISSING_VALUE);
}
$result[MSG_HEADER] = "Location: $targetUrl";
if ($flagSuccess) {
$result[MSG_HEADER] = "Location: $targetUrl";
}
break;
default:
......
......@@ -269,25 +269,15 @@ class QuickFormQuery {
// Check (and release) dirtyRecord.
if ($formMode === FORM_DELETE || $formMode === FORM_SAVE) {
$recordDirty = array();
$dirty = new Dirty();
// Comment as long as long as 4127 is open
$dirty->checkDirtyAndRelease($formMode, $this->formSpec[F_RECORD_LOCK_TIMEOUT_SECONDS],
$answer = $dirty->checkDirtyAndRelease($formMode, $this->formSpec[F_RECORD_LOCK_TIMEOUT_SECONDS],
$this->formSpec[F_DIRTY_MODE], $this->formSpec[F_TABLE_NAME], $recordId);
//
// $lockStatus = $dirty->getCheckDirty($this->formSpec[F_TABLE_NAME], $recordId, $recordDirty, $msg);
// switch ($lockStatus) {
// case LOCK_NOT_FOUND:
// if ($this->formSpec[F_DIRTY_MODE] != DIRTY_MODE_NONE) {
// throw new UserFormException("Missing record lock: please reload the form, edit and save again.", ERROR_DIRTY_MISSING_LOCK);
// }
// break;
// case LOCK_FOUND_CONFLICT:
// throw new UserFormException($msg, ERROR_DIRTY_ALREADY_LOCKED);
// case LOCK_FOUND_OWNER:
// break;
// default:
// }
// in case of a conflict, return immediately
if($answer[API_STATUS]!= API_ANSWER_STATUS_SUCCESS) {
return $answer;
}
}
if ($formMode === FORM_DELETE) {
......@@ -994,14 +984,13 @@ class QuickFormQuery {
/**
* Delete a record (tablename and recordid are given) or process a 'delete form'
*
* @return bool
* @return array
* @throws CodeException
*/
public function delete() {
$this->doForm(FORM_DELETE);
return $this->doForm(FORM_DELETE);
return true;
}
/**
......
......@@ -268,14 +268,18 @@ class Dirty {
return LOCK_NOT_FOUND;
}
// Is the dirtyRecord mine?
if ($recordDirty[DIRTY_QFQ_USER_SESSION_COOKIE] == $this->client[CLIENT_COOKIE_QFQ]) {
return LOCK_FOUND_OWNER;
$msgUser = "you";
} else {
$msgUser = (empty($recordDirty[DIRTY_FE_USER])) ? "another user" : "user '$recordDirty[DIRTY_FE_USER]'";
$msgAt = "at " . $recordDirty[COLUMN_CREATED] . " from " . $recordDirty[DIRTY_REMOTE_ADDRESS];
$msg = "The record has been locked by $msgUser $msgAt";
}
$msgAt = "at " . $recordDirty[COLUMN_CREATED] . " from " . $recordDirty[DIRTY_REMOTE_ADDRESS];
$msg = "The record has been locked by $msgUser $msgAt";
// Is the dirtyRecord mine?
if ($recordDirty[DIRTY_QFQ_USER_SESSION_COOKIE] == $this->client[CLIENT_COOKIE_QFQ]) {
return LOCK_FOUND_OWNER;
} else {
return LOCK_FOUND_CONFLICT;
}
}
......@@ -304,7 +308,6 @@ class Dirty {
return $answer; // New records never have a recordDirty nor a conflict.
}
// $recordDirty = $this->getRecordDirty($tableName, $recordId);
$lockStatus = $this->getCheckDirty($tableName, $recordId, $recordDirty, $msg);
if (empty($recordDirty)) {
......@@ -320,7 +323,15 @@ class Dirty {
}
if ($formMode == FORM_DELETE) {
throw new UserFormException($msg, ERROR_DIRTY_ALREADY_LOCKED);
// Check if the record is timed out
if ( $lockTimeout > 0 && $recordDirty[DIRTY_EXPIRE] < date('Y-m-d H:i:s')) {
$this->deleteDirtyRecord($recordDirty[COLUMN_ID]);
return $answer;
}
$answer = [API_STATUS => API_ANSWER_STATUS_CONFLICT, API_MESSAGE => $msg];
return $answer;
}
// Is the dirtyRecord mine?
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment