From e0a7e0fec760ba12c8067a37e10c96f1f05876e2 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Wed, 24 Jun 2026 04:13:16 +0200 Subject: Stage 1 complete: Rails 2.3.5 to Rails 3.2.22.5 upgrade - Converted plugins to gems (Gemfile) - Updated config structure (application.rb, boot.rb, environment.rb) - Converted routes to Rails 3 DSL - Converted named_scope to scope throughout models - Converted find(:all, :conditions) to where() chains - Fixed has_many :order to use ordering scope - Updated session store and secret token configuration - Fixed exception_notification middleware configuration - Patched Ruby 2.4 / Rails 3.2 incompatibilities: - Integer/Float duration arithmetic (ActiveSupport) - Arel visit_Integer for PostgreSQL adapter - create_database String/Integer coercion - ActionController consider_all_requests_local - Migrated taggings schema for acts-as-taggable-on - Replaced dynamic_form gem with custom form_error_messages helper - Fixed Rails 3 block helper syntax (form_for, form_tag, fields_for) - Fixed admin layout yield - Updated test suite for Rails 3 APIs --- app/controllers/admin_controller.rb | 38 ++++++++++++------------------- app/controllers/application_controller.rb | 18 +++++---------- app/controllers/content_controller.rb | 4 ++-- app/controllers/menu_items_controller.rb | 2 +- app/controllers/nodes_controller.rb | 9 +++----- app/controllers/revisions_controller.rb | 1 + app/controllers/rss_controller.rb | 19 +++++----------- app/controllers/tags_controller.rb | 14 +++++------- app/controllers/users_controller.rb | 2 +- 9 files changed, 40 insertions(+), 67 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index f3cc221..18c4104 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -5,21 +5,15 @@ class AdminController < ApplicationController before_filter :login_required def index - @drafts = Node.all( - :limit => 50, - :order => "updated_at desc", - :conditions => ["draft_id IS NOT NULL"] - ) - @drafts_count = Node.count( - :conditions => ["draft_id IS NOT NULL"] - ) - @recent_changes = Node.all( - :limit => 50, - :order => "updated_at desc", - :conditions => [ - "updated_at < ? AND updated_at > ? AND parent_id IS NOT NULL", Time.now, Time.now-14.days - ] - ) + @drafts = Node.where("draft_id IS NOT NULL") + .limit(50).order("updated_at desc") + + @drafts_count = Node.where("draft_id IS NOT NULL").count + + @recent_changes = Node.where( + "updated_at < ? AND updated_at > ? AND parent_id IS NOT NULL", + Time.now, Time.now - 14.days + ).limit(50).order("updated_at desc") all_nodes = Node.root.self_and_descendants @sitemap_depth = {} @@ -28,16 +22,12 @@ class AdminController < ApplicationController end @sitemap = all_nodes.to_a.sort! { |node1,node2| node1.lft <=> node2.lft }.delete_if { |node| node.update? } - @mypages = Page.all( - :conditions => [ "user_id = ? or editor_id = ?", @current_user, @current_user] - ) - - @mynodes = Node.all( - :order => "updated_at desc", - :joins => :pages, - :conditions => [ "pages.user_id = ? or pages.editor_id = ?", @current_user, @current_user ] - ).uniq.first(50) + @mypages = Page.where("user_id = ? or editor_id = ?", @current_user, @current_user) + @mynodes = Node.joins(:pages) + .where("pages.user_id = ? or pages.editor_id = ?", @current_user, @current_user) + .order("updated_at desc") + .uniq.first(50) end def search diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 89cd330..4d0ed2e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,25 +2,19 @@ # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base - - include ExceptionNotifiable include AuthenticatedSystem - helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for details - # Scrub sensitive parameters from your log - filter_parameter_logging :password, :password_confirmation - before_filter :set_locale protected - def set_locale - if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym) - I18n.locale = params[:locale].to_sym - else - params.delete(:locale) - end + def set_locale + if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym) + I18n.locale = params[:locale].to_sym + else + params.delete(:locale) end + end end diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index c62b726..4248239 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -20,7 +20,7 @@ class ContentController < ApplicationController ) else render( - :file => File.join(RAILS_ROOT, 'public', '404.html'), + :file => Rails.root.join('public', '404.html'), :status => 404 ) end @@ -38,7 +38,7 @@ class ContentController < ApplicationController private def find_page - path = params[:page_path].join('/') + path = params[:page_path].is_a?(Array) ? params[:page_path].join('/') : params[:page_path] if path =~ /^[a-zA-Z\:\/\/\.\-\d_]+$/ @page = Node.find_page(path) else diff --git a/app/controllers/menu_items_controller.rb b/app/controllers/menu_items_controller.rb index 808da15..24a3d5e 100644 --- a/app/controllers/menu_items_controller.rb +++ b/app/controllers/menu_items_controller.rb @@ -7,7 +7,7 @@ class MenuItemsController < ApplicationController layout 'admin' def index - @menu_items = MenuItem.all(:order => "position ASC") + @menu_items = MenuItem.order("position ASC").all end def show diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index 95aed48..7c082c4 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb @@ -15,12 +15,9 @@ class NodesController < ApplicationController ] def index - @nodes = Node.root.descendants.paginate( - :include => [:head, :draft], - :page => params[:page], - :per_page => 25, - :order => 'id DESC' - ) + @nodes = Node.root.descendants.includes(:head, :draft) + .order('id DESC') + .paginate(:page => params[:page], :per_page => 25) end def new diff --git a/app/controllers/revisions_controller.rb b/app/controllers/revisions_controller.rb index 05e8acc..8c16730 100644 --- a/app/controllers/revisions_controller.rb +++ b/app/controllers/revisions_controller.rb @@ -8,6 +8,7 @@ class RevisionsController < ApplicationController def index @node = Node.find(params[:node_id]) + @pages = @node.pages.all end def diff diff --git a/app/controllers/rss_controller.rb b/app/controllers/rss_controller.rb index acffc0e..70a642c 100644 --- a/app/controllers/rss_controller.rb +++ b/app/controllers/rss_controller.rb @@ -7,12 +7,9 @@ class RssController < ApplicationController expires_in 31.minutes, :public => true I18n.locale = :de - - @items = Page.heads.find_tagged_with( - "update", - :order => "published_at DESC", - :limit => 20 - ) + + @items = Page.heads.tagged_with("update") + .order("published_at DESC").limit(20) respond_to do |format| format.xml {} @@ -21,13 +18,9 @@ class RssController < ApplicationController end def recent_changes - @items = Page.all( - :limit => 20, - :order => "updated_at desc", - :conditions => [ - "updated_at < ? AND updated_at > ?", Time.now, Time.now-14.days - ] - ) + @items = Page.where( + "updated_at < ? AND updated_at > ?", Time.now, Time.now - 14.days + ).limit(20).order("updated_at desc") end protected diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index bf64b73..f09d560 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -5,7 +5,7 @@ class TagsController < ApplicationController def index @page = Page.new :title => "Tags" - @tags = Tag.all(:limit => 500) + @tags = Tag.limit(500).all end def show @@ -16,14 +16,12 @@ class TagsController < ApplicationController @tag = @tag ? @tag.name : tag_name @page = Page.new - params[:page] = ( params[:page].is_a?(Fixnum) ? params[:page] : 1 ) + params[:page] = (params[:page].is_a?(Integer) ? params[:page] : 1) - @pages = Page.heads.paginate( - Page.find_options_for_find_tagged_with(@tag).merge( - :order => 'published_at DESC', - :page=>params[:page], - :per_page => 23 - ) + @pages = Page.heads.tagged_with(@tag).paginate( + :order => 'published_at DESC', + :page => params[:page], + :per_page => 23 ) respond_to do |format| diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 87df678..b7914c4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -9,7 +9,7 @@ class UsersController < ApplicationController layout 'admin' def index - @users = User.all(:order => "login ASC").group_by do |user| + @users = User.order("login ASC").all.group_by do |user| user.admin? ? :admin : :user end end -- cgit v1.3