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