diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-06-24 04:13:16 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-06-24 04:13:16 +0200 |
| commit | e0a7e0fec760ba12c8067a37e10c96f1f05876e2 (patch) | |
| tree | d0cf745592a46aee4d4913911fd34c7c24515220 /app/models | |
| parent | 6424e10be5a89f175a74c71c55660412a169b8b8 (diff) | |
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
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/asset.rb | 29 | ||||
| -rw-r--r-- | app/models/event.rb | 12 | ||||
| -rw-r--r-- | app/models/menu_item.rb | 8 | ||||
| -rw-r--r-- | app/models/node.rb | 17 | ||||
| -rw-r--r-- | app/models/occurrence.rb | 24 | ||||
| -rw-r--r-- | app/models/page.rb | 35 | ||||
| -rw-r--r-- | app/models/permission.rb | 4 |
7 files changed, 44 insertions, 85 deletions
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 | |||
| 11 | :headline => "460x250#" | 11 | :headline => "460x250#" |
| 12 | } | 12 | } |
| 13 | ) | 13 | ) |
| 14 | 14 | ||
| 15 | named_scope :images, :conditions => { | 15 | scope :images, where(:upload_content_type => ["image/gif", "image/jpeg", "image/png"]) |
| 16 | :upload_content_type => [ | 16 | scope :documents, where(:upload_content_type => ["application/pdf", "text/plain", "text/rtf"]) |
| 17 | "image/gif", | 17 | scope :audio, where(:upload_content_type => ["audio/mpeg", "audio/x-m4a", "audio/wav", "audio/x-wav"]) |
| 18 | "image/jpeg", | ||
| 19 | "image/png" | ||
| 20 | ] | ||
| 21 | } | ||
| 22 | |||
| 23 | named_scope :documents, :conditions => { | ||
| 24 | :upload_content_type => [ | ||
| 25 | "application/pdf", | ||
| 26 | "text/plain", | ||
| 27 | "text/rtf" | ||
| 28 | ] | ||
| 29 | } | ||
| 30 | |||
| 31 | named_scope :audio, :conditions => { | ||
| 32 | :upload_content_type => [ | ||
| 33 | "audio/mpeg", | ||
| 34 | "audio/x-m4a", | ||
| 35 | "audio/wav", | ||
| 36 | "audio/x-wav" | ||
| 37 | ] | ||
| 38 | } | ||
| 39 | end | 18 | 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 | |||
| 12 | # Instance Methods | 12 | # Instance Methods |
| 13 | 13 | ||
| 14 | def occurrences_in_range start_time, end_time | 14 | def occurrences_in_range start_time, end_time |
| 15 | self.occurrences.find( | 15 | self.occurrences.where( |
| 16 | :all, :conditions => [ | 16 | "start_time > ? AND end_time < ?", |
| 17 | "start_time > ? AND end_time < ?", | 17 | start_time, end_time |
| 18 | start_time, end_time | ||
| 19 | ] | ||
| 20 | ) | 18 | ) |
| 21 | end | 19 | end |
| 22 | 20 | ||
| 23 | private | 21 | private |
| 24 | def generate_occurences | 22 | def generate_occurences |
| 25 | Occurrence.generate self | 23 | 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 @@ | |||
| 1 | class MenuItem < ActiveRecord::Base | 1 | class MenuItem < ActiveRecord::Base |
| 2 | 2 | ||
| 3 | default_scope :conditions => {:type => "MenuItem"} | 3 | default_scope where(:type => "MenuItem") |
| 4 | 4 | ||
| 5 | translates :title | 5 | translates :title |
| 6 | 6 | ||
| @@ -24,5 +24,5 @@ end | |||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | class FeaturedArticle < MenuItem | 26 | class FeaturedArticle < MenuItem |
| 27 | default_scope :conditions => {:type => "FeaturedArticle"} | 27 | default_scope where(:type => "FeaturedArticle") |
| 28 | end \ No newline at end of file | 28 | 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 | |||
| 24 | validate :borders # This should never ever happen. | 24 | validate :borders # This should never ever happen. |
| 25 | 25 | ||
| 26 | # Index for Fulltext Search | 26 | # Index for Fulltext Search |
| 27 | define_index do | 27 | # define_index do |
| 28 | indexes head.translations.title | 28 | # indexes head.translations.title |
| 29 | indexes slug | 29 | # indexes slug |
| 30 | indexes unique_name | 30 | # indexes unique_name |
| 31 | indexes head.translations.body | 31 | # indexes head.translations.body |
| 32 | end | 32 | # end |
| 33 | 33 | ||
| 34 | # Class methods | 34 | # Class methods |
| 35 | 35 | ||
| @@ -39,8 +39,8 @@ class Node < ActiveRecord::Base | |||
| 39 | # revision with -1. It raises an Argument error if the revision is not a | 39 | # revision with -1. It raises an Argument error if the revision is not a |
| 40 | # Fixnum | 40 | # Fixnum |
| 41 | def self.find_page path, revision = -1 | 41 | def self.find_page path, revision = -1 |
| 42 | unless revision.class == Fixnum | 42 | unless revision.is_a?(Integer) |
| 43 | raise ArgumentError, "revision must be a Fixnum" | 43 | raise ArgumentError, "revision must be a Integer" |
| 44 | end | 44 | end |
| 45 | 45 | ||
| 46 | node = Node.find_by_unique_name(path) | 46 | node = Node.find_by_unique_name(path) |
| @@ -111,6 +111,7 @@ class Node < ActiveRecord::Base | |||
| 111 | end | 111 | end |
| 112 | 112 | ||
| 113 | self.save! | 113 | self.save! |
| 114 | self.update_unique_name | ||
| 114 | self.unlock! | 115 | self.unlock! |
| 115 | self | 116 | self |
| 116 | end | 117 | 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 | |||
| 11 | # Class Methods | 11 | # Class Methods |
| 12 | 12 | ||
| 13 | def self.find_in_range start_time, end_time | 13 | def self.find_in_range start_time, end_time |
| 14 | find( | 14 | includes(:node) |
| 15 | :all, | 15 | .where("start_time > ? AND end_time < ?", start_time, end_time) |
| 16 | :include => :node, | 16 | .order("start_time") |
| 17 | :conditions => [ | ||
| 18 | "start_time > ? AND end_time < ?", start_time, end_time | ||
| 19 | ], | ||
| 20 | :order => "start_time" | ||
| 21 | ) | ||
| 22 | end | 17 | end |
| 23 | 18 | ||
| 24 | def self.find_next | 19 | def self.find_next |
| 25 | find( | 20 | includes(:node) |
| 26 | :all, | 21 | .where("start_time > ?", Time.now) |
| 27 | :limit => 1, | 22 | .limit(1) |
| 28 | :include => :node, | ||
| 29 | :conditions => ["start_time > ?", Time.now] | ||
| 30 | ) | ||
| 31 | end | 23 | end |
| 32 | 24 | ||
| 33 | # Deletes all Occurrences which belong to the given event. Afterwards a few | 25 | # Deletes all Occurrences which belong to the given event. Afterwards a few |
| 34 | # variables are set to save repetitive queries. The occurrences of the given | 26 | # variables are set to save repetitive queries. The occurrences of the given |
| 35 | # event are then calculated and created. | 27 | # 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' | |||
| 3 | class Page < ActiveRecord::Base | 3 | class Page < ActiveRecord::Base |
| 4 | 4 | ||
| 5 | PUBLIC_TEMPLATE_PATH = File.join(%w(custom page_templates public)) | 5 | PUBLIC_TEMPLATE_PATH = File.join(%w(custom page_templates public)) |
| 6 | FULL_PUBLIC_TEMPLATE_PATH = File.join(RAILS_ROOT, 'app', 'views', PUBLIC_TEMPLATE_PATH) | 6 | FULL_PUBLIC_TEMPLATE_PATH = Rails.root.join('app', 'views', PUBLIC_TEMPLATE_PATH) |
| 7 | 7 | ||
| 8 | # named scopes | 8 | # named scopes |
| 9 | 9 | scope :drafts, joins(:node).includes(:translations).where("nodes.draft_id = pages.id") | |
| 10 | named_scope( | 10 | scope :heads, joins(:node).includes(:translations).where("nodes.head_id = pages.id") |
| 11 | :drafts, | ||
| 12 | :joins => :node, | ||
| 13 | :include => [:translations], | ||
| 14 | :conditions => ["nodes.draft_id = pages.id"] | ||
| 15 | ) | ||
| 16 | |||
| 17 | named_scope( | ||
| 18 | :heads, | ||
| 19 | :joins => :node, | ||
| 20 | :include => [:translations], | ||
| 21 | :conditions => ["nodes.head_id = pages.id"] | ||
| 22 | ) | ||
| 23 | 11 | ||
| 24 | # Mixins and Plugins | 12 | # Mixins and Plugins |
| 25 | acts_as_taggable | 13 | acts_as_taggable |
| @@ -62,15 +50,16 @@ class Page < ActiveRecord::Base | |||
| 62 | 50 | ||
| 63 | options = defaults.merge options | 51 | options = defaults.merge options |
| 64 | 52 | ||
| 65 | Page.heads.paginate( | 53 | scope = Page.heads |
| 66 | find_options_for_find_tagged_with( | 54 | unless options[:tags].blank? |
| 67 | options[:tags].gsub(/\s/, ","), :match_all => true, :conditions => options[:conditions] | 55 | scope = scope.tagged_with( |
| 68 | ).merge( | 56 | options[:tags].gsub(/\s/, ",").split(",").map(&:strip), |
| 69 | :page => page, | 57 | :match_all => true |
| 70 | :per_page => options[:limit], | ||
| 71 | :order => "#{options[:order_by]} #{options[:order_direction]}" | ||
| 72 | ) | 58 | ) |
| 73 | ) | 59 | end |
| 60 | |||
| 61 | scope.order("#{options[:order_by]} #{options[:order_direction]}") | ||
| 62 | .paginate(:page => page, :per_page => options[:limit]) | ||
| 74 | end | 63 | end |
| 75 | 64 | ||
| 76 | def self.custom_templates | 65 | 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 | |||
| 8 | belongs_to :node | 8 | belongs_to :node |
| 9 | 9 | ||
| 10 | # Named scopes | 10 | # Named scopes |
| 11 | named_scope :for_node, lambda { |node| { :conditions => ['node_id = ?', (node.is_a? Node ? node.id : node)] } } | 11 | scope :for_node, lambda { |node| where('node_id = ?', (node.is_a?(Node) ? node.id : node)) } |
| 12 | named_scope :for_user, lambda { |user| { :conditions => ['user_id = ?', (user.is_a? User ? user.id : user)] } } | 12 | scope :for_user, lambda { |user| where('user_id = ?', (user.is_a?(User) ? user.id : user)) } |
| 13 | end | 13 | end |
