Commit d7768ce6 authored by Tim Felgentreff's avatar Tim Felgentreff

remove journals to start moving it all out to vestal_versions based plugin

parent f2957176
......@@ -25,10 +25,9 @@ class Issue < ActiveRecord::Base
belongs_to :priority, :class_name => 'IssuePriority', :foreign_key => 'priority_id'
belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
has_many :journals, :as => :journalized, :dependent => :destroy
has_many :time_entries, :dependent => :delete_all
has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC"
has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
......@@ -36,16 +35,15 @@ class Issue < ActiveRecord::Base
acts_as_attachable :after_remove => :attachment_removed
acts_as_customizable
acts_as_watchable
acts_as_journalized :event_title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.status}): #{o.subject}"},
:event_type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') },
:activity_find_options => {:include => [:project, :author, :tracker]}
acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"],
:include => [:project, :journals],
:include => [:project, :changes],
# sort by id so that limited eager loading doesn't break with postgresql
:order_column => "#{table_name}.id"
acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.status}): #{o.subject}"},
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}},
:type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') }
acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]},
:author_key => :author_id
:order_column => "#{table_name}.id"
DONE_RATIO_OPTIONS = %w(issue_field issue_status)
......
class Journal < ActiveRecord::Base
self.abstract_class = true
belongs_to :user
serialize :details
attr_accessor :indice
before_save :check_for_empty_journal
def check_for_empty_journal
# Do not save an empty journal
!(details.empty? && notes.blank?)
end
def journalized
nil
end
def project
journalized.respond_to?('project') ? journalized.project: nil
end
end
......@@ -19,6 +19,9 @@ class Version < ActiveRecord::Base
after_update :update_issues_from_sharing_change
belongs_to :project
has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id', :dependent => :nullify
acts_as_journalized
acts_as_customizable
acts_as_attachable :view_permission => :view_files,
:delete_permission => :manage_files
......
......@@ -36,11 +36,11 @@ Rails::Initializer.run do |config|
# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector
config.active_record.observers = :message_observer, :issue_observer, :journal_observer, :news_observer, :document_observer, :wiki_content_observer
config.active_record.observers = :message_observer, :issue_observer, :news_observer, :document_observer, :wiki_content_observer
# Make Active Record use UTC-base instead of local time
# config.active_record.default_timezone = :utc
# Use Active Record's schema dumper instead of SQL when creating the test database
# (enables use of different database adapters for development and test environments)
# config.active_record.schema_format = :ruby
......
require File.dirname(__FILE__) + '/lib/acts_as_journalized'
ActiveRecord::Base.send(:include, Redmine::Acts::Journalized)
module Redmine
module Acts
module Journalized
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def acts_as_journalized(options = {})
return if self.included_modules.include?(Redmine::Acts::Journalized::InstanceMethods)
self.include Redmine::Acts::Journalized::InstanceMethods
plural_name = self.name.underscore.pluralize
journal_name = "#{self.name}Journal"
extra_module = options.delete(:extra_module)
event_hash = {
:description => :notes,
:author => Proc.new {|o| User.find_by_id(o.journal.user_id)},
:url => Proc.new do |o|
{
:controller => self.name.underscore.pluralize,
:action => 'show',
:id => o.id,
:anchor => "change-#{o.id}"
}
end
}
activity_hash = {
:type => plural_name,
:permission => "view_#{plural_name}".to_sym,
:author_key => :user_id,
}
options.each_pair do |k, v|
case
when key = k.to_s.slice(/event_(.+)/, 1)
event_hash[key.to_sym] = v
when key = k.to_s.slice(/activity_(.+)/, 1)
activity_hash[key.to_sym] = v
end
end
# create the new model class
journal = Class.new(Journal)
journal.belongs_to self.name.underscore
journal.acts_as_event event_hash
journal.acts_as_activity_provider activity_hash
journal.send(:include, extra_module)
Object.const_set("#{self.name}Journal", journal)
unless Redmine::Activity.providers[plural_name].include? self.name
Redmine::Activity.register plural_name.to_sym
end
end
end
module InstanceMethods
def self.included(base)
base.extend ClassMethods
base.class_eval do
after_save :create_journal
has_many :journals, :class_name => "#{self.name}Journal", :dependent => :destroy
end
end
def journal_class
"#{self.class.name}Journal".constantize
end
def init_journal(user, notes = "")
@notes ||= ""
@current_journal ||= journal_class.new(:journalized => self, :user => user, :notes => notes)
@object_before_change = self.clone
@object_before_change.status = self.status
if self.respond_to? :custom_values
@custom_values_before_change = {}
self.custom_values.each {|c| @custom_values_before_change[c.custom_field_id] = c.value }
end
# Make sure updated_on is updated when adding a note.
updated_on_will_change!
@current_journal
end
# Saves the changes in a Journal
# Called after_save
def create_journal
if @current_journal
details = {:attr => {}}
if self.respond_to? :custom_values
details[:cf] = {}
end
# attributes changes
self.class.journalized_columns.each do |c|
unless send(c) == @object_before_change.send(c)
details[:attr][c] = {
:old => @object_before_change.send(c),
:new => send(c)
}
end
end
if self.respond_to? :custom_values
# custom fields changes
custom_values.each do |c|
unless ( @custom_values_before_change[c.custom_field_id]==c.value ||
(@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?))
details[:cf][c.custom_field_id] = {
:old => @custom_values_before_change[c.custom_field_id],
:new => c.value
}
end
end
end
@current_journal.details = details
@current_journal.save
end
end
module ClassMethods
def journalized_columns=(columns = [])
@journalized_columns = columns
end
def journalized_columns
@journalized_columns ||= begin
(self.column_names - %w(id description lock_version created_on updated_on))
end
end
end
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment