Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved handling of broken saved searches #16166

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
cedric-anne marked this conversation as resolved.
Show resolved Hide resolved
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'] }}"
trasher marked this conversation as resolved.
Show resolved Hide resolved
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