Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove active_record_5_1? method #1854

Merged
merged 1 commit into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions app/models/alchemy/base_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@ def self.table_name_prefix

class BaseRecord < ActiveRecord::Base
self.abstract_class = true

def active_record_5_1?
ActiveRecord.gem_version >= Gem::Version.new("5.1.0")
end
end
end
12 changes: 2 additions & 10 deletions app/models/alchemy/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,15 @@ def remove_old_default
end

def should_set_pages_language?
if active_record_5_1?
saved_change_to_language_code? || saved_change_to_country_code?
else
language_code_changed? || country_code_changed?
end
saved_change_to_language_code? || saved_change_to_country_code?
end

def set_pages_language
pages.update_all language_code: code
end

def should_unpublish_pages?
if active_record_5_1?
saved_changes[:public] == [true, false]
else
changes[:public] == [true, false]
end
saved_changes[:public] == [true, false]
end

def unpublish_pages
Expand Down
17 changes: 2 additions & 15 deletions app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Page < BaseRecord
if: -> { fixed_attributes.any? }

after_update :create_legacy_url,
if: :should_create_legacy_url?
if: :saved_change_to_urlname?

after_update :attach_to_menu!,
if: :should_attach_to_menu?
Expand Down Expand Up @@ -530,22 +530,9 @@ def set_language_code
self.language_code = language.code
end

def should_create_legacy_url?
if active_record_5_1?
saved_change_to_urlname?
else
urlname_changed?
end
end

# Stores the old urlname in a LegacyPageUrl
def create_legacy_url
if active_record_5_1?
former_urlname = urlname_before_last_save
else
former_urlname = urlname_was
end
legacy_urls.find_or_create_by(urlname: former_urlname)
legacy_urls.find_or_create_by(urlname: urlname_before_last_save)
end

def set_published_at
Expand Down
12 changes: 2 additions & 10 deletions app/models/alchemy/page/page_elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ module Page::PageElements
unless: -> { autogenerate_elements == false }

after_update :trash_not_allowed_elements!,
if: :has_page_layout_changed?
if: :saved_change_to_page_layout?

after_update :generate_elements,
if: :has_page_layout_changed?
if: :saved_change_to_page_layout?
end

module ClassMethods
Expand Down Expand Up @@ -211,14 +211,6 @@ def trash_not_allowed_elements!
not_allowed_elements.to_a.map(&:trash!)
end

def has_page_layout_changed?
if active_record_5_1?
saved_change_to_page_layout?
else
page_layout_changed?
end
end

# Deletes unique and already present definitions from @_element_definitions.
#
def delete_unique_element_definitions!
Expand Down
6 changes: 1 addition & 5 deletions app/models/alchemy/page/page_naming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ def visible_ancestors
def should_update_descendants_urlnames?
return false if !Config.get(:url_nesting)

if active_record_5_1?
saved_change_to_urlname? || saved_change_to_visible?
else
urlname_changed? || visible_changed?
end
saved_change_to_urlname? || saved_change_to_visible?
end

def update_descendants_urlnames
Expand Down