diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6b0fe707619..219f7644fda 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1144,7 +1144,6 @@ class ApplicationController < ActionController::Base # the page title. def get_wiki_page @wiki = @context.wiki - @wiki.check_has_front_page @page_name = params[:wiki_page_id] || params[:id] || (params[:wiki_page] && params[:wiki_page][:title]) if(params[:format] && !['json', 'html'].include?(params[:format])) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 765cc4648ed..ce9c1affc67 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1492,7 +1492,6 @@ class CoursesController < ApplicationController # make sure the wiki front page exists if @course_home_view == 'wiki' - @context.wiki.check_has_front_page @course_home_view = 'feed' if @context.wiki.front_page.nil? end diff --git a/app/controllers/wiki_pages_api_controller.rb b/app/controllers/wiki_pages_api_controller.rb index dad62081c1f..813992f98b7 100644 --- a/app/controllers/wiki_pages_api_controller.rb +++ b/app/controllers/wiki_pages_api_controller.rb @@ -485,7 +485,6 @@ class WikiPagesApiController < ApplicationController def get_wiki_page @wiki = @context.wiki - @wiki.check_has_front_page # attempt to find an existing page url = params[:url] diff --git a/app/models/importers/course_content_importer.rb b/app/models/importers/course_content_importer.rb index a5919ebe85e..a7ff80c7371 100644 --- a/app/models/importers/course_content_importer.rb +++ b/app/models/importers/course_content_importer.rb @@ -137,7 +137,6 @@ module Importers end # be very explicit about draft state courses, but be liberal toward legacy courses - course.wiki.check_has_front_page if course.wiki.has_no_front_page if migration.for_course_copy? && (source = migration.source_course || Course.where(id: migration.migration_settings[:source_course_id]).first) mig_id = CC::CCHelper.create_key(source.wiki.front_page) diff --git a/app/models/wiki.rb b/app/models/wiki.rb index dc631b23dcf..19b3206496f 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -42,7 +42,7 @@ class Wiki < ActiveRecord::Base DEFAULT_FRONT_PAGE_URL = 'front-page' def set_has_no_front_page_default - if self.has_no_front_page.nil? && self.id && context + if self.has_no_front_page.nil? self.has_no_front_page = true end end @@ -72,15 +72,6 @@ class Wiki < ActiveRecord::Base end end - def check_has_front_page - return unless self.has_no_front_page.nil? - - url = DEFAULT_FRONT_PAGE_URL - self.has_no_front_page = !self.wiki_pages.not_deleted.where(:url => url).exists? - self.front_page_url = url unless self.has_no_front_page - self.save - end - def front_page url = self.get_front_page_url return nil if url.nil? @@ -129,7 +120,7 @@ class Wiki < ActiveRecord::Base def context shard.activate do - @context ||= Course.where(wiki_id: self).first || Group.where(wiki_id: self).first + @context ||= self.id && (Course.where(wiki_id: self).first || Group.where(wiki_id: self).first) end end diff --git a/db/migrate/20150415152143_set_wiki_has_no_front_page.rb b/db/migrate/20150415152143_set_wiki_has_no_front_page.rb new file mode 100644 index 00000000000..128eb56679e --- /dev/null +++ b/db/migrate/20150415152143_set_wiki_has_no_front_page.rb @@ -0,0 +1,11 @@ +class SetWikiHasNoFrontPage < ActiveRecord::Migration + tag :postdeploy + + def up + DataFixup::SetWikiHasNoFrontPage.send_later_if_production_enqueue_args(:run, + :priority => Delayed::LOWER_PRIORITY) + end + + def down + end +end \ No newline at end of file diff --git a/lib/data_fixup/set_wiki_has_no_front_page.rb b/lib/data_fixup/set_wiki_has_no_front_page.rb new file mode 100644 index 00000000000..96abf94eb82 --- /dev/null +++ b/lib/data_fixup/set_wiki_has_no_front_page.rb @@ -0,0 +1,9 @@ +module DataFixup::SetWikiHasNoFrontPage + def self.run + while Wiki.where(:has_no_front_page => nil, :front_page_url => nil). + where("NOT EXISTS (SELECT 1 FROM wiki_pages WHERE id=wiki_pages.wiki_id AND wiki_pages.url = ?)", + Wiki::DEFAULT_FRONT_PAGE_URL). + limit(1000).update_all(:has_no_front_page => true) > 0 + end + end +end diff --git a/spec/models/content_migration/course_copy_wiki_spec.rb b/spec/models/content_migration/course_copy_wiki_spec.rb index b69122918df..c597a2e2f95 100644 --- a/spec/models/content_migration/course_copy_wiki_spec.rb +++ b/spec/models/content_migration/course_copy_wiki_spec.rb @@ -50,14 +50,23 @@ describe ContentMigration do context "wiki front page" do it "should copy wiki front page setting if there is no front page" do - page = @copy_from.wiki.wiki_pages.create!(:title => "stuff and stuff") - @copy_from.wiki.set_front_page_url!(page.url) + fake_front_page = @copy_from.wiki.wiki_pages.create!(:title => "Front Page") + real_front_page = @copy_from.wiki.wiki_pages.create!(:title => "actual front page") + @copy_from.wiki.set_front_page_url!(real_front_page.url) - @copy_to.wiki.unset_front_page! run_course_copy - new_page = @copy_to.wiki.wiki_pages.where(migration_id: mig_id(page)).first - expect(@copy_to.wiki.front_page).to eq new_page + new_front_page = @copy_to.wiki.wiki_pages.where(migration_id: mig_id(real_front_page)).first + expect(@copy_to.wiki.front_page).to eq new_front_page + end + + it "should not set 'Front Page' as the front page" do + fake_front_page = @copy_from.wiki.wiki_pages.create!(:title => "Front Page") + + run_course_copy + + @copy_to.reload + expect(@copy_to.wiki.front_page).to be_nil end it "should not overwrite current front page" do