Skip to content

Commit

Permalink
Improved handling of broken saved searches (#16166)
Browse files Browse the repository at this point in the history
* handle corrupt saved searches

* small adjusments

---------

Co-authored-by: Cédric Anne <cedric.anne@gmail.com>
  • Loading branch information
cconard96 and cedric-anne authored Jan 11, 2024
1 parent db2db6a commit 3e852c1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
21 changes: 14 additions & 7 deletions src/SavedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -861,30 +861,37 @@ public function getMine(string $itemtype = null, bool $inverse = false, bool $en

$iterator = $DB->request($criteria);
foreach ($iterator as $data) {
$error = false;

if ($_SESSION['glpishow_count_on_tabs']) {
$this->fields = $data;
$count = null;
$search_data = null;
try {
$search_data = $this->execute(false, $enable_partial_warnings);
} catch (\RuntimeException $e) {
} catch (\Throwable $e) {
ErrorHandler::getInstance()->handleException($e);
$search_data = false;
$error = true;
}
if (isset($search_data['data']['totalcount'])) {

if ($error) {
$info_message = __s('A fatal error occurred while executing this saved search. It is not able to be used.');
$count = "<span class='ti ti-alert-triangle-filled' title='$info_message'></span>";
} elseif (isset($search_data['data']['totalcount'])) {
$count = $search_data['data']['totalcount'];
} else {
$info_message = ($this->fields['do_count'] == self::COUNT_NO)
? __s('Count for this saved search has been disabled.')
: __s('Counting this saved search would take too long, it has been skipped.');
if ($count === null) {
//no count, just inform the user
$count = "<span class='ti ti-info-circle' title='$info_message'></span>";
}
// no count, just inform the user
$count = "<span class='ti ti-info-circle' title='$info_message'></span>";
}

$data['count'] = $count;
}

$data['_error'] = $error;

$searches[$data['id']] = $data;
}

Expand Down
24 changes: 16 additions & 8 deletions templates/layout/parts/saved_searches_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,23 @@
{% for search in saved_searches %}
<div class="savedsearches-item grip-savedsearch list-group-item search-line d-flex align-items-center pe-1 {{ active == search['id'] ? 'active' : '' }}"
data-id="{{ search['id'] }}">
<a href="{{ 'SavedSearch'|itemtype_search_path }}?action=load&amp;id={{ search['id'] }}"
class="d-block saved-searches-link text-truncate">
{{ search['name']|verbatim_value }}
</a>
{% if not search['_error'] %}
<a href="{{ 'SavedSearch'|itemtype_search_path }}?action=load&amp;id={{ search['id'] }}"
class="d-block saved-searches-link text-truncate">
{{ search['name']|verbatim_value }}
</a>
{% else %}
<span class="d-block text-truncate">
{{ search['name']|verbatim_value }}
</span>
{% endif %}
<div class="{{ search['is_default'] > 0 ? '' : 'list-group-item-actions' }} ms-auto default-ctrl">
<i class="{{ search['is_default'] > 0 ? 'fas' : 'far' }} fa-star fa-xs mark-default me-1"
title="{{ search['is_default'] > 0 ? __('Default search') : __('mark as default') }}"
data-bs-toggle="tooltip" data-bs-placement="right"
role="button"></i>
{% if not search['_error'] %}
<i class="{{ search['is_default'] > 0 ? 'fas' : 'far' }} fa-star fa-xs mark-default me-1"
title="{{ search['is_default'] > 0 ? __('Default search') : __('mark as default') }}"
data-bs-toggle="tooltip" data-bs-placement="right"
role="button"></i>
{% endif %}
</div>
<div class="d-flex flex-nowrap align-items-center">
{% if search['is_private'] == 1 %}
Expand Down

0 comments on commit 3e852c1

Please sign in to comment.