Skip to content

Commit

Permalink
FIX Dolibarr#32791 Lost user and THM when updating task time
Browse files Browse the repository at this point in the history
# FIX Dolibarr#32791 Lost user and THM when updating task time

The task time was assigned the user '0' when updating, which resulted in an
error where a NULL object was used.
This resulted in a partially replaced record with no user and empty THM.

The correction adds the use of a DB transaction to avoid inconsistency in case
of an error.
The correction uses the fields from the original record if no new fields
are provided in the POST arguments
  • Loading branch information
mdeweerd committed Jan 28, 2025
1 parent b25e19e commit b14d1e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
8 changes: 4 additions & 4 deletions htdocs/projet/class/task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Copyright (C) 2020 Juanjo Menent <[email protected]>
* Copyright (C) 2022 Charlene Benke <[email protected]>
* Copyright (C) 2023 Gauthier VERDOL <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1417,9 +1417,9 @@ public function mergeTimeSpentTask($origin_id, $dest_id)
/**
* Add time spent
*
* @param User $user User object
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int Return integer <=0 if KO, >0 if OK
* @param User $user User object
* @param int<0,1> $notrigger 0=launch triggers after, 1=disable triggers
* @return int Return integer <=0 if KO, >0 if OK
*/
public function addTimeSpent($user, $notrigger = 0)
{
Expand Down
27 changes: 22 additions & 5 deletions htdocs/projet/tasks/time.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Copyright (C) 2018 Frédéric France <[email protected]>
* Copyright (C) 2019-2021 Christophe Battarel <[email protected]>
* Copyright (C) 2023 Gauthier VERDOL <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
* Copyright (C) 2024 Vincent de Grandpré <[email protected]>
* Copyright (C) 2024 Solution Libre SAS <[email protected]>
*
Expand Down Expand Up @@ -270,6 +270,7 @@

if (($action == 'updateline' || $action == 'updatesplitline') && !$cancel && $user->hasRight('projet', 'lire')) {
$error = 0;
$db->begin();

if (!GETPOST("new_durationhour") && !GETPOST("new_durationmin")) {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Duration")), null, 'errors');
Expand Down Expand Up @@ -300,10 +301,21 @@
} else {
$object->timespent_date = dol_mktime(12, 0, 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear"));
}
$object->timespent_fk_user = GETPOSTINT("userid_line");
$object->timespent_fk_product = GETPOSTINT("fk_product");
$object->timespent_invoiceid = GETPOSTINT("invoiceid");
$object->timespent_invoicelineid = GETPOSTINT("invoicelineid");

// Use fields from existing record or from post (if provided)
if (GETPOST("userid_line") != '') {
$object->timespent_fk_user = GETPOSTINT("userid_line");
}
if (GETPOST("fk_product") != '') {
$object->timespent_fk_product = GETPOSTINT("fk_product");
}
if (GETPOST("invoiceid") != '') {
$object->timespent_invoiceid = GETPOSTINT("invoiceid");
}
if (GETPOST("invoicelineid") != '') {
$object->timespent_invoicelineid = GETPOSTINT("invoicelineid");
}


$result = 0;
if (in_array($object->timespent_fk_user, $childids) || $user->hasRight('projet', 'all', 'creer')) {
Expand Down Expand Up @@ -349,6 +361,11 @@
} else {
$action = '';
}
if ($error == 0) {
$db->commit();
} else {
$db->rollback();
}
}

if ($action == 'confirm_deleteline' && $confirm == "yes" && ($user->hasRight('projet', 'time') || $user->hasRight('projet', 'all', 'creer'))) {
Expand Down

0 comments on commit b14d1e1

Please sign in to comment.