Skip to content

Commit

Permalink
Handle accidental subject deletion and error handling for #4269
Browse files Browse the repository at this point in the history
  • Loading branch information
benwbrum committed Oct 24, 2024
1 parent 8408e08 commit 5d7e5b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 9 additions & 1 deletion app/controllers/transcribe_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,16 @@ def record_translation_deed
private

def rollback_article_categories(destroy_ids, unset_ids)
Article.where(id: destroy_ids, provenance: nil).destroy_all if destroy_ids
Article.where(id: unset_ids).update(categories: []) if unset_ids

if destroy_ids
candidate_articles = Article.where(id: destroy_ids, provenance: nil)
candidate_articles.each do |candidate|
if candidate.pages.count == 1 # don't delete uncategorized subjects that appear elsewhere
candidate.destroy!
end
end
end
end

def page_params
Expand Down
11 changes: 9 additions & 2 deletions lib/tasks/remediator.rake
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,18 @@ namespace :fromthepage do
pages = pages.uniq
# for each page, resave the page so we get updated page source and page article links
pages.each do |page|
print "\nResaving page #{page.title}\n"
print "\nResaving page #{page.id}\t#{page.title}\n"
# print the page_article_link count before and after
print "Before: #{page.page_article_links.count} links\n"
page.source_text+=' '
page.save!
begin
page.save!
# catch any exceptions and print them
rescue => e
print "\nERROR SAVING PAGE #{page.id}!!!\n\n"
print e.message
print "\nERROR SAVING PAGE #{page.id}!!!\n\n"
end
print "After: #{page.page_article_links.count} links\n"
end
end
Expand Down

0 comments on commit 5d7e5b7

Please sign in to comment.