History log and custom fields

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
Anapheron
Posts: 19
Joined: 29 Oct 2015, 21:56

History log and custom fields

Post by Anapheron »

Hi, everyone!
I have a question (i'm kinda of a apprentice on mantis, sorry about that)
i have created a custom field that count the days since that bug has been opened, but i want to update that custom field each time i change the bug status (Open -> Acknowledged, for example)
i haven't configure it to show the text field of that custom field because it updates automaticaly, but the change doesn't appear in history log.
There is a way to put the change in history log without needing the custom field text field?

sorry for my bad english and thanks for the help!
Anapheron
Posts: 19
Joined: 29 Oct 2015, 21:56

Re: History log and custom fields

Post by Anapheron »

Oh, and my mantis version is 1.2.19
aavagyan
Posts: 84
Joined: 08 Dec 2013, 14:23
Location: Germany
Contact:

Re: History log and custom fields

Post by aavagyan »

Hi. How to do update value of that custom field? DB trigger?
Mantis Statistics Plugin: https://www.mantisstats.org
Anapheron
Posts: 19
Joined: 29 Oct 2015, 21:56

Re: History log and custom fields

Post by Anapheron »

i have created a function that update the custom field in DB
each time i call it, it updates the custom field.
aavagyan
Posts: 84
Joined: 08 Dec 2013, 14:23
Location: Germany
Contact:

Re: History log and custom fields

Post by aavagyan »

If you went in the direction of creating function writing to DB, then you can also write to history table, I guess. The structure of history table is very simple.
Mantis Statistics Plugin: https://www.mantisstats.org
Anapheron
Posts: 19
Joined: 29 Oct 2015, 21:56

Re: History log and custom fields

Post by Anapheron »

aavagyan wrote:If you went in the direction of creating function writing to DB, then you can also write to history table, I guess. The structure of history table is very simple.

I thought that too, but when i get the old_value, it returns 0, not the same value if i execute the query directly on MySQL
aavagyan
Posts: 84
Joined: 08 Dec 2013, 14:23
Location: Germany
Contact:

Re: History log and custom fields

Post by aavagyan »

Well, I see two options, I must say:

- digging in PHP until you find what is wrong - why are you getting 0.
- Redoing as DB trigger whole thing - in the case you are strong at DB end (update on bugs table triggers read + calculate + write back + write to history table). You will also need trigger on delete... and on insert probably.

I must say I don't like whole approach because you time will get updated only on action happening with bug. If no action it will show outdated value...
Mantis Statistics Plugin: https://www.mantisstats.org
Anapheron
Posts: 19
Joined: 29 Oct 2015, 21:56

Re: History log and custom fields

Post by Anapheron »

aavagyan wrote: I must say I don't like whole approach because you time will get updated only on action happening with bug. If no action it will show outdated value...
I have called that function in view_all_bug_page.php, view.php, and my_view_page.php before just to give a "dynamic" update, but i'm trying updating by changing status just to see if its possible or not
aavagyan
Posts: 84
Joined: 08 Dec 2013, 14:23
Location: Germany
Contact:

Re: History log and custom fields

Post by aavagyan »

I see. This should work, although doesn't sound like elegant solution. :-) One question - why do you want to record time updates in history log?
Mantis Statistics Plugin: https://www.mantisstats.org
Anapheron
Posts: 19
Joined: 29 Oct 2015, 21:56

Re: History log and custom fields

Post by Anapheron »

aavagyan wrote:I see. This should work, although doesn't sound like elegant solution. :-) One question - why do you want to record time updates in history log?
Well, i have turned off that dynamic update, i can only update by changing the bug status

I need that old_value because i want to "turn back" the days depending on the status

A example:
The bug is Acknowledged at day 20
if i change the status to "Resolved", for example, it was on day 30, so it goes 20 ---> 30, right?
if i change back to "Acknowledged", i want to turn back the day count from 30 to 20
do you understand?
aavagyan
Posts: 84
Joined: 08 Dec 2013, 14:23
Location: Germany
Contact:

Re: History log and custom fields

Post by aavagyan »

OK, I understand. So you will need to iterate through status changes from the history table and depending on old/new status add/subtract corresponding dates. Please have a look at core/history_api.php --> it has plenty of useful functions. For example history_get_events_array, history_get_raw_events_array.
Mantis Statistics Plugin: https://www.mantisstats.org
Anapheron
Posts: 19
Joined: 29 Oct 2015, 21:56

Re: History log and custom fields

Post by Anapheron »

aavagyan wrote:OK, I understand. So you will need to iterate through status changes from the history table and depending on old/new status add/subtract corresponding dates. Please have a look at core/history_api.php --> it has plenty of useful functions. For example history_get_events_array, history_get_raw_events_array.
i'll try that
i have tried custom_field_api and bug_api, i still don't have a look at history_api
Anapheron
Posts: 19
Joined: 29 Oct 2015, 21:56

Re: History log and custom fields

Post by Anapheron »

i'm thinking about searching for the last history update, get its date_modified value (which is in unix timestamp), convert into days and putting as old_value of the new history update
what do you think?
aavagyan
Posts: 84
Joined: 08 Dec 2013, 14:23
Location: Germany
Contact:

Re: History log and custom fields

Post by aavagyan »

To answer without guessing, I need to understand clearly what you need to ger. Is it time that issue was in 'assigned' state, or in all 'open' states, or in selected particular states? Do you need to see same for issues, which are 'new'? If issue is resolved, but then reopened, do you continue incrementing time? Etc. You need to put all situations on the paper before attempting to find solution.

In most of these cases you need to know all status changes with their dates - because, for example, imagine the case what issue was resolved in the middle and then reopened. Once you have array of states+times you can have plus-minus depending on what you need exactly. I don't think getting the last only is any useful. Functions I mentioned should give you this array.

P.S. If you have the simplest case to see time from issue creation to now, then you don't need history table at all. Just have 'now() - submitted_date' and store it in your custom field.
Mantis Statistics Plugin: https://www.mantisstats.org
Anapheron
Posts: 19
Joined: 29 Oct 2015, 21:56

Re: History log and custom fields

Post by Anapheron »

aavagyan wrote:To answer without guessing, I need to understand clearly what you need to ger. Is it time that issue was in 'assigned' state, or in all 'open' states, or in selected particular states? Do you need to see same for issues, which are 'new'? If issue is resolved, but then reopened, do you continue incrementing time? Etc. You need to put all situations on the paper before attempting to find solution.
well, we have particular status where we'll stop counting the days, like closed, for example
we don't continue incrementing time, we'll kinda "go back" to the last time that issue was reopened

aavagyan wrote:P.S. If you have the simplest case to see time from issue creation to now, then you don't need history table at all. Just have 'now() - submitted_date' and store it in your custom field.
that's how i done it before, it has worked, but i'm trying in a diferent way

I tried a condition in history_api in function mantis_log_event_direct were i can insert a new history if the custom field name = 'days'
but it's getting a fatal error because it's not inserting the new_value
PS: all the custom field checkboxes are off in configurations
Post Reply