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 +- app/helpers/application_helper.rb | 11 +++++ app/helpers/content_helper.rb | 10 ++-- app/models/asset.rb | 29 ++---------- app/models/event.rb | 12 ++--- app/models/menu_item.rb | 8 ++-- app/models/node.rb | 17 +++---- app/models/occurrence.rb | 24 ++++------ app/models/page.rb | 35 +++++--------- app/models/permission.rb | 4 +- app/views/assets/edit.html.erb | 6 +-- app/views/assets/new.html.erb | 6 +-- app/views/content/_search.html.erb | 2 +- app/views/content/_tags.html.erb | 2 +- .../public/no_date_and_author_with_map.html.erb | 8 ++++ app/views/events/edit.html.erb | 6 +-- app/views/events/new.html.erb | 6 +-- app/views/layouts/admin.html.erb | 2 +- app/views/layouts/application.html.erb | 2 +- app/views/layouts/application.html.erb.bak | 54 ++++++++++++++++++++++ app/views/menu_items/edit.html.erb | 4 +- app/views/menu_items/new.html.erb | 4 +- app/views/nodes/edit.html.erb | 10 ++-- app/views/nodes/index.html.erb | 2 +- app/views/nodes/new.html.erb | 9 ++-- app/views/occurrences/edit.html.erb | 6 +-- app/views/occurrences/new.html.erb | 6 +-- app/views/pages/edit.html.erb | 4 +- app/views/pages/new.html.erb | 4 +- app/views/revisions/diff.html.erb | 4 +- app/views/revisions/index.html.erb | 6 +-- app/views/sessions/new.html.erb | 4 +- app/views/users/edit.html.erb | 11 +++-- app/views/users/new.html.erb | 11 +++-- 42 files changed, 228 insertions(+), 208 deletions(-) create mode 100644 app/views/custom/page_templates/public/no_date_and_author_with_map.html.erb create mode 100644 app/views/layouts/application.html.erb.bak (limited to 'app') 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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 22a7940..0be66e9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,3 +1,14 @@ # Methods added to this helper will be available to all templates in the application. module ApplicationHelper + def form_error_messages(form_object) + object = form_object.is_a?(ActionView::Helpers::FormBuilder) ? form_object.object : form_object + return "" unless object && object.errors.any? + content_tag(:div, :class => "error_messages") do + content_tag(:ul) do + object.errors.full_messages.map do |msg| + content_tag(:li, msg) + end.join.html_safe + end + end + end end diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 17364f8..dbe468e 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb @@ -1,7 +1,7 @@ module ContentHelper def main_menu - menu_items = MenuItem.all(:order => "position ASC") + menu_items = MenuItem.order("position ASC").all render( :partial => 'content/main_navigation', :locals => {:menu_items => menu_items} @@ -51,7 +51,7 @@ module ContentHelper end def page_title - if @page.title && @page.title != "" + if @page && @page.title && @page.title != "" "CCC | #{@page.title}" else "CCC | Chaos Computer Club" @@ -75,7 +75,7 @@ module ContentHelper def aggregate? content options = {} - cccms_attributes = ActionView::Base.sanitized_allowed_attributes + [ 'lang' ] + cccms_attributes = ActionView::Base.sanitized_allowed_attributes + ['lang'] begin if content =~ /]*)>/ @@ -126,9 +126,7 @@ module ContentHelper # Check if a custom partial exists in the proper location def partial_exists? partial File.exist?( - File.join( - RAILS_ROOT, 'app', 'views', 'custom', 'partials', "_#{partial}.html.erb" - ) + Rails.root.join('app', 'views', 'custom', 'partials', "_#{partial}.html.erb") ) end diff --git a/app/models/asset.rb b/app/models/asset.rb index 5bfea76..d27c525 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -11,29 +11,8 @@ class Asset < ActiveRecord::Base :headline => "460x250#" } ) - - named_scope :images, :conditions => { - :upload_content_type => [ - "image/gif", - "image/jpeg", - "image/png" - ] - } - - named_scope :documents, :conditions => { - :upload_content_type => [ - "application/pdf", - "text/plain", - "text/rtf" - ] - } - - named_scope :audio, :conditions => { - :upload_content_type => [ - "audio/mpeg", - "audio/x-m4a", - "audio/wav", - "audio/x-wav" - ] - } + + scope :images, where(:upload_content_type => ["image/gif", "image/jpeg", "image/png"]) + scope :documents, where(:upload_content_type => ["application/pdf", "text/plain", "text/rtf"]) + scope :audio, where(:upload_content_type => ["audio/mpeg", "audio/x-m4a", "audio/wav", "audio/x-wav"]) end diff --git a/app/models/event.rb b/app/models/event.rb index 60b8521..23deed6 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -12,14 +12,12 @@ class Event < ActiveRecord::Base # Instance Methods def occurrences_in_range start_time, end_time - self.occurrences.find( - :all, :conditions => [ - "start_time > ? AND end_time < ?", - start_time, end_time - ] + self.occurrences.where( + "start_time > ? AND end_time < ?", + start_time, end_time ) - end - + end + private def generate_occurences Occurrence.generate self diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 054e7ee..d1ddc68 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -1,6 +1,6 @@ class MenuItem < ActiveRecord::Base - - default_scope :conditions => {:type => "MenuItem"} + + default_scope where(:type => "MenuItem") translates :title @@ -24,5 +24,5 @@ end class FeaturedArticle < MenuItem - default_scope :conditions => {:type => "FeaturedArticle"} -end \ No newline at end of file + default_scope where(:type => "FeaturedArticle") +end diff --git a/app/models/node.rb b/app/models/node.rb index 75122d1..1b80565 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -24,12 +24,12 @@ class Node < ActiveRecord::Base validate :borders # This should never ever happen. # Index for Fulltext Search - define_index do - indexes head.translations.title - indexes slug - indexes unique_name - indexes head.translations.body - end + # define_index do + # indexes head.translations.title + # indexes slug + # indexes unique_name + # indexes head.translations.body + # end # Class methods @@ -39,8 +39,8 @@ class Node < ActiveRecord::Base # revision with -1. It raises an Argument error if the revision is not a # Fixnum def self.find_page path, revision = -1 - unless revision.class == Fixnum - raise ArgumentError, "revision must be a Fixnum" + unless revision.is_a?(Integer) + raise ArgumentError, "revision must be a Integer" end node = Node.find_by_unique_name(path) @@ -111,6 +111,7 @@ class Node < ActiveRecord::Base end self.save! + self.update_unique_name self.unlock! self end diff --git a/app/models/occurrence.rb b/app/models/occurrence.rb index 62432d5..0760d5e 100644 --- a/app/models/occurrence.rb +++ b/app/models/occurrence.rb @@ -11,25 +11,17 @@ class Occurrence < ActiveRecord::Base # Class Methods def self.find_in_range start_time, end_time - find( - :all, - :include => :node, - :conditions => [ - "start_time > ? AND end_time < ?", start_time, end_time - ], - :order => "start_time" - ) + includes(:node) + .where("start_time > ? AND end_time < ?", start_time, end_time) + .order("start_time") end - + def self.find_next - find( - :all, - :limit => 1, - :include => :node, - :conditions => ["start_time > ?", Time.now] - ) + includes(:node) + .where("start_time > ?", Time.now) + .limit(1) end - + # Deletes all Occurrences which belong to the given event. Afterwards a few # variables are set to save repetitive queries. The occurrences of the given # event are then calculated and created. diff --git a/app/models/page.rb b/app/models/page.rb index f804353..05abd43 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -3,23 +3,11 @@ require 'xml' class Page < ActiveRecord::Base PUBLIC_TEMPLATE_PATH = File.join(%w(custom page_templates public)) - FULL_PUBLIC_TEMPLATE_PATH = File.join(RAILS_ROOT, 'app', 'views', PUBLIC_TEMPLATE_PATH) + FULL_PUBLIC_TEMPLATE_PATH = Rails.root.join('app', 'views', PUBLIC_TEMPLATE_PATH) # named scopes - - named_scope( - :drafts, - :joins => :node, - :include => [:translations], - :conditions => ["nodes.draft_id = pages.id"] - ) - - named_scope( - :heads, - :joins => :node, - :include => [:translations], - :conditions => ["nodes.head_id = pages.id"] - ) + scope :drafts, joins(:node).includes(:translations).where("nodes.draft_id = pages.id") + scope :heads, joins(:node).includes(:translations).where("nodes.head_id = pages.id") # Mixins and Plugins acts_as_taggable @@ -62,15 +50,16 @@ class Page < ActiveRecord::Base options = defaults.merge options - Page.heads.paginate( - find_options_for_find_tagged_with( - options[:tags].gsub(/\s/, ","), :match_all => true, :conditions => options[:conditions] - ).merge( - :page => page, - :per_page => options[:limit], - :order => "#{options[:order_by]} #{options[:order_direction]}" + scope = Page.heads + unless options[:tags].blank? + scope = scope.tagged_with( + options[:tags].gsub(/\s/, ",").split(",").map(&:strip), + :match_all => true ) - ) + end + + scope.order("#{options[:order_by]} #{options[:order_direction]}") + .paginate(:page => page, :per_page => options[:limit]) end def self.custom_templates diff --git a/app/models/permission.rb b/app/models/permission.rb index 438538e..a7a30ed 100644 --- a/app/models/permission.rb +++ b/app/models/permission.rb @@ -8,6 +8,6 @@ class Permission < ActiveRecord::Base belongs_to :node # Named scopes - named_scope :for_node, lambda { |node| { :conditions => ['node_id = ?', (node.is_a? Node ? node.id : node)] } } - named_scope :for_user, lambda { |user| { :conditions => ['user_id = ?', (user.is_a? User ? user.id : user)] } } + scope :for_node, lambda { |node| where('node_id = ?', (node.is_a?(Node) ? node.id : node)) } + scope :for_user, lambda { |user| where('user_id = ?', (user.is_a?(User) ? user.id : user)) } end diff --git a/app/views/assets/edit.html.erb b/app/views/assets/edit.html.erb index d60db94..e65d600 100644 --- a/app/views/assets/edit.html.erb +++ b/app/views/assets/edit.html.erb @@ -1,7 +1,7 @@

Editing asset

-<% form_for(@asset) do |f| %> - <%= f.error_messages %> +<%= form_for(@asset) do |f| %> + <%= form_error_messages(f) %>

<%= f.submit 'Update' %> @@ -9,4 +9,4 @@ <% end %> <%= link_to 'Show', @asset %> | -<%= link_to 'Back', assets_path %> \ No newline at end of file +<%= link_to 'Back', assets_path %> diff --git a/app/views/assets/new.html.erb b/app/views/assets/new.html.erb index 366488f..6c1310a 100644 --- a/app/views/assets/new.html.erb +++ b/app/views/assets/new.html.erb @@ -1,7 +1,7 @@

New asset

-<% form_for(@asset, :html => { :multipart => true }) do |f| %> - <%= f.error_messages %> +<%= form_for(@asset, :html => { :multipart => true }) do |f| %> + <%= form_error_messages(f) %>

<%= f.label :name %>
@@ -14,4 +14,4 @@

<% end %> -<%= link_to 'Back', assets_path %> \ No newline at end of file +<%= link_to 'Back', assets_path %> diff --git a/app/views/content/_search.html.erb b/app/views/content/_search.html.erb index e654462..aa91424 100644 --- a/app/views/content/_search.html.erb +++ b/app/views/content/_search.html.erb @@ -1,3 +1,3 @@ -<% form_tag search_path, :method => 'get' do %> +<%= form_tag search_path, :method => 'get' do %>
<%= text_field_tag :search_term, params[:search_term], :placeholder => 'suchen', :type => 'search' %>
<% end %> diff --git a/app/views/content/_tags.html.erb b/app/views/content/_tags.html.erb index fd808b6..169ae84 100644 --- a/app/views/content/_tags.html.erb +++ b/app/views/content/_tags.html.erb @@ -1,4 +1,4 @@ -<% unless @page.tags.empty? %> +<% unless @page.nil? || @page.tags.empty? %>

Tags

    diff --git a/app/views/custom/page_templates/public/no_date_and_author_with_map.html.erb b/app/views/custom/page_templates/public/no_date_and_author_with_map.html.erb new file mode 100644 index 0000000..6e86edf --- /dev/null +++ b/app/views/custom/page_templates/public/no_date_and_author_with_map.html.erb @@ -0,0 +1,8 @@ +
    +

    <%= @page.title %>

    +

    <%= sanitize( @page.abstract ) %>

    + + <%= aggregate?(@page.body) %> + + +<%= will_paginate(@content_collection) if @content_collection %> diff --git a/app/views/events/edit.html.erb b/app/views/events/edit.html.erb index 17b6980..824cd66 100644 --- a/app/views/events/edit.html.erb +++ b/app/views/events/edit.html.erb @@ -6,8 +6,8 @@

    Editing event

    -<% form_for(@event) do |f| %> - <%= f.error_messages %> +<%= form_for(@event) do |f| %> + <%= form_error_messages(f) %>

    <%= f.label :start_time %>
    @@ -47,4 +47,4 @@

    <%= f.submit 'Update' %>

    -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/events/new.html.erb b/app/views/events/new.html.erb index 8c9812e..cd892c5 100644 --- a/app/views/events/new.html.erb +++ b/app/views/events/new.html.erb @@ -1,7 +1,7 @@

    New event

    -<% form_for(@event) do |f| %> - <%= f.error_messages %> +<%= form_for(@event) do |f| %> + <%= form_error_messages(f) %>

    <%= f.label :start_time %>
    @@ -43,4 +43,4 @@

    <% end %> -<%= link_to 'Back', events_path %> \ No newline at end of file +<%= link_to 'Back', events_path %> diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 97b81df..9f36021 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -34,7 +34,7 @@ <% end %>
    - <%= yield :layout %> + <%= yield %>
    diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d2a624f..2a46f09 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -28,7 +28,7 @@ - +