From 26030c71c7b300c30367222f263d74b8d2142ecf Mon Sep 17 00:00:00 2001 From: erdgeist Date: Thu, 25 Jun 2026 17:50:55 +0200 Subject: Rails 5.2 application fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rename before_filter → before_action across all controllers - Fix string conditions in validators to lambda syntax (node.rb) - Fix publish_draft!: move staged slug/parent logic outside draft guard, use move_to_child_of for parent changes, add nil guard for no-op calls - Fix update_unique_names_of_children: use parent_id traversal instead of lft/rgt descendants (awesome_nested_set 3.x lft/rgt update bug) - Fix unique_path to return Array instead of String - Fix Occurrence.delete_all syntax for Rails 5 - Fix Page.find_with_outdated_translations: use includes instead of all - Fix outdated_translations?: use find instead of splat array --- app/controllers/admin_controller.rb | 2 +- app/controllers/application_controller.rb | 2 +- app/controllers/assets_controller.rb | 2 +- app/controllers/content_controller.rb | 2 +- app/controllers/events_controller.rb | 2 +- app/controllers/menu_items_controller.rb | 2 +- app/controllers/nodes_controller.rb | 4 +-- app/controllers/occurrences_controller.rb | 2 +- app/controllers/pages_controller.rb | 2 +- app/controllers/revisions_controller.rb | 2 +- app/controllers/rss_controller.rb | 4 +-- app/controllers/tags_controller.rb | 2 +- app/controllers/users_controller.rb | 6 ++-- app/models/node.rb | 51 ++++++++++++++++++++----------- app/models/occurrence.rb | 2 +- app/models/page.rb | 6 ++-- 16 files changed, 54 insertions(+), 39 deletions(-) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 18c4104..9e8564e 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -2,7 +2,7 @@ class AdminController < ApplicationController # Private - before_filter :login_required + before_action :login_required def index @drafts = Node.where("draft_id IS NOT NULL") diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4d0ed2e..32c7373 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base protect_from_forgery # See ActionController::RequestForgeryProtection for details - before_filter :set_locale + before_action :set_locale protected diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb index cfaf176..a11bbdd 100644 --- a/app/controllers/assets_controller.rb +++ b/app/controllers/assets_controller.rb @@ -2,7 +2,7 @@ class AssetsController < ApplicationController # Private - before_filter :login_required + before_action :login_required layout 'admin' diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 4248239..876bccf 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -2,7 +2,7 @@ class ContentController < ApplicationController # Public - before_filter :find_page + before_action :find_page # This is the method that renders most of the the public content. It recieves # a :locale and a :page_path parameter through the params hash. It looks up diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 805e941..6eba476 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -2,7 +2,7 @@ class EventsController < ApplicationController # Private - before_filter :login_required + before_action :login_required layout 'admin' diff --git a/app/controllers/menu_items_controller.rb b/app/controllers/menu_items_controller.rb index 24a3d5e..4018693 100644 --- a/app/controllers/menu_items_controller.rb +++ b/app/controllers/menu_items_controller.rb @@ -2,7 +2,7 @@ class MenuItemsController < ApplicationController # Private - before_filter :login_required + before_action :login_required layout 'admin' diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index 2b36b78..482d0ac 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb @@ -4,8 +4,8 @@ class NodesController < ApplicationController layout 'admin' - before_filter :login_required - before_filter :find_node, :only => [ + before_action :login_required + before_action :find_node, :only => [ :show, :edit, :update, diff --git a/app/controllers/occurrences_controller.rb b/app/controllers/occurrences_controller.rb index 751be40..61b42ff 100644 --- a/app/controllers/occurrences_controller.rb +++ b/app/controllers/occurrences_controller.rb @@ -2,7 +2,7 @@ class OccurrencesController < ApplicationController # Private - before_filter :login_required + before_action :login_required # GET /occurrences # GET /occurrences.xml diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index a684327..f5609eb 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -2,7 +2,7 @@ class PagesController < ApplicationController # Private - before_filter :login_required + before_action :login_required def preview @page = Page.find(params[:id]) diff --git a/app/controllers/revisions_controller.rb b/app/controllers/revisions_controller.rb index 8c16730..42d667e 100644 --- a/app/controllers/revisions_controller.rb +++ b/app/controllers/revisions_controller.rb @@ -2,7 +2,7 @@ class RevisionsController < ApplicationController # Private - before_filter :login_required + before_action :login_required layout 'admin' diff --git a/app/controllers/rss_controller.rb b/app/controllers/rss_controller.rb index be9cd2c..4b47218 100644 --- a/app/controllers/rss_controller.rb +++ b/app/controllers/rss_controller.rb @@ -1,7 +1,7 @@ class RssController < ApplicationController - before_filter :authenticate, :only => :recent_changes - before_filter :get_host + before_action :authenticate, :only => :recent_changes + before_action :get_host def updates expires_in 31.minutes, :public => true diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index e4ceec9..bf6a029 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -35,7 +35,7 @@ class TagsController < ApplicationController end else respond_to do |format| - format.html { render :nothing => true, :status => 400 } + format.html { head :bad_request } end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1d85690..72e6058 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,9 +2,9 @@ class UsersController < ApplicationController # Private - before_filter :login_required - before_filter :find_user, :only => [:show, :edit, :update, :destroy] - before_filter :verify_status, :except => [:index, :show] + before_action :login_required + before_action :find_user, :only => [:show, :edit, :update, :destroy] + before_action :verify_status, :except => [:index, :show] layout 'admin' diff --git a/app/models/node.rb b/app/models/node.rb index 8be6daf..d760f0a 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -16,10 +16,10 @@ class Node < ActiveRecord::Base after_save :update_unique_names_of_children # Validations - validates_length_of :slug, :within => 1..255, :unless => "parent_id.nil?" - validates_presence_of :slug, :unless => "parent_id.nil?" - validates_uniqueness_of :slug, :scope => :parent_id, :unless => "parent_id.nil?" - validates_presence_of :parent_id, :unless => "Node.root.nil?" + validates_length_of :slug, :within => 1..255, :unless => -> { parent_id.nil? } + validates_presence_of :slug, :unless => -> { parent_id.nil? } + validates_uniqueness_of :slug, :scope => :parent_id, :unless => -> { parent_id.nil? } + validates_presence_of :parent_id, :unless => -> { Node.root.nil? } validate :borders # This should never ever happen. @@ -95,26 +95,37 @@ class Node < ActiveRecord::Base end def publish_draft! + # Return nil if nothing to publish and no staged changes + return nil unless self.draft || staged_slug || staged_parent_id + if self.draft self.head = self.draft self.head.published_at ||= Time.now self.head.save! - self.draft = nil + end - if staged_slug && (staged_slug != slug) - self.slug = staged_slug - end - - if staged_parent_id && (staged_parent_id != parent_id) - self.parent_id = staged_parent_id - end + if staged_slug && (staged_slug != slug) + self.slug = staged_slug + self.staged_slug = nil + end + if staged_parent_id && (staged_parent_id != parent_id) + new_parent = Node.find(staged_parent_id) + self.staged_parent_id = nil self.save! - self.update_unique_name - self.unlock! - self + self.move_to_child_of(new_parent) + else + unless self.save + raise ActiveRecord::RecordInvalid.new(self) + end end + + self.reload + self.update_unique_name + self.send(:update_unique_names_of_children) + self.unlock! + self end # removes a draft and the lock if it is older than a day and still @@ -146,7 +157,7 @@ class Node < ActiveRecord::Base # returns an array with all parts of a unique_name rather than a string def unique_path - unique_name.to_s + unique_name.to_s.split("/") end # returns array with pages up to root excluding root @@ -228,8 +239,12 @@ class Node < ActiveRecord::Base # Hopefully until no childrens occur def update_unique_names_of_children unless root? - self.descendants.each do |descendant| - descendant.update_unique_name + # Use parent_id-based traversal instead of lft/rgt descendants + # due to awesome_nested_set not refreshing parent lft/rgt in memory + Node.where(:parent_id => self.id).each do |child| + child.reload + child.update_unique_name + child.send(:update_unique_names_of_children) end end end diff --git a/app/models/occurrence.rb b/app/models/occurrence.rb index 0760d5e..8457ffd 100644 --- a/app/models/occurrence.rb +++ b/app/models/occurrence.rb @@ -26,7 +26,7 @@ class Occurrence < ActiveRecord::Base # variables are set to save repetitive queries. The occurrences of the given # event are then calculated and created. def self.generate event - self.delete_all(:event_id => event.id) + self.where(:event_id => event.id).delete_all node = event.node duration = (event.end_time - event.start_time) diff --git a/app/models/page.rb b/app/models/page.rb index e2cbee5..93debf8 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -83,7 +83,7 @@ class Page < ActiveRecord::Base # outdated_translations? for more information. # Takes :locale => and :delta_time => 12.hours as options def self.find_with_outdated_translations options = {} - Page.all(:include => :translations).select do |page| + Page.includes(:translations).select do |page| page.outdated_translations? options end end @@ -182,8 +182,8 @@ class Page < ActiveRecord::Base translations = self.translations - default = *(translations.select {|x| x.locale == I18n.default_locale}) - custom = *(translations.select {|x| x.locale == options[:locale]}) + default = translations.find {|x| x.locale.to_s == I18n.default_locale.to_s } + custom = translations.find {|x| x.locale.to_s == options[:locale].to_s } if translations.size > 1 && default && custom difference = (default.updated_at - custom.updated_at).to_i.abs -- cgit v1.3