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

Tidy Rake task to remove duplicate legacy URLs #2036

Merged
merged 1 commit into from
Feb 22, 2021
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
12 changes: 12 additions & 0 deletions lib/alchemy/tasks/tidy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ def remove_orphaned_contents
end
end

def remove_duplicate_legacy_urls
puts "\n## Removing duplicate legacy URLs"
sql = <<~SQL
DELETE FROM alchemy_legacy_page_urls A USING alchemy_legacy_page_urls B
WHERE A.page_id = B.page_id
AND A.urlname = B.urlname
AND A.id < B.id
SQL
count = ActiveRecord::Base.connection.exec_delete(sql)
tvdeyen marked this conversation as resolved.
Show resolved Hide resolved
log "Deleted #{count} duplicate legacy URLs"
end

private

def destroy_orphaned_records(records, class_name)
Expand Down
6 changes: 6 additions & 0 deletions lib/tasks/alchemy/tidy.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace :alchemy do
Rake::Task["alchemy:tidy:content_positions"].invoke
Rake::Task["alchemy:tidy:remove_orphaned_records"].invoke
Rake::Task["alchemy:tidy:remove_trashed_elements"].invoke
Rake::Task["alchemy:tidy:remove_duplicate_legacy_urls"].invoke
end

desc "Fixes element positions."
Expand Down Expand Up @@ -42,6 +43,11 @@ namespace :alchemy do
Alchemy::Tidy.remove_trashed_elements
end

desc "Remove duplicate legacy URLs"
task remove_duplicate_legacy_urls: [:environment] do
Alchemy::Tidy.remove_duplicate_legacy_urls
end

desc "List Alchemy elements usage"
task elements_usage: :environment do
puts "\n"
Expand Down