Skip to content
Snippets Groups Projects
Verified Commit 3b9f2130 authored by Damien's avatar Damien
Browse files

FEAT #9105 Resource lock update

parent 3cb982b0
No related branches found
No related tags found
No related merge requests found
......@@ -493,32 +493,6 @@ class ResController
return $response->withJson(['success' => 'success']);
}
public function isLock(Request $request, Response $response, array $aArgs)
{
if (!ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$currentUser = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$resource = ResModel::getById(['resId' => $aArgs['resId'], 'select' => ['locker_user_id', 'locker_time']]);
$lock = true;
if (empty($resource['locker_user_id'] || empty($resource['locker_time']))) {
$lock = false;
} elseif ($resource['locker_user_id'] == $currentUser['id']) {
$lock = false;
} elseif (strtotime($resource['locker_time']) < time()) {
$lock = false;
}
$lockBy = '';
if ($lock) {
$lockBy = UserModel::getLabelledUserById(['id' => $resource['locker_user_id']]);
}
return $response->withJson(['lock' => $lock, 'lockBy' => $lockBy]);
}
public function lock(Request $request, Response $response, array $aArgs)
{
if (!ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) {
......@@ -542,6 +516,12 @@ class ResController
return $response->withStatus(403)->withJson(['lockBy' => $user]);
}
ResModel::update([
'set' => ['locker_user_id' => $currentUser['id'], 'locker_time' => 'CURRENT_TIMESTAMP + interval \'1\' MINUTE'],
'where' => ['res_id = ?'],
'data' => [$aArgs['resId']]
]);
return $response->withStatus(204);
}
......
......@@ -248,7 +248,7 @@ class DatabaseModel
$dataSet = [];
if (!empty($args['set'])) {
foreach ($args['set'] as $key => $value) {
if ($value == 'SYSDATE' || $value == 'CURRENT_TIMESTAMP') {
if ($value == 'SYSDATE' || strpos($value, 'CURRENT_TIMESTAMP') !== false) {
$querySet[] = "{$key} = {$value}";
} else {
$querySet[] = "{$key} = ?";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment