Skip to content

Commit

Permalink
Add rake task to remove trashed elements
Browse files Browse the repository at this point in the history
We removed the element trashed with Alchemy 6.0

This task helps to clean up the database with a Rake task.

    bin/rake alchemy:tidy:remove_trashed_elements
  • Loading branch information
tvdeyen committed Feb 16, 2021
1 parent 4e7d035 commit 996b05e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/alchemy/tasks/tidy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ def remove_orphaned_elements
end
end

def remove_trashed_elements
puts "\n## Removing trashed elements"
elements = Alchemy::Element.unscoped.not_nested.where(position: nil)
if elements.any?
log "Destroying #{elements.size} trashed elements\n"
elements.each do |element|
element.destroy
print "."
end
log "\nDone"
else
log "No trashed elements found", :skip
end
end

def remove_orphaned_contents
puts "\n## Removing orphaned contents"
contents = Alchemy::Content.unscoped.all
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 @@ -8,6 +8,7 @@ namespace :alchemy do
Rake::Task["alchemy:tidy:element_positions"].invoke
Rake::Task["alchemy:tidy:content_positions"].invoke
Rake::Task["alchemy:tidy:remove_orphaned_records"].invoke
Rake::Task["alchemy:tidy:remove_trashed_elements"].invoke
end

desc "Fixes element positions."
Expand Down Expand Up @@ -36,6 +37,11 @@ namespace :alchemy do
Alchemy::Tidy.remove_orphaned_contents
end

desc "Remove trashed elements."
task remove_trashed_elements: [:environment] do
Alchemy::Tidy.remove_trashed_elements
end

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

0 comments on commit 996b05e

Please sign in to comment.