Sha256: e54337d1494559c2a93e9093498c1871641595a0644b19832fe7401b04f14ffb

Contents?: true

Size: 1.84 KB

Versions: 6

Compression:

Stored size: 1.84 KB

Contents

class Admin::SettingsController < Admin::BaseController

  cache_sweeper :blog_sweeper

  def index
    if this_blog.base_url.blank?
      this_blog.base_url = blog_base_url
    end
    load_settings
  end
  
  def read; load_settings end
  def write; load_settings end
  def feedback; load_settings end
  
  def seo
    load_settings
    if File.exists? "#{RAILS_ROOT}/public/robots.txt"
      @setting.robots = ""
      file = File.readlines("#{RAILS_ROOT}/public/robots.txt")
      file.each do |line|
        @setting.robots << line
      end
    end
  end
  
  def redirect
    flash[:notice] = _("Please review and save the settings before continuing")
    redirect_to :action => "index"
  end

  def update
    if request.post?
      Blog.transaction do
        params[:setting].each { |k,v| this_blog.send("#{k.to_s}=", v) }
        this_blog.save
        flash[:notice] = _('config updated.')
      end
      
      save_robots unless params[:setting][:robots].blank?
      
      redirect_to :action => params[:from]
    end
  rescue ActiveRecord::RecordInvalid
    render :action => params[:from]
  end
  
  def update_database
    @current_version = Migrator.current_schema_version
    @needed_version = Migrator.max_schema_version
    @support = Migrator.db_supports_migrations?
    @needed_migrations = Migrator.available_migrations[@current_version..@needed_version].collect do |mig|
      mig.scan(/\d+\_([\w_]+)\.rb$/).flatten.first.humanize
    end
  end

  def migrate
    if request.post?
      Migrator.migrate
      redirect_to :action => 'update_database'
    end
  end
  
  private
  def load_settings
    @setting = this_blog
  end
  
  def save_robots
    if File.writable? "#{RAILS_ROOT}/public/robots.txt"
      robots = File.new("#{RAILS_ROOT}/public/robots.txt", "r+")
      robots.write(params[:setting][:robots])
      robots.close
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
typo-5.5 app/controllers/admin/settings_controller.rb
typo-5.4.4 app/controllers/admin/settings_controller.rb
typo-5.4.3 app/controllers/admin/settings_controller.rb
typo-5.4.2 app/controllers/admin/settings_controller.rb
typo-5.4.1 app/controllers/admin/settings_controller.rb
typo-5.4 app/controllers/admin/settings_controller.rb