How to catch when project is closed

72 Views Asked by At

Redmine's model Project has a method

  def close
    self_and_descendants.status(STATUS_ACTIVE).update_all :status => STATUS_CLOSED
  end

In this method updating with update_all means that when projects are closed callback after_save is not called.

How do you catch (through model) when a project is closed?

2

There are 2 best solutions below

3
Rustik On

Rails 5 allows to update records with callbacks and validations:

self_and_descendants.status(STATUS_ACTIVE).update(status: STATUS_CLOSED)

For Rails 4 and below you can trigger callbacks by updating records in batches:

self_and_descendants.status(STATUS_ACTIVE).find_each { |record| record.update_attributes(status: STATUS_CLOSED) }
0
Stephan Wiehr On

If you don't want to change the original method in place you could add a plugin patching the close function for you (with the code that Rustik proposed above: https://stackoverflow.com/a/48684242/5961910).