pluginsGLPI / geninventorynumber

Inventorynumber generation
GNU General Public License v3.0
8 stars 14 forks source link

Fix generation pattern handling #60

Closed kabassanov closed 2 years ago

kabassanov commented 2 years ago

Prefixing inventory numbers by some text was removed in version 2.6. People trying to migrate from GLPI 9.5 to GLPI 10 will create text strings instead of real inventory numbers. The proposed modification reenables the previous feature...

cedric-anne commented 2 years ago

Hi,

I pushed a commit to handle more cases (with prefix and/or suffix and extra chars inside <> and also when string contains other < and >.

Could you test it ?

kabassanov commented 2 years ago

Hi, OK, I'll try to test tomorrow. But I wonder what is the meaning of autonum and the end of mask filter (in particular < at the beginning and the # mark at the end...

(?<autonum>[^<#]*(?<mask>#{1,10})[^#>]*)

cedric-anne commented 2 years ago

Hi,

/
^(?<prefix>.*)                # capture every char located before the "autonum" part
<                             # "<" char that indicates beginning of the "autonum" part
(?<autonum>
   [^<#>]*                    # any char that is not "#", "<" or ">"
   (?<mask>#{1,10})           # mask part
   [^<#>]*                    # any char that is not "#", "<" or ">"
)
>                             # ">" char that indicates ending the "autonum" part
(?<suffix>.*)$                # capture every char located after the "autonum" part
/
kabassanov commented 2 years ago

Hi, I used the following test sets ang got these results:

  1. <###> 8108
  2. <####> 8109
  3. <###########> <###########>
  4. <SUB-####> SUB-8111
  5. <SUB-<####> <SUB-8112
  6. INV-TEXT INV-TEXT
  7. INV-<####> INV-8114
  8. <INV-<####> <INV-8115
  9. INV-<SUB-####> INV-SUB-8116
  10. INV-<<####> INV-<8117
  11. INV-<#SUB####> INV-<#SUB####>
  12. INV-<SUB#SUB-####> INV-
  13. INV-<SUB<SUB-####> INV-<SUBSUB-8120
  14. INV-<#SUB-####> INV-<#SUB-####>
  15. INV-<###########> INV-<###########>
  16. INV-<####>> INV-8123>
  17. INV-<####-SUB> INV-8124-SUB
  18. INV-<####-SUB>> INV-8125-SUB>
  19. INV-<####-SUB#> INV-<####-SUB#>
  20. INV-<####-SUB>SUB> INV-8127-SUBSUB>
  21. INV-<####-SUB#SUB> INV-<####-SUB#SUB>
  22. INV-<####>-POST INV-8129-POST
  23. <####>->POST 8130->POST 24. INV-<SUB>####> INV-####> * 25. INV-<####<SUB> INV-####> **

I hope I didn't miss some important cases...

cedric-anne commented 2 years ago

I will try to handle these cases properly.

kabassanov commented 2 years ago

Didn't take care, but 8130 is also displayed in a particular way: image

cedric-anne commented 2 years ago

I updated the pattern and the way we find mask length.

It should result in

Case n° pattern before after
11 INV-<#SUB####> INV-<#SUB####> INV-#SUB0011
12 INV-<SUB#SUB-####> INV- INV-SUB#SUB-0012
14 INV-<#SUB-####> INV-<#SUB-####> INV-#SUB-0014
15 INV-<###########> INV-<###########> INV-0000000015#
19 INV-<####-SUB#> INV-<####-SUB#> INV-0019-SUB#
21 INV-<####-SUB#SUB> INV-<####-SUB#SUB> INV-0021-SUB#SUB
24 INV-<SUB>####> INV-<SUB>####> INV-SUB>0024
25 INV-<####<SUB> INV-<####<SUB> INV-0025<SUB

I also fixed missing escaping when template was not recognized.

kabassanov commented 2 years ago

I forgot the following case:

INV-<<##########>> INV-<0000008134>

It seemed to work with your intermediate version. Hope it is still working.

cedric-anne commented 2 years ago

INV-<<##########>>

Still working with commits I pushed.

kabassanov commented 2 years ago

OK, let's move ahead. Do I have to do anything for the merge?