Skip to content

Commit

Permalink
Merge pull request #1449 from mamhoff/fix-tidy-task
Browse files Browse the repository at this point in the history
Fix tidy task
  • Loading branch information
tvdeyen authored May 18, 2018
2 parents 3cb526d + 97cea0d commit 9ba107b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/alchemy/tasks/tidy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,20 @@ def remove_orphaned_contents
end
end

def remove_duplicate_folded_pages
Alchemy::FoldedPage.select(:page_id, :user_id).group(:page_id, :user_id).having("count(*) > 1").each do |duplicate_page|
duplicate_page_ids = Alchemy::FoldedPage.where(duplicate_page.attributes.except("id")).pluck(:id)
duplicate_page_ids_except_oldest = duplicate_page_ids.reject { |i| i == duplicate_page_ids.min }
Alchemy::FoldedPage.where(id: duplicate_page_ids_except_oldest).delete_all
end
end

private

def destroy_orphaned_records(records, class_name)
records.each do |record|
log "Destroy orphaned #{class_name}: #{record.inspect}"
record.destroy
record.reload.try(:destroy)
end
end
end
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_duplicate_folded_pages'].invoke
end

desc "Creates missing cells for pages."
Expand Down Expand Up @@ -56,5 +57,10 @@ namespace :alchemy do
task remove_orphaned_contents: [:environment] do
Alchemy::Tidy.remove_orphaned_contents
end

desc "Remove duplicate folded pages."
task remove_duplicate_folded_pages: [:environment] do
Alchemy::Tidy.remove_duplicate_folded_pages
end
end
end

0 comments on commit 9ba107b

Please sign in to comment.