Project

General

Profile

Actions

Patch #5717

closed

Request for controller_timelog_edit_after_save hook

Added by Andriy Lesyuk almost 14 years ago. Updated over 11 years ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
Plugin API
Target version:
-
Start date:
2010-06-20
Due date:
% Done:

0%

Estimated time:

Description

The Timelog controller has controller_timelog_edit_before_save hook but does not provide controller_timelog_edit_after_save hook. I believe it should provide the last as well.

Thanks


Files

controller_timelog_edit_after_save.patch (503 Bytes) controller_timelog_edit_after_save.patch Redmine 0.9.4 Andriy Lesyuk, 2010-06-20 23:33
Actions #1

Updated by test test almost 14 years ago

(snip)

Actions #2

Updated by Andriy Lesyuk over 13 years ago

Guys, please apply this patch! :(

Actions #3

Updated by Jean-Baptiste Barth over 13 years ago

Can you just give us some details about your use case ? As said in other issues, we could add hooks everywhere but it will become hard to maintain. Can't you use rails standard callbacks ? Just tell us a bit more.

Actions #4

Updated by Andriy Lesyuk over 13 years ago

There is an external tool which receives notifications from Redmine about new issues, changes in issues... new time entries, changes in time entries etc. I wrote a very little Redmine plugin responsible for sending notification to this tool.

If I "attach" to standard Rails callbacks the external tool fails to find a corresponding record in database because they do not exist yet at the moment of notification. So I found that using hooks works very well - records are always there already.

Actions #5

Updated by Jean-Baptiste Barth over 13 years ago

Andriy Lesyuk wrote:

If I "attach" to standard Rails callbacks the external tool fails to find a corresponding record in database because they do not exist yet at the moment of notification.

Even with an after_save callback on the right object ? (Issue or TimeEntry I presume)

Actions #6

Updated by Andriy Lesyuk over 13 years ago

Yes. I googled a little for this issue and that's what I've found:

For example, if you invoke an external indexer at this point it won‘t see the changes in the database.

http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html#M001373

Actions #7

Updated by Eric Davis over 13 years ago

  • Category changed from Time tracking to Plugin API
  • Assignee set to Eric Davis

Andriy Lesyuk:

Can you post or give me a url to your callback code for this?

The problem with adding hooks in the controller is that they make things really hard for us to change how Redmine works without breaking the hooks. I'm running into this exact same problem with the Issues controller right now.

Actions #8

Updated by Jean-Baptiste Barth over 13 years ago

  • Category changed from Plugin API to Time tracking
  • Status changed from New to 7
  • Assignee changed from Eric Davis to Jean-Baptiste Barth
  • Target version set to 1.0.2

Seems ok to me. Cannot commit this tonight, but I think we'll integrate it in the next version.

Actions #9

Updated by Jean-Baptiste Barth over 13 years ago

  • Category changed from Time tracking to Plugin API
  • Assignee changed from Jean-Baptiste Barth to Eric Davis

Sorry just saw your reply Eric, didn't want to steal you this issue :)

Is there a place where this kind of problem is described ? Do you have ideas to make these hooks a bit more flexible ? For Issue model the save transaction is wrapped in a specific method with our hooks, can we apply it to other models in your opinion ?

Actions #10

Updated by Andriy Lesyuk over 13 years ago

Not sure if this is what you requested:

class IssueHook  < Redmine::Hook::ViewListener

    def controller_issues_new_after_save(context = {})
        if context[:issue] && context[:issue].id.present?
            Monkey.instance.tell("+issue:#{context[:issue].id}/cinas")
        end
    end

    def controller_issues_edit_after_save(context = {})
        if context[:time_entry] && context[:time_entry].id.present?
            Monkey.instance.tell("+entry:#{context[:time_entry].id}/cieas")
        end
        if context[:journal] && context[:journal].id.present?
            Monkey.instance.tell("+journal:#{context[:journal].id}/cieas")
        end
    end

    def controller_issues_bulk_edit_after_save(context = { })
        if context[:journal] && context[:journal].id.present?
            Monkey.instance.tell("+journal:#{context[:journal].id}/cibeas")
        end
    end

    def controller_journals_edit_post(context = { })
        if context[:journal] && context[:journal].id.present? && context[:journal].notes.present?
            Monkey.instance.tell("=journal:#{context[:journal].id}/cjep")
        end
    end

    def controller_timelog_edit_after_save(context = { })
        if context[:time_entry] && context[:time_entry].id.present?
            if context[:params][:id].present?
                Monkey.instance.tell("=entry:#{context[:time_entry].id}/cteas")
            else
                Monkey.instance.tell("+entry:#{context[:time_entry].id}/cteas")
            end
        end
    end

    def controller_bulk_time_entries_new_after_save(context = { })
        if context[:time_entry] && context[:time_entry].id.present?
            Monkey.instance.tell("+entry:#{context[:time_entry].id}/cbtenas")
        end
    end

end

If not - tell me what do you need and I will post.

Actions #11

Updated by Eric Davis over 13 years ago

Andriy Lesyuk wrote:

Not sure if this is what you requested:

From what I see, you can use observers for Issue, TimeEntry, and Journal using the after_save callback provided by Rails. after_save is fired after the record is created so you should be able to access the id.

Actions #12

Updated by Andriy Lesyuk over 13 years ago

Eric Davis wrote:

Andriy Lesyuk wrote:

Not sure if this is what you requested:

From what I see, you can use observers for Issue, TimeEntry, and Journal using the after_save callback provided by Rails. after_save is fired after the record is created so you should be able to access the id.

This id is sent to the external tool written in Perl. This Perl tool then fetches corresponding records from database. If I use Rails callbacks the tool fails to find the records. So, no, I can't use standard Rails callbacks.

Actions #13

Updated by Eric Davis over 13 years ago

  • Target version deleted (1.0.2)

Andriy Lesyuk:

What if you send it to the Perl tool asynchronously or have the Perl script wait for the database to commit the transaction?

If this hook is added, it will end up being removed in a few weeks when I start cleaning up the code in this controller. (See the current IssuesController compared to it 6 months ago to see what kind of cleanup I'm doing)

Actions #14

Updated by Andriy Lesyuk over 13 years ago

Well... I'm not sure that waiting for commit is the best solution in this case. For now I choose patching the code. :) Perhaps in future will try to find some solution not requiring patching.

I checked a little the latest code of IssuesController and found that it still contains hooks. I'm not sure why don't you want to include other hooks like ones suggested by me... It seems that you are just renaming hooks. As soon as you provide a similar after_save hook for timelog I will be happy. :) I don't want you to apply my patch I just want you to provide an after_save hook...

Thanks

Actions #15

Updated by Eric Davis over 13 years ago

  • Assignee deleted (Eric Davis)

I am stepping down from working on Redmine. If someone else is interesting in working on this issue, feel free to reassign it to them.

Eric Davis

Actions #16

Updated by Andriy Lesyuk about 13 years ago

  • Status changed from 7 to Resolved

I don't need this patch anymore...

Actions #17

Updated by Jan Niggemann (redmine.org team member) over 11 years ago

Closing this, status is resolved since 400 days and more (issue was last updated more than 400 days ago)...

Actions #18

Updated by Jan Niggemann (redmine.org team member) over 11 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF