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

FEAT #10769 TIME 1:30 Handle user when deleted

parent c0903ee2
No related branches found
No related tags found
No related merge requests found
...@@ -125,7 +125,7 @@ CREATE TABLE history ...@@ -125,7 +125,7 @@ CREATE TABLE history
object_type CHARACTER VARYING(128) NOT NULL, object_type CHARACTER VARYING(128) NOT NULL,
object_id CHARACTER VARYING(32) NOT NULL, object_id CHARACTER VARYING(32) NOT NULL,
type CHARACTER VARYING(64) NOT NULL, type CHARACTER VARYING(64) NOT NULL,
user_id INTEGER NOT NULL, "user" text NOT NULL,
date TIMESTAMP without TIME ZONE NOT NULL, date TIMESTAMP without TIME ZONE NOT NULL,
message text NOT NULL, message text NOT NULL,
data jsonb NOT NULL DEFAULT '{}', data jsonb NOT NULL DEFAULT '{}',
......
...@@ -156,10 +156,9 @@ class DocumentController ...@@ -156,10 +156,9 @@ class DocumentController
$date = new \DateTime($document['process_date']); $date = new \DateTime($document['process_date']);
$value['process_date'] = $date->format('d-m-Y H:i'); $value['process_date'] = $date->format('d-m-Y H:i');
} }
$user = UserModel::getById(['select' => ['id', 'firstname', 'lastname'], 'id' => $value['user_id']]);
$formattedDocument['workflow'][] = [ $formattedDocument['workflow'][] = [
'userId' => $user['id'], 'userId' => $value['user_id'],
'userDisplay' => "{$user['firstname']} {$user['lastname']}", 'userDisplay' => UserModel::getLabelledUserById(['id' => $value['user_id']]),
'mode' => $value['mode'], 'mode' => $value['mode'],
'processDate' => $value['process_date'], 'processDate' => $value['process_date'],
'current' => !$currentFound && empty($value['process_date']) 'current' => !$currentFound && empty($value['process_date'])
......
...@@ -38,7 +38,7 @@ class HistoryController ...@@ -38,7 +38,7 @@ class HistoryController
'object_type' => $args['objectType'], 'object_type' => $args['objectType'],
'object_id' => $args['objectId'], 'object_id' => $args['objectId'],
'type' => $args['type'], 'type' => $args['type'],
'user_id' => $GLOBALS['id'], 'user' => UserModel::getLabelledUserById(['id' => $GLOBALS['id']]),
'message' => $args['message'], 'message' => $args['message'],
'data' => empty($args['data']) ? '{}' : json_encode($args['data']), 'data' => empty($args['data']) ? '{}' : json_encode($args['data']),
'ip' => empty($_SERVER['REMOTE_ADDR']) ? 'script' : $_SERVER['REMOTE_ADDR'] 'ip' => empty($_SERVER['REMOTE_ADDR']) ? 'script' : $_SERVER['REMOTE_ADDR']
...@@ -59,7 +59,7 @@ class HistoryController ...@@ -59,7 +59,7 @@ class HistoryController
} }
$history = HistoryModel::get([ $history = HistoryModel::get([
'select' => ['code', 'type', 'user_id', 'date', 'message', 'data'], 'select' => ['code', 'type', '"user"', 'date', 'message', 'data'],
'where' => ["(object_type = ? AND object_id = ?) OR (data->>'mainDocumentId' = ?)"], 'where' => ["(object_type = ? AND object_id = ?) OR (data->>'mainDocumentId' = ?)"],
'data' => ['main_documents', $args['id'], $args['id']], 'data' => ['main_documents', $args['id'], $args['id']],
'orderBy' => ['date'] 'orderBy' => ['date']
...@@ -76,13 +76,12 @@ class HistoryController ...@@ -76,13 +76,12 @@ class HistoryController
} }
foreach ($history as $value) { foreach ($history as $value) {
$user = UserModel::getById(['select' => ['login'], 'id' => $value['user_id']]);
$date = new \DateTime($value['date']); $date = new \DateTime($value['date']);
$formattedHistory[] = [ $formattedHistory[] = [
'code' => $value['code'], 'code' => $value['code'],
'type' => $value['type'], 'type' => $value['type'],
'userLogin' => $user['login'], 'user' => $value['user'],
'date' => $date->format('d-m-Y H:i'), 'date' => $date->format('d-m-Y H:i'),
'message' => preg_replace($langKeys, $langValues, $value['message']), 'message' => preg_replace($langKeys, $langValues, $value['message']),
'data' => json_decode($value['data'], true) 'data' => json_decode($value['data'], true)
......
...@@ -40,9 +40,8 @@ class HistoryModel ...@@ -40,9 +40,8 @@ class HistoryModel
public static function create(array $args) public static function create(array $args)
{ {
ValidatorModel::notEmpty($args, ['code', 'object_type', 'object_id', 'type', 'user_id', 'message', 'data', 'ip']); ValidatorModel::notEmpty($args, ['code', 'object_type', 'object_id', 'type', 'user', 'message', 'data', 'ip']);
ValidatorModel::stringType($args, ['code', 'objectType', 'type', 'message', 'data', 'ip']); ValidatorModel::stringType($args, ['code', 'object_type', 'type', 'user', 'message', 'data', 'ip']);
ValidatorModel::intVal($args, ['user_id']);
DatabaseModel::insert([ DatabaseModel::insert([
'table' => 'history', 'table' => 'history',
...@@ -51,7 +50,7 @@ class HistoryModel ...@@ -51,7 +50,7 @@ class HistoryModel
'object_type' => $args['object_type'], 'object_type' => $args['object_type'],
'object_id' => $args['object_id'], 'object_id' => $args['object_id'],
'type' => $args['type'], 'type' => $args['type'],
'user_id' => $args['user_id'], '"user"' => $args['user'],
'date' => 'CURRENT_TIMESTAMP', 'date' => 'CURRENT_TIMESTAMP',
'message' => $args['message'], 'message' => $args['message'],
'data' => $args['data'], 'data' => $args['data'],
......
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