glpi-project / glpi

GLPI is a Free Asset and IT Management Software package, Data center management, ITIL Service Desk, licenses tracking and software auditing.
https://glpi-project.org
GNU General Public License v3.0
4.36k stars 1.3k forks source link

Reservation free period search tool considers items as unavailable because of coincidence of desired time range with adjacent reservations #13548

Closed C-Duv closed 1 year ago

C-Duv commented 1 year ago

Code of Conduct

Is there an existing issue for this?

Version

9.5.11

Bug description

The "Find a free item in a specific period" reservation tool does not list available items that are reserved until or from the desired start/end date.

Relevant log output

No response

Page URL

https://glpi.example.com/front/reservationitem.php

Steps To reproduce

Given the following reservation planning for item X on day 2022-11-07:

Start End User
10:00 11:00 Foo
15:00 16:00 Bar
16:30 17:30 Baz

(There is a gap between 16:00 and 16:30)

  1. Go to Tools > Reservations page.
  2. Click "Find a free item in a specific period".
  3. Fill the form as follows:
    • Start Date: 2022-11-07 16:00:00
    • Duration: 0h30
  4. Submit the form using the "Search" button

Actual output

The item X is not listed, thus considered unavailable for the submitted "2022-11-07 16:00:00 → 2022-11-07 16:30:00" time range.

Expected output

The item X should be listed, because it's reserved until 16:00 and not before 16:30 which allows for the submitted "2022-11-07 16:00:00 → 2022-11-07 16:30:00" time range.

Your GLPI setup information

Information about system installation & configuration

GLPI 9.5.11 ( => /var/www/glpi.example.com/versions/9.5.11)
Installation mode: TARBALL
Current language:en_US

Server

Operating system: Linux server.example.com 5.10.0-14-amd64 #1 SMP Debian 5.10.113-1 (2022-04-29) x86_64
PHP 7.4.33 fpm-fcgi (Core, FFI, PDO, Phar, Reflection, SPL, SimpleXML, Zend OPcache, calendar, cgi-fcgi, ctype, curl, date, dom,
    exif, fileinfo, filter, ftp, gd, gettext, hash, iconv, imap, intl, json, ldap, libxml, mbstring, mysqli, mysqlnd, openssl, pcre,
    pdo_mysql, posix, readline, session, shmop, snmp, soap, sockets, sodium, standard, sysvmsg, sysvsem, sysvshm, tokenizer, xml,
    xmlreader, xmlrpc, xmlwriter, xsl, zlib)
Setup: max_execution_time="30" memory_limit="128M" post_max_size="8M" safe_mode="" session.save_handler="files"
    upload_max_filesize="30M" 
Software: nginx/1.18.0
    Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:106.0) Gecko/20100101 Firefox/106.0
Server Software: Debian 11
    Server Version: 10.5.15-MariaDB-0+deb11u1
    Server SQL Mode: 
    Parameters: glpi-prod@localhost/glpi-prod
    Host info: Localhost via UNIX socket

PHP version is at least 7.2.0 - Perfect!PHP version is at least 7.2.0 - Perfect!
Sessions support is available - Perfect!Sessions support is available - Perfect!
Allocated memory > 64 Mio - Perfect!Allocated memory > 64 Mio - Perfect!
mysqli extension is installedmysqli extension is installed
ctype extension is installedctype extension is installed
fileinfo extension is installedfileinfo extension is installed
json extension is installedjson extension is installed
mbstring extension is installedmbstring extension is installed
iconv extension is installediconv extension is installed
zlib extension is installedzlib extension is installed
curl extension is installedcurl extension is installed
gd extension is installedgd extension is installed
simplexml extension is installedsimplexml extension is installed
intl extension is installedintl extension is installed
ldap extension is installedldap extension is installed
apcu extension is not presentapcu extension is not present
Zend OPcache extension is installedZend OPcache extension is installed
xmlrpc extension is installedxmlrpc extension is installed
exif extension is installedexif extension is installed
zip extension is not presentzip extension is not present
bz2 extension is not presentbz2 extension is not present
sodium extension is installedsodium extension is installed
Database version seems correct (10.5.15) - Perfect!Database version seems correct (10.5.15) - Perfect!
Timezones seems loaded in databaseTimezones seems loaded in database
The log file has been created successfully.The log file has been created successfully.
Write access to /…/files/_cache has been validated.Write access to /…/files/_cache has been validated.
Write access to /…/config has been validated.Write access to /…/config has been validated.
Write access to /…/files/_cron has been validated.Write access to /…/files/_cron has been validated.
Write access to /…/files has been validated.Write access to /…/files has been validated.
Write access to /…/files/_dumps has been validated.Write access to /…/files/_dumps has been validated.
Write access to /…/files/_graphs has been validated.Write access to /…/files/_graphs has been validated.
Write access to /…/files/_lock has been validated.Write access to /…/files/_lock has been validated.
Write access to /…/files/_pictures has been validated.Write access to /…/files/_pictures has been validated.
Write access to /…/files/_plugins has been validated.Write access to /…/files/_plugins has been validated.
Write access to /…/files/_rss has been validated.Write access to /…/files/_rss has been validated.
Write access to /…/files/_sessions has been validated.Write access to /…/files/_sessions has been validated.
Write access to /…/files/_tmp has been validated.Write access to /…/files/_tmp has been validated.
Write access to /…/files/_uploads has been validated.Write access to /…/files/_uploads has been validated.
The directory could not be created in /…/marketplace.The directory could not be created in /…/marketplace.
Web access to the files directory should not be allowed but this cannot be checked automatically on this instance. Make sure access to error log file (/files/_log/php-errors.log) is forbidden; otherwise review .htaccess file and web server configuration.Web access to the files directory should not be allowed but this cannot be checked automatically on this instance.
Make sure access to error log file (/files/_log/php-errors.log) is forbidden; otherwise review .htaccess file and web server configuration.

GLPI constants

GLPI_ROOT: /…/
GLPI_CONFIG_DIR: /…/config
GLPI_VAR_DIR: /…/files
GLPI_MARKETPLACE_DIR: /…/marketplace
GLPI_USE_CSRF_CHECK: 1
GLPI_CSRF_EXPIRES: 7200
GLPI_CSRF_MAX_TOKENS: 100
GLPI_USE_IDOR_CHECK: 1
GLPI_IDOR_EXPIRES: 7200
GLPI_ALLOW_IFRAME_IN_RICH_TEXT: 
GLPI_SERVERSIDE_URL_ALLOWLIST: Array
GLPI_TELEMETRY_URI: https://telemetry.glpi-project.org
GLPI_INSTALL_MODE: TARBALL
GLPI_NETWORK_MAIL: glpi@teclib.com
GLPI_NETWORK_SERVICES: https://services.glpi-network.com
GLPI_MARKETPLACE_PRERELEASES: 
GLPI_MARKETPLACE_ALLOW_OVERRIDE: 1
GLPI_MARKETPLACE_MANUAL_DOWNLOADS: 1
GLPI_USER_AGENT_EXTRA_COMMENTS: 
GLPI_AJAX_DASHBOARD: 1
GLPI_CALDAV_IMPORT_STATE: 0
GLPI_DEMO_MODE: 0
GLPI_FORCE_EMPTY_SQL_MODE: 1
GLPI_DOC_DIR: /…/files
GLPI_CACHE_DIR: /…/files/_cache
GLPI_CRON_DIR: /…/files/_cron
GLPI_DUMP_DIR: /…/files/_dumps
GLPI_GRAPH_DIR: /…/files/_graphs
GLPI_LOCAL_I18N_DIR: /…/files/_locales
GLPI_LOCK_DIR: /…/files/_lock
GLPI_LOG_DIR: /…/files/_log
GLPI_PICTURE_DIR: /…/files/_pictures
GLPI_PLUGIN_DOC_DIR: /…/files/_plugins
GLPI_RSS_DIR: /…/files/_rss
GLPI_SESSION_DIR: /…/files/_sessions
GLPI_TMP_DIR: /…/files/_tmp
GLPI_UPLOAD_DIR: /…/files/_uploads
GLPI_NETWORK_REGISTRATION_API_URL: https://services.glpi-network.com/api/registration/
GLPI_MARKETPLACE_PLUGINS_API_URI: https://services.glpi-network.com/api/glpi-plugins/
GLPI_I18N_DIR: /…/locales
GLPI_VERSION: 9.5.11
GLPI_SCHEMA_VERSION: 9.5.7
GLPI_MIN_PHP: 7.2.0
GLPI_YEAR: 2022

Libraries

htmlawed/htmlawed version 1.2.5 in (/…/vendor/htmlawed/htmlawed)
phpmailer/phpmailer version 6.6.5 in (/…/vendor/phpmailer/phpmailer/src)
simplepie/simplepie version 1.5.6 in (/…/vendor/simplepie/simplepie/library)
tecnickcom/tcpdf version 6.3.5 in (/…/vendor/tecnickcom/tcpdf)
michelf/php-markdown in (/…/vendor/michelf/php-markdown/Michelf)
true/punycode in (/…/vendor/true/punycode/src)
iamcal/lib_autolink in (/…/vendor/iamcal/lib_autolink)
sabre/dav in (/…/vendor/sabre/dav/lib/DAV)
sabre/http in (/…/vendor/sabre/http/lib)
sabre/uri in (/…/vendor/sabre/uri/lib)
sabre/vobject in (/…/vendor/sabre/vobject/lib)
laminas/laminas-cache in (/…/vendor/laminas/laminas-cache/src)
laminas/laminas-i18n in (/…/vendor/laminas/laminas-i18n/src)
laminas/laminas-serializer in (/…/vendor/laminas/laminas-serializer/src)
monolog/monolog in (/…/vendor/monolog/monolog/src/Monolog)
sebastian/diff in (/…/vendor/sebastian/diff/src)
elvanto/litemoji in (/…/vendor/elvanto/litemoji/src)
symfony/console in (/…/vendor/symfony/console)
scssphp/scssphp in (/…/vendor/scssphp/scssphp/src)
laminas/laminas-mail in (/…/vendor/laminas/laminas-mail/src/Protocol)
laminas/laminas-mime in (/…/vendor/laminas/laminas-mime/src)
rlanvin/php-rrule in (/…/vendor/rlanvin/php-rrule/src)
blueimp/jquery-file-upload in (/…/vendor/blueimp/jquery-file-upload/server/php)
ramsey/uuid in (/…/vendor/ramsey/uuid/src)
psr/log in (/…/vendor/psr/log/Psr/Log)
psr/simple-cache in (/…/vendor/psr/simple-cache/src)
mexitek/phpcolors in (/…/vendor/mexitek/phpcolors/src/Mexitek/PHPColors)
guzzlehttp/guzzle in (/…/vendor/guzzlehttp/guzzle/src)
guzzlehttp/psr7 in (/…/vendor/guzzlehttp/psr7/src)
wapmorgan/unified-archive in (/…/vendor/wapmorgan/unified-archive/src)
paragonie/sodium_compat in (/…/vendor/paragonie/sodium_compat/src)

LDAP directories

Server: 'ldap://ldap.example.com', Port: '389', BaseDN: 'dc=example,dc=com', Connection filter:
        '(&(objectClass=somePerson)(mail=*@example.com))', RootDN:
        'cn=glpi.example.com,ou=Applications,dc=example,dc=com', Use TLS: '1'
Server: 'ldap://ldap.example.com', Port: '389', BaseDN: 'dc=example,dc=com', Connection filter:
        '(&(objectClass=somePerson)(mail=*@example.net))', RootDN:
        'cn=glpi.example.com,ou=Applications,dc=example,dc=com', Use TLS: '1'

SQL replicas

Not active

Notifications

Way of sending emails: SMTP+TLS (sender@mail.example.com)

Mails receivers

Name: 'support@example.com' Active: Yes
    Server: '{mail.example.com:995/pop/ssl}' Login: 'support@example.com' Password: Yes

Plugins list

    addressing           Name: Adressage IP                   Version: 2.9.1      State: Enabled
    news                 Name: Alertes                        Version: 1.9.1      State: Enabled
    additionalalerts     Name: Alertes supplémentaires        Version: 2.3.0      State: Enabled
    webapplications      Name: Applications Web               Version: 3.0.2      State: Enabled
    archires             Name: Architectures réseau           Version: 2.6.0      State: Installed / not activated
    badges               Name: Badges                         Version: 2.6.0      State: Enabled
    positions            Name: Cartographie                   Version: 5.0.0      State: Enabled
    fields               Name: Champs supplémentaires         Version: 1.13.0     State: Enabled
    timelineticket       Name: Chronologie des tickets        Version: 9.5+1.1    State: Enabled
    shellcommands        Name: Commandes Shell                Version: 3.0.0      State: Enabled
    behaviors            Name: Comportements                  Version: 2.6.0      State: Installed / not activated
    printercounters      Name: Compteurs Imprimantes          Version: 1.7.0      State: Installed / not activated
    connections          Name: Connexions                     Version: 9.5        State: Enabled
    mydashboard          Name: Dashboard                      Version: 1.8.3      State: Enabled
    domains              Name: Domaines                       Version: 2.1.0      State: Installed / not activated
    financialreports     Name: Financial reports              Version: 2.6.0      State: Installed / not activated
    fusioninventory      Name: FusionInventory                Version: 9.5+4.2    State: Enabled
    geninventorynumber   Name: Génération de numéros d'invent Version: 2.5.1      State: Installed / not activated
    genericobject        Name: Gestion d'objets               Version: 2.11.1     State: Enabled
    order                Name: Gestion des commandes          Version: 2.7.6      State: Enabled
    pdf                  Name: Impression pdf                 Version: 2.0.1      State: Enabled
    mailanalyzer         Name: Mail Analyzer                  Version: 2.1.0      State: Enabled
    moreticket           Name: More ticket                    Version: 1.6.1      State: Enabled
    mreporting           Name: Plus de rapports               Version: 1.7.4      State: Enabled
    reports              Name: Rapports                       Version: 1.14.1     State: Enabled
    reservation          Name: Reservation                    Version: 2.3.8      State: Installed / not activated
    room                 Name: Rooms                          Version: 3.1.4      State: Enabled
    dashboard            Name: Tableau de bord                Version: 0.9.6      State: Enabled
    ticketcleaner        Name: Ticket Cleaner                 Version: 3.0.0      State: Enabled
    typology             Name: Typologies                     Version: 2.7.2      State: Installed / not activated

Anything else?

I tested with the following inputs and here are my findings:

Start Date Duration Outcome
2022-11-07 16:00:00 0h30 ❌ Item X is not listed
2022-11-07 16:00:00 0h25 ❌ Item X is not listed
2022-11-07 16:00:01 0h30 ❌ Item X is not listed
2022-11-07 16:00:01 0h25 ✅ Item X is listed

It looks like the GLPI is using equality comparison.

And code (/inc/reservationitem.class.php, lines 565-575) seems to say the same thing:

            $criteria['LEFT JOIN']['glpi_reservations'] = [
               'ON'  => [
                  'glpi_reservationitems' => 'id',
                  'glpi_reservations'     => 'reservationitems_id', [
                     'AND' => [
                        'glpi_reservations.end'    => ['>=', $begin],
                        'glpi_reservations.begin'  => ['<=', $end]
                     ]
                  ]
               ]
            ];

By changing the >= and <= operators on line 570-571 to > and < respectively I can get item X to be listed as available.

cedric-anne commented 1 year ago

Hi,

Could you create a PR to fix this on 10.0/bugfixes branch ?

C-Duv commented 1 year ago

PR opened.

cedric-anne commented 1 year ago

Fixed by #13590.