You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2023-09-25 12:58:00

Rafumel1774
Member
Registered: 2019-05-11
Posts: 131

Rules: Adding tasks is not respecting order

I create a Rule for Tickets which is triggering on specific tickets. If it is triggered it adds multiple (15) task template.
I've added the tasks in order in the rule in the correct order and named them:

something > 1 more text
something > 2 more text
something > 3 more text
something > 4 more text
..

I've also made sure that they are created one after another to make sure the ID's in the table are in order.

However, when the rule is triggered the tasks are not added in the expected order.
So it seems that it's not sorting them by the "name of the template", "order they are added to the rule" nor the "ID's in the database".

How can I add them in the specified order? What am I doing wrong?

Offline

#2 2023-09-25 13:02:39

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: Rules: Adding tasks is not respecting order

Please test with the latest bug-fix release (10.0.10). A similar issue was fixed recently an should be a part of the latest release.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#3 2023-09-25 13:11:18

Rafumel1774
Member
Registered: 2019-05-11
Posts: 131

Re: Rules: Adding tasks is not respecting order

Thank you for the fast reply!
I will try to prepare an update, which requires a lot of testing. Will let you know if it is not working.

Thanks!

Offline

#4 2023-09-26 21:11:53

Rafumel1774
Member
Registered: 2019-05-11
Posts: 131

Re: Rules: Adding tasks is not respecting order

Updated but the problem persists sad

Offline

#5 2023-09-27 17:51:52

Rafumel1774
Member
Registered: 2019-05-11
Posts: 131

Re: Rules: Adding tasks is not respecting order

Definitely a bug!

I've tested it on another system (with only 3 elements) and it worked. So I created a new rule and added some ... it worked ... until I added more.
    Category    Assign    XX > XXX
    Technician group    Assign    VXXX
    Task template    Add    XXX - XXX
    Task template    Add    XXX > 1 XXX
    Task template    Add    XXX > 2 XXX
    Task template    Add    XXX > 3 XXX
    Task template    Add    XXX > 4 XXX
    Task template    Add    XXX > 5 XXX
    Task template    Add    XXX > 6 XXX
    Task template    Add    XXX > 7 XXX
    Task template    Add    XXX > 8 XXX
    Task template    Add    XXX > 9 XXX
    Task template    Add    XXX > 10 XXX

Testet 3 times -> worked perfectly.
After adding ONE more task template it completely messed up the order of all elements (tested 3 times)!

Last edited by Rafumel1774 (2023-09-27 17:54:32)

Offline

#6 2023-10-18 16:47:38

Rafumel1774
Member
Registered: 2019-05-11
Posts: 131

Re: Rules: Adding tasks is not respecting order

Can someone confirm this?

Offline

#7 2023-10-18 23:51:01

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: Rules: Adding tasks is not respecting order

There is a bug report for this, but it hasn't been confirmed/troubleshot yet.

https://github.com/glpi-project/glpi/issues/15761


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#8 2023-10-24 12:33:58

Rafumel1774
Member
Registered: 2019-05-11
Posts: 131

Re: Rules: Adding tasks is not respecting order

Digging deep into this issue, it seems to be working to fine in the "logic" from the processing of the "rules module".
However, it is an issue with the "representation" layer.
The data is properly added to the "glpi_tickettasks" table in the correct order with the IDs and so on.
But it seems that the "representation layer" is sorting by the timestamp for "date_creation of the element and as there seems to be many elements with exactly the time timestamp (seconds - not miliseconds) there seems to be a mixup.

Offline

#9 2023-10-24 13:23:03

Rafumel1774
Member
Registered: 2019-05-11
Posts: 131

Re: Rules: Adding tasks is not respecting order

Found it!

Caused by CommonITILObject.php
Around line 7267
       //sort timeline items by date
        $reverse = $params['sort_by_date_desc'];
        usort($timeline, function ($a, $b) use ($reverse) {
            $date_a = $a['item']['date_creation'] ?? $a['item']['date'];
            $date_b = $b['item']['date_creation'] ?? $b['item']['date'];
            $diff = strtotime($date_a) - strtotime($date_b);
            return $reverse ? 0 - $diff : $diff;
        });

This messes the order up as the date_creation is the same for all tasks as the rule module processed them in the same seconds.
@cconard96: Maybe you can make the function from the rule processing less efficent and slower tongue

Offline

#10 2023-10-25 02:18:40

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: Rules: Adding tasks is not respecting order

Rafumel1774 wrote:

This messes the order up as the date_creation is the same for all tasks as the rule module processed them in the same seconds.
@cconard96: Maybe you can make the function from the rule processing less efficent and slower tongue

Or, we could just sort by creation date and then ID tongue

I made a pull request for a potential fix:
https://github.com/glpi-project/glpi/pull/15856

You can see the changes made on the "Files changed" tab. Only the changes made to "src/CommonITILObject.php" apply. The rest is just for code tests.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#11 2023-10-25 09:10:48

Rafumel1774
Member
Registered: 2019-05-11
Posts: 131

Re: Rules: Adding tasks is not respecting order

Guess thats why you are the developers wink

Yes, I can confirm that it is working fine and fixed the order for all open tickets in my system without affecting other tasks.

Thank you!

Offline

Board footer

Powered by FluxBB