Book Image

Redmine Plugin Extension and Development

By : Alex Bevilacqua
Book Image

Redmine Plugin Extension and Development

By: Alex Bevilacqua

Overview of this book

Table of Contents (16 chapters)
Redmine Plugin Extension and Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Model hooks


These hooks are used even less frequently than controller hooks but are being included here for completeness.

Model extension is better handled through the use of new methods or encapsulation of existing methods by means of the alias_method_chain pattern. For a summary of alias_method_chain see http://stackoverflow.com/a/3697391.

A common use-case for model hooks is the :model_project_copy_before_save hook as this can be used to replicate content from our plugin that belonged to a specific project if that project is copied:

module RedmineKnowledgebase
  class Hooks < Redmine::Hook::ViewListener
    def model_project_copy_before_save(context = {})
      source = context[:source_project]
      destination = context[:destination_project]

      if source.module_enabled?(:redmine_knowledgebase)
        # TODO: clone all categories
        # TODO: clone all articles
        # TODO: ensure cloned articles refer to cloned categories 
      end
    end
  end
end

The actual implementation...