Expire pages that want file, when file is successfully uploaded
Reported by Andrew Stacey
This commit is contained in:
parent
ee05118e8f
commit
c603aca852
|
@ -18,6 +18,9 @@ class FileController < ApplicationController
|
||||||
new_file = @web.wiki_files.create(params['file'])
|
new_file = @web.wiki_files.create(params['file'])
|
||||||
if new_file.valid?
|
if new_file.valid?
|
||||||
flash[:info] = "File '#{@file_name}' successfully uploaded"
|
flash[:info] = "File '#{@file_name}' successfully uploaded"
|
||||||
|
WikiReference.pages_that_want_file(@web, @file_name).each do |page|
|
||||||
|
RevisionSweeper.expire_page(page)
|
||||||
|
end
|
||||||
redirect_to(params['referring_page'])
|
redirect_to(params['referring_page'])
|
||||||
else
|
else
|
||||||
# pass the file with errors back into the form
|
# pass the file with errors back into the form
|
||||||
|
|
|
@ -25,6 +25,10 @@ class RevisionSweeper < ActionController::Caching::Sweeper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.expire_page(page)
|
||||||
|
new.expire_caches(page)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def expire_caches(page)
|
def expire_caches(page)
|
||||||
|
|
|
@ -51,6 +51,15 @@ class WikiReference < ActiveRecord::Base
|
||||||
names = connection.select_all(sanitize_sql([query, file_name])).map { |row| row['name'] }
|
names = connection.select_all(sanitize_sql([query, file_name])).map { |row| row['name'] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.pages_that_want_file(web, file_name)
|
||||||
|
query = 'SELECT name FROM pages JOIN wiki_references ' +
|
||||||
|
'ON pages.id = wiki_references.page_id ' +
|
||||||
|
'WHERE wiki_references.referenced_name = ? ' +
|
||||||
|
"AND wiki_references.link_type in ('#{WANTED_FILE}') " +
|
||||||
|
"AND pages.web_id = '#{web.id}'"
|
||||||
|
names = connection.select_all(sanitize_sql([query, file_name])).map { |row| row['name'] }
|
||||||
|
end
|
||||||
|
|
||||||
def self.pages_that_include(web, page_name)
|
def self.pages_that_include(web, page_name)
|
||||||
query = 'SELECT name FROM pages JOIN wiki_references ' +
|
query = 'SELECT name FROM pages JOIN wiki_references ' +
|
||||||
'ON pages.id = wiki_references.page_id ' +
|
'ON pages.id = wiki_references.page_id ' +
|
||||||
|
|
Loading…
Reference in a new issue