Loading...
 
Skip to main content

Change in condition inside a calculation field (breaks rebuilt index operation and calculation)

Status
Closed
Subject
Change in condition inside a calculation field (breaks rebuilt index operation and calculation)
Version
21.x
21.x Regression
Category
  • Regression
  • Usability
Feature
Advanced Rating Language / Mathematical calculation tracker field
Trackers
Resolution status
Partially solved
Submitted by
Bernard Sfez / Tiki Specialist
Lastmod by
Bernard Sfez / Tiki Specialist
Rating
(0)
Related-to
Description

Due to (I guess) change in the calculation field, the if condition or the way the index is rebuilt a previous condition to perform a calculation stopped to work and interfere with the rebuild index operation.

calculation that doesn't work
Copy to clipboard
(if timeworkDateIn (round (div (sub timeworkDateOut timeworkDateIn) 3600)1))


The "if" here was checking if there is a value in the field "timeworkDateIn" to avoid a different error (Divide by zero on "0") that was displayed to the visitor of the site. After I upgrade this Tiki20 to Tiki21 I got an error on rebuild index:

Copy to clipboard
[root@server html]# php console.php i:r --log [04-03-2020 09:48] Started rebuilding index... logging to file: /tmp/Search_Indexer_mysql_tsaharoniki_tiki21_console.log Unified search engine: MySQL, version 10.1.44-MariaDB error: The search index could not be rebuilt. Variable not found "timeworkDateIn". .../... 2020-03-04T09:48:36+02:00 INFO (6): addDocument trackeritem 53 {"memoryUsage":"22.3 MiB"} (where it stopped)


I found a workaround see below, but we should have a way to keep it as is or to better verbose so the admin knows what to do.

Long story

I have a field that calculate time from 2 dates field to set a work clock.
Worker enter when he come to work and when he get out.
The calculation is done on save so data are updated constantly and the user can see results in real time.

Image

It was working fine on Tiki20.

Since I upgraded to Tiki21 it has stopped to work.
(on the sample a new employee entered 3 row after the Tiki was upgraded)
Image

@Roberto: I think we have similar case setup as we worked together on some solution for a "Tiki" company 😊 but else I can provide playground to help.

Update1

I got an error on rebuild index:

Copy to clipboard
[root@server html]# php console.php i:r --log [04-03-2020 09:48] Started rebuilding index... logging to file: /tmp/Search_Indexer_mysql_tsaharoniki_tiki21_console.log Unified search engine: MySQL, version 10.1.44-MariaDB error: The search index could not be rebuilt. Variable not found "timeworkDateIn". .../... 2020-03-04T09:48:36+02:00 INFO (6): addDocument trackeritem 53 {"memoryUsage":"22.3 MiB"} (where it stopped)


trackeritem 53 is an old work clock item (closed).
The calculation was ok and all field looked ok.
I edited and saved and had the following error:

Copy to clipboard
The search index could not be updated. The site is misconfigured. Contact an administrator. Variable not found "timeworkDateIn".


The field is here and the permaname is correct:
Image

Retested on the same Tiki still on version 20 (I kept for test) and there it is working fine.
(calculaltion are made, indexing is ok)

I escalated the bug to upgrade blocker.
If something corrupt a working index or block Tiki from indexing then it just kill the website (IMO).

Update2

Above I see that the operation stopped very early, trackeritem 53 (I have more than 1500 trackeritems).
It stopped because it couldn’t find the field "timeworkDateIn" during a calculation.

I have 2 calculation field that use the same field "timeworkDateIn"
If I keep the first one and remove the second it work:

First calculation
Copy to clipboard
(concat (date (str F) (str-to-time (str +0 day) timeworkDateIn)) (str |) timeworkName)

second calculation that doesn't work
Copy to clipboard
(if timeworkDateIn (round (div (sub timeworkDateOut timeworkDateIn) 3600)1))


I reworked the code starting by the smallest value and up till the complete formula;
From: (sub timeworkDateOut timeworkDateIn)
To: (if (IsEmpty timeworkDateIn) NA (round (div (sub timeworkDateOut timeworkDateIn) 3600)1))


Solution
Was temporary or was solved
Workaround

Use instead isEmpty to test if a field as a value.
(if (IsEmpty timeworkDateIn) NA (round (div (sub timeworkDateOut timeworkDateIn) 3600)1))

I can rebuild the index, but the error is back and displayed.

Copy to clipboard
Divide by zero on "0"


Note: (if (IsEmpty timeworkDateIn) NA exist) return the expected result so the condition is working.
It is unclear why I got the Divide by zero warning.

Importance
7
Easy to solve?
5
Priority
35
Demonstrate Bug on Tiki 19+
Demonstrate Bug (older Tiki versions)
Ticket ID
7304
Created
Wednesday 04 March, 2020 07:46:52 UTC
by Bernard Sfez / Tiki Specialist
LastModif
Sunday 04 July, 2021 11:45:13 UTC


Show PHP error messages