blob: 49441f9fcd65b6e10bf4b429f7a599fee789052e [file] [log] [blame]
require 'open-uri'
class OtherController < ApplicationController
layout 'management'
before_filter :authenticate_cadmin, :only => [:reset]
protect_from_forgery :except => [:reset]
FLASH_WARNING = "Click the link to reset the EPF Wiki database. All changes will be lost!"
FLASH_SUCCESS = "Database reset complete!"
# Action #info displays information this application
def about
@version = Utils.db_script_version(ENV['EPFWIKI_ROOT_DIR'] + "db/migrate")
sql = 'select max(version) from schema_migrations'
@database_schema = ActiveRecord::Base.connection.execute(sql).extend(Enumerable).to_a.first.first
if @database_schema.to_s == @version.to_s
@version = nil
else
flash.now['warning'] = "Database seems out-of-date. Available scripts are of a higher version. Available is " + @version.to_s + ", installed is " + @database_schema.to_s
end
config = Rails.configuration.database_configuration
@host = config[Rails.env]["host"]
@database = config[Rails.env]["database"]
@username = config[Rails.env]["username"]
end
# Action #error is redirected to from ApplicationController.resque_action_in_public
# to display a userfriendly error message
def error
end
# See routes.rb
def show404
flash.now['error'] = 'The page you\'ve requested cannot be found.'
render :action => 'error', :status => 404
end
def reset
if request.post?
DaText.delete_all
Page.delete_all
Version.delete_all
Site.delete_all
Checkout.delete_all
Notification.delete_all
Update.delete_all
Upload.delete_all
User.delete_all
['pages','development_sites','development_wikis','development_diffs',
'test_diffs','test_sites','test_wikis','wikis',
'uploads','bp' ].each do |entry|
FileUtils.rm_rf "public/#{entry}" if File.exists? "public/#{entry}"
end
reset_session
expire_cookie
flash['success'] = FLASH_SUCCESS
redirect_to :controller => 'login', :action => 'new_cadmin'
else
flash['warning'] = FLASH_WARNING
end
end
end