Loading...
 
Skip to main content

Username rename in trackers doesn't work when there are multiple values

Status
Closed
Subject
Username rename in trackers doesn't work when there are multiple values
Version
17.x
Category
  • Consistency
Feature
Trackers
Resolution status
Fixed or Solved
Submitted by
Bernard Sfez / Tiki Specialist
Volunteered to solve
Andres Valero
Lastmod by
Andres Valero
Rating
(0)
Description
Username rename in trackers doesn't work when there are multiple values.
Solution

Hello!
I solved this issue modifying the function change_login located in the lib/userslib.php file.
This is the output of the svn diff:

svn diff
Copy to clipboard
Index: lib/userslib.php =================================================================== --- lib/userslib.php (revision 62864) +++ lib/userslib.php (working copy) @@ -2697,27 +2697,48 @@ $this->query('update `tiki_object_relations` set `target_itemId`=? where target_type="user" and `target_itemId`=?', array($to, $from)); $this->query('update `tiki_freetagged_objects` set `user`=? where `user`=?', array($to, $from)); - $this->query( - 'update `tiki_tracker_item_fields`ttif' . - ' left join `tiki_tracker_fields` ttf on (ttif.`fieldId`=ttf.`fieldId`)' . - ' set `value`=? where ttif.`value`=? and ttf.`type`=?', - array($to, $from, 'u') - ); $this->query('update `tiki_tracker_items` set `createdBy`=? where `createdBy`=?', array($to, $from)); $this->query('update `tiki_tracker_items` set `lastModifBy`=? where `lastModifBy`=?', array($to, $from)); - $result = $this->query("select `fieldId`, `itemChoices` from `tiki_tracker_fields` where `type`='u'"); - + $result = $this->query("select ttif.`itemId`, ttf.`fieldId`, ttf.`itemChoices`, ttif.value from `tiki_tracker_fields` ttf + LEFT JOIN `tiki_tracker_item_fields` ttif + on (ttif.`fieldId`=ttf.`fieldId`) + where ttf.`type`='u'"); + $resFieldIdAnt = ""; while ($res = $result->fetchRow()) { - $this->query('update `tiki_tracker_item_fields` set `value`=? where `value`=? and `fieldId`=?', array($to, $from, $res['fieldId'])); - $u = ($res['itemChoices'] != '' ) ? unserialize($res['itemChoices']) : array(); + $values = explode(",", $res['value']); - if ($value = array_search($from, $u)) { - $u[$value] = $to; - $u = serialize($u); - $this->query('update `tiki_tracker_fields` set `itemChoices`=? where `fieldId`=?', array($u, $res['fieldId'])); + if(count($values)>1){//Check if is a list of comma separated values + + if ($v = array_search($from, $values)) { + $values[$v] = $to; + $fromAux = $res['value']; + $toAux = implode(",", $values); + $this->query('update `tiki_tracker_item_fields` set `value`=? where `value`=? and `fieldId`=? and `itemId`=? ', array($toAux, $fromAux, $res['fieldId'],$res['itemId'])); + } + + }else{//Is a unique value + + if($res['value'] == $from){ + $this->query('update `tiki_tracker_item_fields` set `value`=? where `value`=? and `fieldId`=? and `itemId`=? ', array($to, $from, $res['fieldId'],$res['itemId'])); + } + } + + //Avoiding make the same query many times. + if($resFieldIdAnt!=$res['fieldId']){ + + $u = ($res['itemChoices'] != '' ) ? unserialize($res['itemChoices']) : array(); + + if ($value = array_search($from, $u)) { + $u[$value] = $to; + $u = serialize($u); + $this->query('update `tiki_tracker_fields` set `itemChoices`=? where `fieldId`=?', array($u, $res['fieldId'])); + } + + } + $resFieldIdAnt = $res['fieldId']; } $cachelib->invalidate('userslist'); TikiLib::events()->trigger('tiki.user.update', array('type' => 'user', 'object' => $from));


I didn't did the commit yet because is my first commit and I want you to check it 😊

Importance
5
Easy to solve?
5
Priority
25
Demonstrate Bug on Tiki 19+
Demonstrate Bug (older Tiki versions)
Ticket ID
6326
Created
Monday 24 April, 2017 12:35:16 UTC
by Bernard Sfez / Tiki Specialist
LastModif
Wednesday 06 January, 2021 17:05:46 UTC


Show PHP error messages