kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.4 KiB
65 lines
2.4 KiB
#-- copyright
|
|
# OpenProject is a project management system.
|
|
#
|
|
# Copyright (C) 2011-2013 the OpenProject Team
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License version 3.
|
|
#
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
#++
|
|
|
|
class MergeMeetingContentVersionsWithJournals < ActiveRecord::Migration
|
|
def self.up
|
|
# The table doesn't exist on fresh installations
|
|
if table_exists? :meeting_content_versions
|
|
# This is provided here for migrating up after the MeetingContent::Version class has been removed
|
|
unless MeetingContent.const_defined?("Version")
|
|
MeetingContent.const_set("Version", Class.new(ActiveRecord::Base))
|
|
end
|
|
|
|
# load some classes
|
|
MeetingAgenda
|
|
MeetingMinutes
|
|
|
|
# avoid touching WikiContent on journal creation
|
|
MeetingAgendaJournal.class_exec {
|
|
def touch_journaled_after_creation
|
|
end
|
|
}
|
|
MeetingMinutesJournal.class_exec {
|
|
def touch_journaled_after_creation
|
|
end
|
|
}
|
|
|
|
cache = Hash.new{|h,k| h[k] = Hash.new{|h,k| h[k] = Hash.new{|h,k| h[k] = {}}}}
|
|
|
|
MeetingContent::Version.find_by_sql('SELECT * FROM meeting_content_versions ORDER BY version ASC').each do |mcv|
|
|
options = {:journaled_id => mcv.meeting_content_id, :created_at => mcv.created_at,
|
|
:user_id => mcv.author_id, :notes => mcv.comment, :activity_type => 'meetings',
|
|
:version => mcv.version}
|
|
ft = [cache[mcv.meeting_content_id][mcv.versioned_type][mcv.version-1][:locked], mcv.locked]
|
|
options[:changes] = {'locked' => ft} unless mcv.version == 1 || ft.first == ft.last
|
|
journal = case mcv.versioned_type
|
|
when 'MeetingAgenda'
|
|
MeetingAgendaJournal.create! options
|
|
when 'MeetingMinutes'
|
|
MeetingMinutesJournal.create! options
|
|
end
|
|
journal.text = mcv.text unless mcv.text == cache[mcv.meeting_content_id][mcv.versioned_type][mcv.version-1][:text]
|
|
cache[mcv.meeting_content_id][mcv.versioned_type][mcv.version] = {:text => mcv.text, :locked => mcv.locked}
|
|
end
|
|
|
|
drop_table :meeting_content_versions
|
|
end
|
|
|
|
change_table :meeting_contents do |t|
|
|
t.rename :version, :lock_version
|
|
t.remove :comment
|
|
end
|
|
end
|
|
|
|
def self.down
|
|
raise ActiveRecord::IrreversibleMigration, "Can't revert to pre-journalized versioning model"
|
|
end
|
|
end
|
|
|