Skip to content

Commit

Permalink
Merge branch '10.0/bugfixes' of https://github.com/Lainow/glpi into 1…
Browse files Browse the repository at this point in the history
…0.0/bugfixes
  • Loading branch information
Lainow committed Oct 9, 2023
2 parents 4f38474 + b46d235 commit d2358bd
Show file tree
Hide file tree
Showing 33 changed files with 576 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cancel_workflow_runs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: "${{ github.repository == 'glpi-network/glpi' && 'self-hosted' || 'ubuntu-latest' }}"
steps:
- name: "Cancel outdated workflow runs"
uses: "styfle/cancel-workflow-action@0.11.0"
uses: "styfle/cancel-workflow-action@0.12.0"
with:
all_but_latest: true
workflow_id: ${{ github.event.workflow.id }}
4 changes: 4 additions & 0 deletions css/includes/components/_select2.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
}
}

.select2-selection__rendered input[type="search"] {
color: $input-color;
}

&.select2-selection--single {
@include font-size($input-font-size);

Expand Down
2 changes: 1 addition & 1 deletion css/legacy/includes/_inputs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/

textarea:not(.form-control), input:not(.submit):not(.form-control):not([type=submit]):not([type=color]):not([type=reset]):not([type=checkbox]):not([type=radio]):not(.select2-search__field):not(.numInput):not(.tox-textfield) {
color: $body-color;
color: $input-color;
background-color: $input-bg;
background-clip: padding-box;
border: $input-border-width solid $input-border-color;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2023 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

/**
* @var DB $DB
* @var Migration $migration
*/

$migration->changeSearchOption('Computer', 129, 1429);
$migration->changeSearchOption('Computer', 130, 1430);
$migration->changeSearchOption('Computer', 131, 1431);
$migration->changeSearchOption('Computer', 132, 1432);

$migration->changeSearchOption('Domain', 30, 1400);
$migration->changeSearchOption('Project', 119, 1400);
7 changes: 6 additions & 1 deletion src/AuthLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -3088,9 +3088,14 @@ public static function connectToServer(
LDAP_OPT_PROTOCOL_VERSION => 3,
LDAP_OPT_REFERRALS => 0,
LDAP_OPT_DEREF => $deref_options,
LDAP_OPT_NETWORK_TIMEOUT => $timeout
];

if ($timeout > 0) {
// Apply the timeout unless it is "unlimited" ("unlimited" is the default value defined in `libldap`).
// see https://linux.die.net/man/3/ldap_set_option
$ldap_options[LDAP_OPT_NETWORK_TIMEOUT] = $timeout;
}

foreach ($ldap_options as $option => $value) {
if (!@ldap_set_option($ds, $option, $value)) {
trigger_error(
Expand Down
15 changes: 10 additions & 5 deletions src/Change.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ public function rawSearchOptions()
'field' => 'impactcontent',
'name' => __('Analysis impact'),
'massiveaction' => false,
'datatype' => 'text'
'datatype' => 'text',
'htmltext' => true
];

$tab[] = [
Expand All @@ -519,7 +520,8 @@ public function rawSearchOptions()
'field' => 'controlistcontent',
'name' => __('Control list'),
'massiveaction' => false,
'datatype' => 'text'
'datatype' => 'text',
'htmltext' => true
];

$tab[] = [
Expand All @@ -528,7 +530,8 @@ public function rawSearchOptions()
'field' => 'rolloutplancontent',
'name' => __('Deployment plan'),
'massiveaction' => false,
'datatype' => 'text'
'datatype' => 'text',
'htmltext' => true
];

$tab[] = [
Expand All @@ -537,7 +540,8 @@ public function rawSearchOptions()
'field' => 'backoutplancontent',
'name' => __('Backup plan'),
'massiveaction' => false,
'datatype' => 'text'
'datatype' => 'text',
'htmltext' => true
];

$tab[] = [
Expand All @@ -546,7 +550,8 @@ public function rawSearchOptions()
'field' => 'checklistcontent',
'name' => __('Checklist'),
'massiveaction' => false,
'datatype' => 'text'
'datatype' => 'text',
'htmltext' => true
];

$tab = array_merge($tab, Notepad::rawSearchOptionsToAdd());
Expand Down
4 changes: 2 additions & 2 deletions src/CommonDBTM.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,8 @@ public function updateInDB($updates, $oldvalues = [])

$tobeupdated = [];
foreach ($updates as $field) {
if (isset($this->fields[$field])) {
if (isset($oldvalues[$field]) && $this->fields[$field] == $oldvalues[$field]) {
if (array_key_exists($field, $this->fields)) {
if (array_key_exists($field, $oldvalues) && $this->fields[$field] == $oldvalues[$field]) {
unset($oldvalues[$field]);
}
$tobeupdated[$field] = $this->fields[$field];
Expand Down
8 changes: 7 additions & 1 deletion src/CommonITILTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ public function post_addItem()
NotificationEvent::raiseEvent('add_task', $this->input["_job"], $options);
}

PendingReason_Item::handlePendingReasonUpdateFromNewTimelineItem($this);

// Add log entry in the ITIL object
$changes = [
0,
Expand Down Expand Up @@ -1281,7 +1283,11 @@ public static function genericPopulatePlanning($itemtype, $options = [])

/// Specific for tickets
$interv[$key]["device"] = [];
if (isset($parentitem->hardwaredatas) && !empty($parentitem->hardwaredatas)) {
if (
$parentitem instanceof Ticket
&& isset($parentitem->hardwaredatas)
&& !empty($parentitem->hardwaredatas)
) {
foreach ($parentitem->hardwaredatas as $hardwaredata) {
$interv[$key]["device"][$hardwaredata->fields['id']] = ($hardwaredata
? $hardwaredata->getName() : '');
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Maintenance/EnableMaintenanceModeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$values = [
'maintenance_mode' => '1'
];
if ($input->hasOption('text')) {
if ($input->hasOption('text') && $input->getOption('text') !== null) {
$values['maintenance_text'] = Sanitizer::sanitize($input->getOption('text'));
}
$config = new Config();
Expand Down
3 changes: 3 additions & 0 deletions src/DBmysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,9 @@ public function buildUpdate($table, $params, $clauses, array $joins = [])
if (!count($clauses['WHERE'])) {
throw new \RuntimeException('Cannot run an UPDATE query without WHERE clause!');
}
if (!count($params)) {
throw new \RuntimeException('Cannot run an UPDATE query without parameters!');
}

$query = "UPDATE " . self::quoteName($table);

Expand Down
2 changes: 1 addition & 1 deletion src/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function rawSearchOptions()
];

$tab[] = [
'id' => '30',
'id' => '1400',
'table' => $this->getTable(),
'field' => 'id',
'name' => __('ID'),
Expand Down
2 changes: 2 additions & 0 deletions src/ITILFollowup.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ public function post_addItem()
NotificationEvent::raiseEvent("add_followup", $parentitem, $options);
}

PendingReason_Item::handlePendingReasonUpdateFromNewTimelineItem($this);

// Add log entry in the ITILObject
$changes = [
0,
Expand Down
4 changes: 2 additions & 2 deletions src/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static function constructHistory(CommonDBTM $item, $oldvalues, $values)
&& ($val2['rightname'] == $item->fields['name'])
) {
$id_search_option = $key2;
$changes = [$id_search_option, addslashes($oldval ?? ''), $values[$key]];
$changes = [$id_search_option, addslashes($oldval ?? ''), $values[$key] ?? ''];
}
} else if (
($val2['linkfield'] == $key && $real_type === $item->getType())
Expand All @@ -169,7 +169,7 @@ public static function constructHistory(CommonDBTM $item, $oldvalues, $values)
$oldval = CommonTreeDropdown::sanitizeSeparatorInCompletename($oldval);
$values[$key] = CommonTreeDropdown::sanitizeSeparatorInCompletename($values[$key]);
}
$changes = [$id_search_option, addslashes($oldval ?? ''), $values[$key]];
$changes = [$id_search_option, addslashes($oldval ?? ''), $values[$key] ?? ''];
} else {
// other cases; link field -> get data from dropdown
if ($val2["table"] != 'glpi_auth_tables') {
Expand Down
16 changes: 5 additions & 11 deletions src/MailCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,9 @@ public function showForm($ID, array $options = [])
var li = $(this);
var input_id = li.data('input-id');
var folder = li.children('.folder-name').html();
var folder = li.find('.folder-name').data('globalname');
var _label = '';
var _parents = li.parents('li').children('.folder-name');
for (i = _parents.length -1 ; i >= 0; i--) {
_label += $(_parents[i]).html() + '/';
}
_label += folder;
$('#'+input_id).val(_label);
$('#'+input_id).val(folder);
var modalEl = $('#'+input_id+'_modal')[0];
var modal = bootstrap.Modal.getInstance(modalEl);
Expand Down Expand Up @@ -427,10 +420,11 @@ public function displayFoldersList($input_id = "")
*/
private function displayFolder($folder, $input_id)
{
$fname = mb_convert_encoding($folder->getLocalName(), "UTF-8", "UTF7-IMAP");
$fglobalname = htmlspecialchars(mb_convert_encoding($folder->getGlobalName(), "UTF-8", "UTF7-IMAP"), ENT_QUOTES);
$flocalname = htmlspecialchars(mb_convert_encoding($folder->getLocalName(), "UTF-8", "UTF7-IMAP"), ENT_QUOTES);
echo "<li class='pointer' data-input-id='$input_id'>
<i class='fa fa-folder'></i>&nbsp;
<span class='folder-name'>" . $fname . "</span>";
<span class='folder-name' data-globalname='" . $fglobalname . "'>" . $flocalname . "</span>";
echo "<ul>";

foreach ($folder as $sfolder) {
Expand Down
2 changes: 1 addition & 1 deletion src/Monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public static function rawSearchOptionsToAdd($itemtype = null)
];

$tab[] = [
'id' => '129',
'id' => '1429',
'table' => 'glpi_computers_items',
'field' => 'id',
'name' => _x('quantity', 'Number of monitors'),
Expand Down
99 changes: 90 additions & 9 deletions src/PendingReason_Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,13 @@ public function getAutoResolvedate()
}

/**
* Check that the given timeline event is the lastest "pending" action for
* the given item
* Get the lastest "pending" action for the given item
*
* @param CommonITILObject $item
* @param CommonDBTM $timeline_item
* @return boolean
* @return CommonDBTM|false
*/
public static function isLastPendingForItem(
CommonITILObject $item,
CommonDBTM $timeline_item
): bool {
public static function getLastPendingTimelineItemDataForItem(CommonITILObject $item)
{
global $DB;

$task_class = $item::getTaskClass();
Expand Down Expand Up @@ -257,7 +253,27 @@ public static function isLastPendingForItem(
$row = $data->current();
$pending_item = self::getById($row['max_id']);

return $pending_item->fields['items_id'] == $timeline_item->fields['id'] && $pending_item->fields['itemtype'] == $timeline_item::getType();
return $pending_item;
}

/**
* Check that the given timeline event is the lastest "pending" action for
* the given item
*
* @param CommonITILObject $item
* @param CommonDBTM $timeline_item
* @return boolean
*/
public static function isLastPendingForItem(
CommonITILObject $item,
CommonDBTM $timeline_item
): bool {
$pending_item = self::getLastPendingTimelineItemDataForItem($item);

return
$pending_item->fields['items_id'] == $timeline_item->fields['id']
&& $pending_item->fields['itemtype'] == $timeline_item::getType()
;
}

/**
Expand Down Expand Up @@ -323,6 +339,71 @@ public static function isLastTimelineItem(CommonDBTM $timeline_item): bool
return $row['max_date_creation'] == $timeline_item->fields['date_creation'];
}

/**
* User might be trying to update the active pending reason by modifying the
* pending reason data in a new timeline item form
*
* This method update the latest pending timeline item if the user has edited
* the pending details while adding a new task or followup
*
* @param CommonDBTM $new_timeline_item
* @return void
*/
public static function handlePendingReasonUpdateFromNewTimelineItem(
CommonDBTM $new_timeline_item
): void {
$last_pending = self::getLastPendingTimelineItemDataForItem($new_timeline_item->input['_job']);

// There is no existing pending data on previous timeline items for this ticket
// Nothing to be done here since the goal of this method is to update active pending data
if (!$last_pending) {
return;
}

// The new timeline item is the latest pending reason
// This mean there was no active pending reason before this timeline item was added
// Nothing to be done here as we don't have any older active pending reason to update
if (
$last_pending->fields['itemtype'] == $new_timeline_item::getType()
&& $last_pending->fields['items_id'] == $new_timeline_item->getID()
) {
return;
}

// Pending reason was removed or is not enabled
// Nothing to update here as it was already handled in CommonITILObject::prepareInputForUpdate
if (!($new_timeline_item->input['pending'] ?? 0)) {
return;
}

// If we reach this point, this mean a timeline item with pending information
// was added on a CommonITILObject which already had pending data
// This mean the user might be trying to update the existing pending reason data

// Let's check if there is any real updates before going any further
$pending_updates = [];
$fields_to_check_for_updates = ['pendingreasons_id', 'followup_frequency', 'followups_before_resolution'];
foreach ($fields_to_check_for_updates as $field) {
if (
isset($new_timeline_item->input[$field])
&& $new_timeline_item->input[$field] != $last_pending->fields[$field]
) {
$pending_updates[$field] = $new_timeline_item->input[$field];
}
}

// No actual updates -> nothing to be done
if (count($pending_updates) == 0) {
return;
}

// Update last pending item and parent
$last_pending_timeline_item = new $last_pending->fields['itemtype']();
$last_pending_timeline_item->getFromDB($last_pending->fields['items_id']);
self::updateForItem($last_pending_timeline_item, $pending_updates);
self::updateForItem($new_timeline_item->input['_job'], $pending_updates);
}

/**
* Handle edit on a "pending action" from an item the timeline
*
Expand Down
Loading

0 comments on commit d2358bd

Please sign in to comment.