summaryrefslogtreecommitdiffstats
path: root/app/models/wiki.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-11-23 13:36:01 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-11-23 13:36:01 +0000
commite0a034164f3409336f686cfa381da8a5db15c40e (patch)
treee4bd9590116c03026375a3ae5c618e01cd7bddc3 /app/models/wiki.rb
parent1ada789a6ccbbbaa55adc3a661ea7cef917d4b71 (diff)
downloadredmine-e0a034164f3409336f686cfa381da8a5db15c40e.tar.gz
redmine-e0a034164f3409336f686cfa381da8a5db15c40e.zip
Move wiki page to other project (#5450).
git-svn-id: http://svn.redmine.org/redmine/trunk@13643 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/wiki.rb')
-rw-r--r--app/models/wiki.rb14
1 files changed, 11 insertions, 3 deletions
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: