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

Fix WikiPage#destroy when destroying child, then parent

Oliver Günther1f6288233190
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index 9d5f58bcb74..885f23eab0b 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -93,6 +93,18 @@ class WikiPage < ApplicationRecord
title.to_localized_slug(locale: :en)
end
+ # Using a hook will not allow us to retry the call
+ # rubocop:disable Rails/ActiveRecordOverride
+ def destroy
+ super
+ rescue ActiveRecord::StaleObjectError
+ # Due to closure_tree, parent_id might have changed
+ # when destroying all wiki pages
+ reload
+ super
+ end
+ # rubocop:enable Rails/ActiveRecordOverride
+
def delete_wiki_menu_item
menu_item&.destroy
# ensure there is a menu item for the wiki