[TikiWiki-commits] [Git][tikiwiki/tiki][30.x] [FIX] Trackers: handle status history rows in item comments
"MAGENE Sem Joel \(@Jomagene\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a3133f6ee732_381964c8846d1@gitlab-sidekiq-low-urgency-cpu-bound-v2-7d87cb8569-shlv7.mail> |
MAGENE Sem Joel pushed to branch 30.x at Tiki Wiki CMS Groupware / Tiki
Commits:
cdc51eb8 by MAGENE Sem Joel at 2026-06-16T11:24:57+00:00
[FIX] Trackers: handle status history rows in item comments
---
* [FIX] Trackers: handle status history rows in item comments
---
* [FIX] Trackers: show deleted fields in item history
* [FIX] Trackers: handle status history rows in item comments
See merge request tikiwiki/tiki!10466
(cherry picked from commit efac367cd060176a0b91e3d89cdcf741a0425e7e)
See merge request tikiwiki/tiki!10531
- - - - -
8 changed files:
- lib/comments/commentslib.php
- lib/core/Services/Comment/Controller.php
- lib/core/Services/Tracker/Controller.php
- lib/trackers/trackerlib.php
- templates/comment/edit.tpl
- templates/comment/list_inner.tpl
- templates/comment/post.tpl
- templates/tracker/item_history.tpl
Changes:
=====================================
lib/comments/commentslib.php
=====================================
@@ -2674,11 +2674,6 @@ class Comments extends TikiLib
['version' => $ret[$key]['version']]
);
- foreach ($history['data'] as &$hist) {
- $field_info = TikiLib::lib('trk')->get_field_info($hist['fieldId']);
- $hist['fieldName'] = $field_info['name'];
- }
-
if (! empty($history['data'])) {
$ret[$key]['diffInfo'] = $history['data'];
}
=====================================
lib/core/Services/Comment/Controller.php
=====================================
@@ -926,13 +926,7 @@ class Services_Comment_Controller
['version' => $version]
);
- $diffInfo = [];
-
- foreach ($history['data'] as $info) {
- $field_info = $trackerLib->get_field_info($info['fieldId']);
- $info['fieldName'] = $field_info['name'];
- $diffInfo[] = $info;
- }
+ $diffInfo = $history['data'];
}
// add some specific js to set up comment post form in a modal dialog
// so it can refresh the page after the post
=====================================
lib/core/Services/Tracker/Controller.php
=====================================
@@ -2389,12 +2389,21 @@ class Services_Tracker_Controller
$has_initial_version = true;
}
if (empty($field_option[$hist['fieldId']])) {
- if ($hist['fieldId'] !== HISTLIB_INVALID_FIELDID_THAT_MEANS_TRACKER_ITEM_STATUS_CHANGE) {
+ if (! empty($hist['isDeletedField'])) {
+ $field_option[$hist['fieldId']] = [
+ 'type' => 't',
+ 'name' => $hist['fieldName'],
+ 'fieldId' => $hist['fieldId'],
+ 'trackerId' => $item_info['trackerId'],
+ 'visibleInHistoryMode' => 'y',
+ 'isDeletedField' => true,
+ ];
+ } elseif ($hist['fieldId'] !== HISTLIB_INVALID_FIELDID_THAT_MEANS_TRACKER_ITEM_STATUS_CHANGE) {
$field_option[$hist['fieldId']] = $trklib->get_tracker_field($hist['fieldId']);
} else {
$field_option[$hist['fieldId']] = [ // fake field to do the diff on
'type' => 't',
- 'name' => tr('Status'),
+ 'name' => $hist['fieldName'],
'fieldId' => $hist['fieldId'],
'trackerId' => $item_info['trackerId'],
];
@@ -2402,7 +2411,7 @@ class Services_Tracker_Controller
}
// Pre-render field values here in the controller, before Smarty starts rendering the template.
$field_value = $field_option[$hist['fieldId']];
- if (! empty($field_value['fieldId']) && $field_value['fieldId'] > 0) {
+ if (! empty($field_value['fieldId']) && $field_value['fieldId'] > 0 && empty($field_value['isDeletedField'])) {
$emptyTemplate = TikiLib::lib('smarty')->getEmptyInternalTemplate();
if (empty($diff_style)) {
$field_value['value'] = $hist['value'];
=====================================
lib/trackers/trackerlib.php
=====================================
@@ -5294,6 +5294,13 @@ class TrackerLib extends TikiLib
if (! empty($item_info['itemId'])) {
$mid[] = 'ttifl.`itemId`=?';
$bindvars[] = $item_info['itemId'];
+ if (! array_key_exists('status', $item_info) || empty($item_info['trackerId'])) {
+ $itemRow = $this->items()->fetchRow(['trackerId', 'status'], ['itemId' => $item_info['itemId']]);
+ if ($itemRow) {
+ $item_info['trackerId'] = $item_info['trackerId'] ?? $itemRow['trackerId'];
+ $item_info['status'] = $item_info['status'] ?? $itemRow['status'];
+ }
+ }
if ($prefs['feature_categories'] == 'y') {
$categlib = TikiLib::lib('categ');
$item_categs = $categlib->get_object_categories('trackeritem', $item_info['itemId']);
@@ -5359,6 +5366,8 @@ class TrackerLib extends TikiLib
}
$itemObject = Tracker_Item::fromId($item_info['itemId']);
+ $trackerDefinition = ! empty($item_info['trackerId']) ? Tracker_Definition::get($item_info['trackerId']) : false;
+ $trackerFields = $trackerDefinition ? $trackerDefinition->getFieldsIdKeys() : [];
$query = 'SELECT ttifl.`version`, ttifl.`fieldId`, ttifl.`value`, ta.`user`, ta.`lastModif` ' .
'FROM `tiki_tracker_item_field_logs` ttifl ' .
@@ -5371,17 +5380,35 @@ class TrackerLib extends TikiLib
}
$history['data'] = [];
foreach ($all as $hist) {
- $hist['new'] = $last[$hist['fieldId']] ?? '';
+ $historyFieldId = (int) $hist['fieldId'];
+ $hasNewValue = array_key_exists($historyFieldId, $last);
+ $hist['new'] = $hasNewValue ? $last[$historyFieldId] : '';
if ($hist['new'] == $hist['value']) {
continue;
}
- $last[$hist['fieldId']] = $hist['value'];
- if (! $itemObject->canViewField($hist['fieldId'])) {
+ $last[$historyFieldId] = $hist['value'];
+ $isStatusHistory = $historyFieldId === HISTLIB_INVALID_FIELDID_THAT_MEANS_TRACKER_ITEM_STATUS_CHANGE;
+ $isDeletedFieldHistory = ! $isStatusHistory && ! isset($trackerFields[$historyFieldId]);
+ if ($isDeletedFieldHistory && ! $hasNewValue) {
+ $hist['newValueUnavailable'] = true;
+ }
+ $canViewHistory = ($isStatusHistory || $isDeletedFieldHistory)
+ ? $itemObject->canView()
+ : $itemObject->canViewField($historyFieldId);
+ if (! $canViewHistory) {
continue;
}
if (! empty($filter['version']) && $filter['version'] != $hist['version']) {
continue;
}
+ if ($isStatusHistory) {
+ $hist['fieldName'] = tr('Status');
+ } elseif ($isDeletedFieldHistory) {
+ $hist['fieldName'] = tr('(Deleted field)');
+ $hist['isDeletedField'] = true;
+ } else {
+ $hist['fieldName'] = $trackerFields[$historyFieldId]['name'];
+ }
$history['data'][] = $hist;
}
$history['count'] = $count;
=====================================
templates/comment/edit.tpl
=====================================
@@ -36,8 +36,14 @@
<div class="card bg-body-tertiary">
<div class="card-body">
{foreach $diffInfo as $info}
- <label>{$info.fieldName}</label> {*{$info.value} => {$info.new}<br>*}
- {trackeroutput fieldId=$info.fieldId list_mode='y' history=y process=y oldValue=$info.value value=$info.new diff_style='sidediff'}
+ {if $info.fieldId eq HISTLIB_INVALID_FIELDID_THAT_MEANS_TRACKER_ITEM_STATUS_CHANGE}
+ <label>{tr}Status{/tr}</label>: {$info.value} -> {$info.new}
+ {elseif !empty($info.isDeletedField)}
+ <label>{$info.fieldName}</label>: {$info.value|escape}{if empty($info.newValueUnavailable)} -> {$info.new|escape}{/if}
+ {else}
+ <label>{$info.fieldName}</label> {*{$info.value} => {$info.new}<br>*}
+ {trackeroutput fieldId=$info.fieldId list_mode='y' history=y process=y oldValue=$info.value value=$info.new diff_style='sidediff'}
+ {/if}
{/foreach}
</div>
</div>
=====================================
templates/comment/list_inner.tpl
=====================================
@@ -97,8 +97,10 @@
</h4>
<div class="collapse table-responsive version{$comment.diffInfo[0].version}">
{foreach $comment.diffInfo as $info}
- {if $info.fieldId eq -1}
+ {if $info.fieldId eq HISTLIB_INVALID_FIELDID_THAT_MEANS_TRACKER_ITEM_STATUS_CHANGE}
<label>{tr}Status{/tr}</label>: {$info.value} -> {$info.new}
+ {elseif !empty($info.isDeletedField)}
+ <label>{$info.fieldName}</label>: {$info.value|escape}{if empty($info.newValueUnavailable)} -> {$info.new|escape}{/if}
{else}
<label>{$info.fieldName}</label>
{trackeroutput fieldId=$info.fieldId list_mode='y' history=y process=y oldValue=$info.value value=$info.new diff_style='sidediff'}
=====================================
templates/comment/post.tpl
=====================================
@@ -36,8 +36,10 @@
<div class="card bg-body-tertiary">
<div class="card-body">
{foreach $diffInfo as $info}
- {if $info.fieldId eq -1}
+ {if $info.fieldId eq HISTLIB_INVALID_FIELDID_THAT_MEANS_TRACKER_ITEM_STATUS_CHANGE}
<label>{tr}Status{/tr}</label>: {$info.value} -> {$info.new}
+ {elseif !empty($info.isDeletedField)}
+ <label>{$info.fieldName}</label>: {$info.value|escape}{if empty($info.newValueUnavailable)} -> {$info.new|escape}{/if}
{else}
<label>{$info.fieldName}</label>
{trackeroutput fieldId=$info.fieldId list_mode='y' history=y process=y oldValue=$info.value value=$info.new diff_style='sidediff'}
=====================================
templates/tracker/item_history.tpl
=====================================
@@ -77,7 +77,7 @@
{if $hist.value neq $hist.new or $hist.version == 0}
{$fieldId=$hist.fieldId}
{$field_value=$field_option[$fieldId]}
- {if is_array($field_value) and ($field_value.visibleInHistoryMode eq 'y' or $hist.version == 0 or $hist.fieldId == -1)}
+ {if is_array($field_value) and ($field_value.visibleInHistoryMode eq 'y' or $hist.version == 0 or $hist.fieldId == HISTLIB_INVALID_FIELDID_THAT_MEANS_TRACKER_ITEM_STATUS_CHANGE)}
<tr>
<td class="id"><strong>{$hist.version|escape}</strong></td>
<td class="date"><strong>{if not empty($hist.lastModif)}{$hist.lastModif|tiki_short_datetime}{/if}</strong></td>
@@ -89,7 +89,7 @@
{if $fieldId eq HISTLIB_INVALID_FIELDID_THAT_MEANS_TRACKER_ITEM_STATUS_CHANGE}_{tr}Status{/tr}_{else}{$field_option[$fieldId].name}{/if}
</td>
{if empty($diff_style)}
- {if !empty($field_value.fieldId) && $field_value.fieldId > 0}
+ {if !empty($field_value.fieldId) && $field_value.fieldId > 0 && empty($field_value.isDeletedField)}
<td class="text">{$hist.rendered_value}</td>
<td class="text">{$hist.rendered_new}</td>
{else}
@@ -98,7 +98,7 @@
{/if}
{else}
<td colspan="2" class="tracker-diff {$diff_style}">
- {if !empty($field_value.fieldId) && $field_value.fieldId > 0}
+ {if !empty($field_value.fieldId) && $field_value.fieldId > 0 && empty($field_value.isDeletedField)}
{$hist.rendered_diff}
{else}
{wikidiff object_type=direct oldver=$hist.value newver=$hist.new diff_style=$diff_style}
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/cdc51eb8318f4d39736192e70c75e229aad2cc3e
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/cdc51eb8318f4d39736192e70c75e229aad2cc3e
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs