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/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 ++-- 7 files changed, 44 insertions(+), 85 deletions(-) (limited to 'app/models') 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 -- cgit v1.3