Rake Task - How to update the history of an issue on issue status change

Added by Heiko Jung 4 months ago

I wrote a plugin that is basically a rake task which changes the status of an issue based on some criteria (due date or a "deferred"-date). The task should then, via cron job, run every night to "reenable" the issues that will be due in a configurable number of days.

after filtering the issues I do the following:

deferred_issue.update(status_id: reactivated_state)

where "deferred_issue" is one of the filtered issues and "reactivated_state" contains the index of an issue_status that is configurable in the plugin config dialog.

This works... kind of. The problem with this is, that the status change is not listed afterwards in the issue history.

How can I accomplish that? I'm a total noob and could use some hints that direct me to the correct solution (how to solve problems like this by myself; Which documentation can I use? Where to look in the source code? etc.)

Thanks very much in advance!

Heiko Jung

P.S.: English is not my first language so please accept my apologies if I'm not describing the problem clear enough.

Replies (5)

RE: Rake Task - How to update the history of an issue on issue status change - Added by Liane Hampe 4 months ago

Hi Heiko

A good starting point to solve your problem is to look into the partial which holds the issue history.

You can find it in app/views/issues/tab/history.html.erb.

Best Regards
Liane

RE: Rake Task - How to update the history of an issue on issue status change - Added by Heiko Jung 4 months ago

Hi again,

thank you very much for your help!

I tried to wrap my head around the _history.html.erb partial, but I do not really understand how this can solve my problem.

In my very (very) basic understanding, that partial is part of a view and therefore responsible for DISPLAYING the history information of an issue. What I need is a method to UPDATE/ADD TO the history information from inside a rake task. I'm well aware that I might (slight understatement ;) ) not understand some basic mechanisms how Redmine works but could you please elaborate a little bit more and nudge me into the right direction. I'm a bit lost here.

Is there probably some documentation/tutorial I could read or watch on this topic? I tried to find someting in the book "Redmine Plugin Extension and Development" by Alex Bevilacqua, but besides being a little bit dated, I could'nt find details that would help me. There's a chapter about "Interacting with the Activity Stream" but that uses another plugin ("acts_as_searchable") that does not seem to apply well for a rake task.

Thanks again for your time!

Regards
Heiko

RE: Rake Task - How to update the history of an issue on issue status change - Added by Heiko Jung 4 months ago

Hey,

I'm really sorry, but I'm still completely stuck here.
Can somebody help?

Sorry for the inconvenience!

Best regards
Heiko

RE: Rake Task - How to update the history of an issue on issue status change - Added by Liane Hampe 4 months ago

Hi Heiko

What I meant when suggesting to start with the partial is following the code from the partial down to some method which will help you.

This is one approach to dive deeper into the codebase. Reading the code in the partial would give you a hint which method brings you closer to a solution. That is, you read method by method until you think you will find something useful what you can apply in your rake task.

By the way, there is no explicit tutorial or documentation helping you with your problem. What you need are some general coding experiences with Ruby and Rails. Gaining these experiences needs time and exercise.

When you don't have that time but need to solve your problem quickly, you probably need a paid coaching.

Sorry, I understand that you wish something easier but there is no shortcut.

Best Regards
Liane

RE: Rake Task - How to update the history of an issue on issue status change - Added by Heiko Jung 4 months ago

Well, thanks for the quick reply.

It seems, that I have to find a solution on my own. I'm a system administrator with some programming experience, mostly in Python and other Scripting languages, but at the moment I have to fix this "little" issue in the plugin.

Since this is my only programming project I have to support in Ruby on Rails, I just couldn't gain the experience levels in Ruby and Rails that are needed to solve this all by myself. I just can't justify to my boss, locking myself in a room and "learn myself some Rails" for a week or four ("ain't nobody got time for that!"). I already spent almost three full days on this.
I hoped, that my problem was more on the "trivial" side and somebody else had a similar or even the same problem and that there would be a relatively "simple" solution or at least a practical hint, like for example a specific method call or a hook or something that I just couldn't find with my limited knowledge of Rails and the Redmine codebase.

To be clear, I'm not complaining about your help, in fact I'm really thankful for it, I'm just trying to explain the reason for asking and not "spending the time myself".

So, sorry again for using your time. I really appreciate the effort.

Thanks
Heiko

P.S.: If(!) I find a solution for the problem, I will post it here. So at least the next guy searching for a similar Problem will find it here.

(1-5/5)