From 162b148e8778d2775b83cebfadba5741918f4b37 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Thu, 7 Dec 2023 16:33:53 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Add=20task=20to=20remove=20place?= =?UTF-8?q?holder=20file=20sets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit will add a rake task to remove placeholder file sets from the Dickinson tenant. To test, set an environment variable with whatever cname you want to use and run the task. For example: ```sh REMOVE_PLACEHOLDER_FILE_SETS_FROM="dev.hyku.test" rake hyku:remove_placeholder_file_sets ``` Ref: - https://github.com/scientist-softserv/palni-palci/issues/912 --- ...move_dickinson_placeholder_thumbnails.rake | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/tasks/remove_dickinson_placeholder_thumbnails.rake diff --git a/lib/tasks/remove_dickinson_placeholder_thumbnails.rake b/lib/tasks/remove_dickinson_placeholder_thumbnails.rake new file mode 100644 index 000000000..88f86b5aa --- /dev/null +++ b/lib/tasks/remove_dickinson_placeholder_thumbnails.rake @@ -0,0 +1,28 @@ +namespace :hyku do + desc "Remove Hyku Commons placeholder file sets from tenant" + task remove_placeholder_file_sets: :environment do + # The original ask was for the Dickinson tenant, but passing in an ENV var would be useful for testing + # example: + # ```sh + # REMOVE_PLACEHOLDER_FILE_SETS_FROM="dev.hyku.test" rake hyku:remove_placeholder_file_sets + # ``` + account_cname = ENV['REMOVE_PLACEHOLDER_FILE_SETS_FROM'] || "dickinson.hykucommons.org" + + Account.find_each do |account| + next unless account.cname == account_cname + + begin + switch!(account.cname) + puts "********************** switched to #{account.cname} **********************" + + file_set_titles = ["HykuCommonsPlaceholder.pdf", "hykuplaceholderarchives.pdf"] + query = file_set_titles.map { |title| "title_tesim:\"#{title}\"" }.join(" OR ") + file_sets = FileSet.where(query) + file_sets.each { |file_set| file_set.destroy(eradicate: true) } + rescue StandardError => e + puts "********************** error: #{e} **********************" + next + end + end + end +end