forked from Dolibarr/dolibarr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX Dolibarr#32791 Lost user and THM when updating task time
# 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
Showing
2 changed files
with
26 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]> | ||
* | ||
|
@@ -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'); | ||
|
@@ -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')) { | ||
|
@@ -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'))) { | ||
|