-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix delete by prefix rake task. #272
- Loading branch information
Martin Fenner
committed
May 22, 2019
1 parent
61b3fc3
commit 3312f47
Showing
9 changed files
with
101 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class DeleteJob < ActiveJob::Base | ||
queue_as :lupo_background | ||
|
||
def perform(doi_id, options={}) | ||
logger = Logger.new(STDOUT) | ||
doi = Doi.where(doi: doi_id).first | ||
|
||
if doi.present? | ||
doi.destroy | ||
logger.info "Deleted DOI " + doi_id + "." | ||
else | ||
logger.info "Error deleting DOI " + doi_id + ": not found" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
namespace :prefix do | ||
desc 'Delete prefix and associated DOIs' | ||
task :delete => :environment do | ||
# These prefixes are used by multiple clients and can't be deleted | ||
prefixes_to_keep = %w(10.5072 10.4124 10.4225 10.4226 10.4227) | ||
|
||
if ENV['PREFIX'].nil? | ||
puts "ENV['PREFIX'] is required." | ||
exit | ||
end | ||
|
||
if prefixes_to_keep.include?(ENV['PREFIX']) | ||
puts "Prefix #{ENV['PREFIX']} can't be deleted." | ||
exit | ||
end | ||
|
||
prefix = Prefix.where(prefix: ENV['PREFIX']).first | ||
if prefix.nil? | ||
puts "Prefix #{ENV['PREFIX']} not found." | ||
exit | ||
end | ||
|
||
ClientPrefix.where('prefixes = ?', prefix.id).destroy_all | ||
puts "Client prefix deleted." | ||
|
||
ProviderPrefix.where('prefixes = ?', prefix.id).destroy_all | ||
puts "Provider prefix deleted." | ||
|
||
prefix.destroy | ||
puts "Prefix #{ENV['PREFIX']} deleted." | ||
|
||
# delete DOIs | ||
count = Doi.delete_dois_by_prefix(ENV['PREFIX']) | ||
puts "#{count} DOIs with prefix #{ENV['PREFIX']} deleted." | ||
end | ||
end |