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 --- config/application.rb | 60 +++++++++++ config/boot.rb | 113 +-------------------- config/environment.rb | 88 +--------------- config/environments/development.rb | 27 ++--- config/environments/production.rb | 53 +++++----- config/environments/test.rb | 55 +++++----- .../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 +-- config/locales/de.yml | 5 +- config/routes.rb | 91 ++++++++++------- 14 files changed, 314 insertions(+), 311 deletions(-) create mode 100644 config/application.rb 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') diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000..9b7ae67 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,60 @@ +# Put this in config/application.rb +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +Bundler.require(:default, Rails.env) if defined?(Bundler) + +require 'action_controller' + +module ActionController + class Base + def self.consider_all_requests_local=(val) + # no-op: controlled via config.consider_all_requests_local in environment files + end + end +end + +module Cccms + class Application < Rails::Application + config.autoload_paths += [config.root.join('lib')] + config.encoding = 'utf-8' + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Add additional load paths for your own custom dirs + # config.load_paths += %W( #{RAILS_ROOT}/extras ) + + # Only load the plugins named here, in the order given (default is alphabetical). + # :all can be used as a placeholder for all plugins not explicitly named + # config.plugins = [ :exception_notification, :ssl_requirement, :all ] + + # Allowed Tags + # strong em b i p code pre tt samp kbd var sub sup dfn cite big small + # address hr br div span h1 h2 h3 h4 h5 h6 ul ol li dt dd abbr + # acronym a img blockquote del ins + + # Allowed Attributes: + # href src width height alt cite datetime title class name xml:lang abbr)) + + # Add tags to whitelist with: + # config.action_view.sanitized_allowed_tags = 'table', 'tr', 'td' + + # Add attributes to whitelist with: + # config.action_view.sanitized_allowed_attributes = 'id', 'class', 'style' + + # Activate observers that should always be running + # config.active_record.observers = :cacher, :garbage_collector, :forum_observer + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. + config.time_zone = 'Berlin' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] + config.i18n.default_locale = :de + + config.filter_parameters += [:password, :password_confirmation] + end +end diff --git a/config/boot.rb b/config/boot.rb index 9834fc4..b92444f 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,111 +1,2 @@ -# Don't change this file! -# Configure your app in config/environment.rb and config/environments/*.rb - -RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) -ENV['NLS_LANG'] = 'de_DE.UTF8' - -module Rails - class << self - def boot! - unless booted? - preinitialize - pick_boot.run - end - end - - def booted? - defined? Rails::Initializer - end - - def pick_boot - (vendor_rails? ? VendorBoot : GemBoot).new - end - - def vendor_rails? - File.exist?("#{RAILS_ROOT}/vendor/rails") - end - - def preinitialize - load(preinitializer_path) if File.exist?(preinitializer_path) - end - - def preinitializer_path - "#{RAILS_ROOT}/config/preinitializer.rb" - end - end - - class Boot - def run - load_initializer - Rails::Initializer.run(:set_load_path) - end - end - - class VendorBoot < Boot - def load_initializer - require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer" - Rails::Initializer.run(:install_gem_spec_stubs) - Rails::GemDependency.add_frozen_gem_path - end - end - - class GemBoot < Boot - def load_initializer - self.class.load_rubygems - load_rails_gem - require 'initializer' - end - - def load_rails_gem - if version = self.class.gem_version - gem 'rails', version - else - gem 'rails' - end - rescue Gem::LoadError => load_error - $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.) - exit 1 - end - - class << self - def rubygems_version - Gem::RubyGemsVersion rescue nil - end - - def gem_version - if defined? RAILS_GEM_VERSION - RAILS_GEM_VERSION - elsif ENV.include?('RAILS_GEM_VERSION') - ENV['RAILS_GEM_VERSION'] - else - parse_gem_version(read_environment_rb) - end - end - - def load_rubygems - min_version = '1.3.2' - require 'rubygems' - unless rubygems_version >= min_version - $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.) - exit 1 - end - - rescue LoadError - $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org) - exit 1 - end - - def parse_gem_version(text) - $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/ - end - - private - def read_environment_rb - File.read("#{RAILS_ROOT}/config/environment.rb") - end - end - end -end - -# All that for this: -Rails.boot! +require 'rubygems' +require 'bundler/setup' diff --git a/config/environment.rb b/config/environment.rb index 57b9ef2..6fdeb06 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,86 +1,2 @@ -# Be sure to restart your server when you modify this file - -# Specifies gem version of Rails to use when vendor/rails is not present -RAILS_GEM_VERSION = '2.3.15' unless defined? RAILS_GEM_VERSION - -# Bootstrap the Rails environment, frameworks, and default configuration -require File.join(File.dirname(__FILE__), 'boot') - -# monkey patch for 2.0. Will ignore vendor gems. -if RUBY_VERSION >= "2.0.0" - module Gem - def self.source_index - sources - end - - def self.cache - sources - end - - SourceIndex = Specification - - class SourceList - # If you want vendor gems, this is where to start writing code. - def search( *args ); []; end - def each( &block ); end - include Enumerable - end - end -end - -Rails::Initializer.run do |config| - # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. - - # Add additional load paths for your own custom dirs - # config.load_paths += %W( #{RAILS_ROOT}/extras ) - - # Specify gems that this application depends on and have them installed with rake gems:install - # config.gem "bj" - # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" - # config.gem "sqlite3-ruby", :lib => "sqlite3" - # config.gem "aws-s3", :lib => "aws/s3" - - # config.gem "rake", :version => ">= 0.8.3" - # config.gem "rack", :version => ">= 0.9.1" - config.gem "pg" - config.gem "thinking-sphinx", :lib => 'thinking_sphinx', :version => '1.5.0' - config.gem "libxml-ruby", :lib => 'xml' - config.gem "erdgeist-chaos_calendar", :lib => "chaos_calendar", :source => "http://gems.github.com" - - # Only load the plugins named here, in the order given (default is alphabetical). - # :all can be used as a placeholder for all plugins not explicitly named - # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - - # Allowed Tags - # strong em b i p code pre tt samp kbd var sub sup dfn cite big small - # address hr br div span h1 h2 h3 h4 h5 h6 ul ol li dt dd abbr - # acronym a img blockquote del ins - - # Allowed Attributes: - # href src width height alt cite datetime title class name xml:lang abbr)) - - # Add tags to whitelist with: - # config.action_view.sanitized_allowed_tags = 'table', 'tr', 'td' - - # Add attributes to whitelist with: - # config.action_view.sanitized_allowed_attributes = 'id', 'class', 'style' - - # Activate observers that should always be running - # config.active_record.observers = :cacher, :garbage_collector, :forum_observer - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. - config.time_zone = 'Berlin' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] - config.i18n.default_locale = :de - -end - -require 'awesome_patch' - -ExceptionNotifier.exception_recipients = %w(erdgeist@ccc.de) -ExceptionNotifier.sender_address = %("CCCMS Error" ) +require File.expand_path('../application', __FILE__) +Cccms::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 85c9a60..6446686 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,17 +1,20 @@ # Settings specified here will take precedence over those in config/environment.rb -# In the development environment your application's code is reloaded on -# every request. This slows down response time but is perfect for development -# since you don't have to restart the webserver when you make code changes. -config.cache_classes = false +Cccms::Application.configure do + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the webserver when you make code changes. + config.cache_classes = false -# Log error messages when you accidentally call methods on nil. -config.whiny_nils = true + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true -# Show full error reports and disable caching -config.action_controller.consider_all_requests_local = true -config.action_view.debug_rjs = true -config.action_controller.perform_caching = false + # Show full error reports and disable caching + config.action_controller.consider_all_requests_local = true + config.action_controller.perform_caching = false -# Don't care if the mailer can't send -config.action_mailer.raise_delivery_errors = false \ No newline at end of file + # Don't care if the mailer can't send + config.action_mailer.raise_delivery_errors = false + + config.active_support.deprecation = :log +end diff --git a/config/environments/production.rb b/config/environments/production.rb index 1768ab7..2f933de 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,36 +1,39 @@ # Settings specified here will take precedence over those in config/environment.rb -# The production environment is meant for finished, "live" apps. -# Code is not reloaded between requests -config.cache_classes = true +Cccms::Application.configure do + # The production environment is meant for finished, "live" apps. + # Code is not reloaded between requests + config.cache_classes = true -# Full error reports are disabled and caching is turned on -config.action_controller.consider_all_requests_local = false -config.action_controller.perform_caching = true + # Full error reports are disabled and caching is turned on + config.action_controller.consider_all_requests_local = false + config.action_controller.perform_caching = true -# See everything in the log (default is :info) -config.log_level = :info + # See everything in the log (default is :info) + config.log_level = :info -# Use a different logger for distributed setups -# config.logger = SyslogLogger.new + config.active_support.deprecation = :notify -# Use a different cache store in production -# config.cache_store = :mem_cache_store + # Use a different logger for distributed setups + # config.logger = SyslogLogger.new -# Enable serving of images, stylesheets, and javascripts from an asset server -# config.action_controller.asset_host = "http://assets.example.com" + # Use a different cache store in production + # config.cache_store = :mem_cache_store -# Disable delivery errors, bad email addresses will be ignored -# config.action_mailer.raise_delivery_errors = false + # Enable serving of images, stylesheets, and javascripts from an asset server + # config.action_controller.asset_host = "http://assets.example.com" -# Enable threaded mode -# config.threadsafe! + # Disable delivery errors, bad email addresses will be ignored + # config.action_mailer.raise_delivery_errors = false -ActionMailer::Base.delivery_method = :sendmail -ActionMailer::Base.sendmail_settings = { - :location => '/usr/sbin/sendmail', - :arguments => '-i -t' -} -ActionMailer::Base.perform_deliveries = true -ActionMailer::Base.raise_delivery_errors = true + # Enable threaded mode + # config.threadsafe! + ActionMailer::Base.delivery_method = :sendmail + ActionMailer::Base.sendmail_settings = { + :location => '/usr/sbin/sendmail', + :arguments => '-i -t' + } + ActionMailer::Base.perform_deliveries = true + ActionMailer::Base.raise_delivery_errors = true +end diff --git a/config/environments/test.rb b/config/environments/test.rb index 496eb95..728e147 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,27 +1,32 @@ # Settings specified here will take precedence over those in config/environment.rb -# The test environment is used exclusively to run your application's -# test suite. You never need to work with it otherwise. Remember that -# your test database is "scratch space" for the test suite and is wiped -# and recreated between test runs. Don't rely on the data there! -config.cache_classes = true - -# Log error messages when you accidentally call methods on nil. -config.whiny_nils = true - -# Show full error reports and disable caching -config.action_controller.consider_all_requests_local = true -config.action_controller.perform_caching = false - -# Disable request forgery protection in test environment -config.action_controller.allow_forgery_protection = false - -# Tell Action Mailer not to deliver emails to the real world. -# The :test delivery method accumulates sent emails in the -# ActionMailer::Base.deliveries array. -config.action_mailer.delivery_method = :test - -# Use SQL instead of Active Record's schema dumper when creating the test database. -# This is necessary if your schema can't be completely dumped by the schema dumper, -# like if you have constraints or database-specific column types -# config.active_record.schema_format = :sql \ No newline at end of file +Cccms::Application.configure do + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true + + # Show full error reports and disable caching + config.action_controller.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Disable request forgery protection in test environment + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Use SQL instead of Active Record's schema dumper when creating the test database. + # This is necessary if your schema can't be completely dumped by the schema dumper, + # like if you have constraints or database-specific column types + # config.active_record.schema_format = :sql + + config.active_support.deprecation = :raise +end 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' diff --git a/config/locales/de.yml b/config/locales/de.yml index fca8c11..5f77d79 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -18,7 +18,10 @@ de: abbr_day_names: [So, Mo, Di, Mi, Do, Fr, Sa] month_names: [~, Januar, Februar, März, April, Mai, Juni, Juli, August, September, Oktober, November, Dezember] abbr_month_names: [~, Jan, Feb, Mär, Apr, Mai, Jun, Jul, Aug, Sep, Okt, Nov, Dez] - order: [ :day, :month, :year ] + order: + - :day + - :month + - :year time: formats: diff --git a/config/routes.rb b/config/routes.rb index c2590bd..5e3eb3f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,38 +1,57 @@ -ActionController::Routing::Routes.draw do |map| - - map.filter :locale - - map.root( - :locale => 'de', - :controller => 'content', - :action => 'render_page', - :page_path => ['home'] - ) - map.resources :assets - map.resources :tags - map.resources :occurrences - map.resources :events - map.resources :pages, :member => {:preview => :get, :sort_images => :put} - map.resources :nodes, :member => {:publish => :put, :unlock => :put} do |node| - node.resources :revisions, :member => {:restore => :put}, :collection => {:diff => :post} +Cccms::Application.routes.draw do + filter :locale + + root :to => 'content#render_page', :page_path => ['home'], :locale => 'de' + + resources :assets + resources :tags + resources :occurrences + resources :events + + resources :pages do + member do + get :preview + put :sort_images + end + end + + resources :nodes do + member do + put :unlock + put :publish + end + + resources :revisions do + collection do + post :diff + end + member do + put :restore + end + end + end + + match '/logout' => 'sessions#destroy', :as => :logout + match '/login' => 'sessions#new', :as => :login + match 'admin/search' => 'admin#search', :as => :admin_search + match 'search' => 'search#index', :as => :search + + resources :users + + resources :menu_items do + member do + post :sort + end end - map.logout '/logout', :controller => 'sessions', :action => 'destroy' - map.login '/login', :controller => 'sessions', :action => 'new' - map.admin_search 'admin/search', :controller => 'admin', :action => 'search' - map.search 'search', :controller => "search", :action => 'index' - map.resources :users - map.resources :menu_items, :member => {:sort => :post} - map.resource :session - - map.rss 'rss/:action', :controller => 'rss' - map.rss 'rss/:action.:format', :controller => 'rss' - - map.connect ':controller/:action/:id' - map.connect ':controller/:action/:id.:format' - - map.connect 'galleries/*page_path', - :controller => 'content', :action => 'render_gallery' - - map.content '/*page_path', - :controller => 'content', :action => 'render_page' + + resource :session + + match 'rss/:action' => 'rss#index', :as => :rss + match 'rss/:action.:format' => 'rss#index' + + match '/:controller(/:action(/:id))' + match '/:controller(/:action(/:id.:format))' + + match 'galleries/*page_path' => 'content#render_gallery' + match '/*page_path' => 'content#render_page', :as => :content end -- cgit v1.3