Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Allow lookup of already removed journal class

Oliver Günthera2604cbda22e
diff --git a/db/migrate/20220818074159_fix_deleted_data_journals.rb b/db/migrate/20220818074159_fix_deleted_data_journals.rb
index 68bc6707384..557aead228e 100644
--- a/db/migrate/20220818074159_fix_deleted_data_journals.rb
+++ b/db/migrate/20220818074159_fix_deleted_data_journals.rb
@@ -116,9 +116,7 @@ class FixDeletedDataJournals < ActiveRecord::Migration[7.0]
Journal
.pluck("DISTINCT(journable_type)")
.to_h do |journable_type|
- journal_class = journable_type.constantize.journal_class
- table_name = journal_class.table_name
-
+ table_name = lookup_journal_class_table(journable_type)
relation = Journal
.joins("LEFT OUTER JOIN #{table_name} ON journals.data_type = '#{journal_class}' AND #{table_name}.id = journals.data_id")
.where("#{table_name}.id IS NULL")
@@ -131,6 +129,15 @@ class FixDeletedDataJournals < ActiveRecord::Migration[7.0]
end
end
+ # Lookup table for items that were already deleted
+ def lookup_journal_class_table(journable_type)
+ lookup = { "WikiContent" => "wiki_content_journals" }
+ lookup.fetch(journable_type) do
+ journal_class = journable_type.constantize.journal_class
+ journal_class.table_name
+ end
+ end
+
def take_over_from_successor(journal)
# The successors may also have their data deleted.
# in this case, look for the first journal with data. If non can be found, instantiate from the journaled object.