From e0a034164f3409336f686cfa381da8a5db15c40e Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 23 Nov 2014 13:36:01 +0000 Subject: Move wiki page to other project (#5450). git-svn-id: http://svn.redmine.org/redmine/trunk@13643 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/wiki.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'app/models/wiki.rb') diff --git a/app/models/wiki.rb b/app/models/wiki.rb index b1ce29743..ce06a2a6e 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -19,7 +19,7 @@ class Wiki < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :project has_many :pages, lambda {order('title')}, :class_name => 'WikiPage', :dependent => :destroy - has_many :redirects, :class_name => 'WikiRedirect', :dependent => :delete_all + has_many :redirects, :class_name => 'WikiRedirect' acts_as_watchable @@ -27,6 +27,8 @@ class Wiki < ActiveRecord::Base validates_format_of :start_page, :with => /\A[^,\.\/\?\;\|\:]*\z/ attr_protected :id + before_destroy :delete_redirects + safe_attributes 'start_page' def visible?(user=User.current) @@ -52,11 +54,11 @@ class Wiki < ActiveRecord::Base title = start_page if title.blank? title = Wiki.titleize(title) page = pages.where("LOWER(title) = LOWER(?)", title).first - if !page && !(options[:with_redirect] == false) + if page.nil? && options[:with_redirect] != false # search for a redirect redirect = redirects.where("LOWER(title) = LOWER(?)", title).first if redirect - page = find_page(redirect.redirects_to, :with_redirect => false) + page = redirect.target_page @page_found_with_redirect = true end end @@ -68,6 +70,12 @@ class Wiki < ActiveRecord::Base @page_found_with_redirect end + # Deletes all redirects from/to the wiki + def delete_redirects + WikiRedirect.where(:wiki_id => id).delete_all + WikiRedirect.where(:redirects_to_wiki_id => id).delete_all + end + # Finds a page by title # The given string can be of one of the forms: "title" or "project:title" # Examples: -- cgit v1.2.3