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 --- .../initializers/activesupport_duration_patch.rb | 53 ++++++++++++++++++++++ config/initializers/arel_patch.rb | 12 +++++ config/initializers/exception_notifier.rb | 6 +++ config/initializers/postgresql_adapter_patch.rb | 30 ++++++++++++ config/initializers/ruby2.rb | 16 +++++++ config/initializers/session_store.rb | 16 +------ 6 files changed, 118 insertions(+), 15 deletions(-) create mode 100644 config/initializers/activesupport_duration_patch.rb create mode 100644 config/initializers/arel_patch.rb create mode 100644 config/initializers/exception_notifier.rb create mode 100644 config/initializers/postgresql_adapter_patch.rb create mode 100644 config/initializers/ruby2.rb (limited to 'config/initializers') diff --git a/config/initializers/activesupport_duration_patch.rb b/config/initializers/activesupport_duration_patch.rb new file mode 100644 index 0000000..c2b431d --- /dev/null +++ b/config/initializers/activesupport_duration_patch.rb @@ -0,0 +1,53 @@ +class Integer + def days + ActiveSupport::Duration.new(self * 86400, [[:days, self]]) + end + alias :day :days + + def weeks + ActiveSupport::Duration.new(self * 7 * 86400, [[:days, self * 7]]) + end + alias :week :weeks + + def hours + ActiveSupport::Duration.new(self * 3600, [[:seconds, self * 3600]]) + end + alias :hour :hours + + def minutes + ActiveSupport::Duration.new(self * 60, [[:seconds, self * 60]]) + end + alias :minute :minutes + + def seconds + ActiveSupport::Duration.new(self, [[:seconds, self]]) + end + alias :second :seconds + + def months + ActiveSupport::Duration.new(self * 30 * 86400, [[:months, self]]) + end + alias :month :months + + def years + ActiveSupport::Duration.new((self * 365.25 * 86400).to_i, [[:years, self]]) + end + alias :year :years +end + +class Float + def days + ActiveSupport::Duration.new((self * 86400).to_i, [[:days, self]]) + end + alias :day :days + + def hours + ActiveSupport::Duration.new((self * 3600).to_i, [[:seconds, (self * 3600).to_i]]) + end + alias :hour :hours + + def minutes + ActiveSupport::Duration.new((self * 60).to_i, [[:seconds, (self * 60).to_i]]) + end + alias :minute :minutes +end diff --git a/config/initializers/arel_patch.rb b/config/initializers/arel_patch.rb new file mode 100644 index 0000000..753a72b --- /dev/null +++ b/config/initializers/arel_patch.rb @@ -0,0 +1,12 @@ +require 'arel' +module Arel + module Visitors + [ToSql, DepthFirst].each do |visitor| + visitor.class_eval do + def visit_Integer(o, collector = nil) + collector ? collector << o.to_s : o.to_s + end + end + end + end +end diff --git a/config/initializers/exception_notifier.rb b/config/initializers/exception_notifier.rb new file mode 100644 index 0000000..bc7c385 --- /dev/null +++ b/config/initializers/exception_notifier.rb @@ -0,0 +1,6 @@ +Cccms::Application.config.middleware.use ExceptionNotification::Rack, + :email => { + :email_prefix => "[CCCMS] ", + :sender_address => %("CCCMS Error" ), + :exception_recipients => %w(erdgeist@ccc.de) + } diff --git a/config/initializers/postgresql_adapter_patch.rb b/config/initializers/postgresql_adapter_patch.rb new file mode 100644 index 0000000..57df6a2 --- /dev/null +++ b/config/initializers/postgresql_adapter_patch.rb @@ -0,0 +1,30 @@ +require 'active_record/connection_adapters/postgresql_adapter' + +module ActiveRecord + module ConnectionAdapters + class PostgreSQLAdapter + def create_database(name, options = {}) + options = options.reverse_merge(:encoding => "utf8") + + option_string = options.symbolize_keys.inject("") do |memo, (key, value)| + memo + case key + when :owner + " OWNER = \"#{value}\"" + when :template + " TEMPLATE = \"#{value}\"" + when :encoding + " ENCODING = '#{value}'" + when :tablespace + " TABLESPACE = \"#{value}\"" + when :connection_limit + " CONNECTION LIMIT = #{value}" + else + "" + end + end + + execute "CREATE DATABASE #{quote_table_name(name)}#{option_string}" + end + end + end +end diff --git a/config/initializers/ruby2.rb b/config/initializers/ruby2.rb new file mode 100644 index 0000000..d2d62aa --- /dev/null +++ b/config/initializers/ruby2.rb @@ -0,0 +1,16 @@ +if Rails::VERSION::MAJOR == 2 && RUBY_VERSION >= '2.0.0' + module ActiveRecord + module Associations + class AssociationProxy + def send(method, *args) + if proxy_respond_to?(method, true) + super + else + load_target + @target.send(method, *args) + end + end + end + end + end +end diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index b3e1098..507dc3c 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,15 +1 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key for verifying cookie session data integrity. -# If you change this key, all old sessions will become invalid! -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -ActionController::Base.session = { - :key => '_cccms_session', - :secret => 'b50f62033369e6039f2ece511f83f10f70301024709e189ab28d42379a26b7bfd0739fb83d89b6b76dba350569e5b9d83ee4abedbd9da468deea963512e4102b' -} - -# Use the database for sessions instead of the cookie-based default, -# which shouldn't be used to store highly confidential information -# (create the session table with "rake db:sessions:create") -# ActionController::Base.session_store = :active_record_store +Cccms::Application.config.session_store :cookie_store, :key => '_cccms_session' -- cgit v1.3