scientist-softserv / palni-palci

Other
1 stars 0 forks source link

Create script to remove all instances of a specific file that has been uploaded in a tenant (placeholder PDF files) #912

Closed jillpe closed 10 months ago

jillpe commented 11 months ago

Summary

Want to remove "HykuCommonsPlaceholder.pdf" and "hykuplaceholderarchives.pdf" from dickinson.hykucommons.org

Pals is okay if this is a one time script that SoftServ runs.

Acceptance Criteria

Testing Instructions

Create several works, upload each file and set them as their thumbnail:

hykuplaceholderarchives.pdf

HykuCommonsPlaceholder.pdf

After running the script, these works should no longer be attached to the works.

jillpe commented 11 months ago

What do you want this to look like? (Do you want to provide the file name and it runs the script in the UI? If so, who has permission to do that?)

ShanaLMoore commented 11 months ago

This may be helpful to reference.

ShanaLMoore commented 11 months ago

I drafted this up waiting for a build. Maybe something like this will work? NOTE: I DID NOT TEST THIS

TODO: test on staging. (Note: You may need to update the cname in the script)

Create several works, upload each file and set them as their thumbnail:

hykuplaceholderarchives.pdf

HykuCommonsPlaceholder.pdf

After running the script, these works should no longer be attached to the works.


namespace :hyku do
  desc "Delete specific thumbnails for dickinson account"
  task delete_dickinson_placeholder_thumbnails: :environment do
    account_cname = "dickinson.hykucommons.org"

    Account.find_each do |account|
      next unless account.cname == account_cname

      begin
        switch!(account.cname)
        puts "********************** switched to #{account.cname} **********************"

        Hyrax.config.curation_concerns.each do |cc|
          next if cc.count.zero?

          puts "********************** checking #{cc}s **********************"

          cc.find_each do |work|
            if work.thumbnail && (work.thumbnail.title == "HykuCommonsPlaceholder.pdf" || work.thumbnail.title == "hykuplaceholderarchives.pdf")
              work.thumbnail.destroy(eradicate: true)
              puts "Deleted thumbnail for #{work.id}"
              next
            end
          end

          puts "********************** updated #{cc}s **********************"
        end
      rescue StandardError => e
        puts "********************** error: #{e} **********************"
        next
      end
    end
  end
end
ShanaLMoore commented 11 months ago

QA Results: PASS ✅

@ndroark I don't think one requires your review. Is it ok to deploy to prod?

Tested on: Staging

Testing Instructions

Create several works, upload each file and set them as their thumbnail:

hykuplaceholderarchives.pdf

HykuCommonsPlaceholder.pdf

After running the script, these works should no longer be attached to the works.

Acceptance Criteria

Note: In this case, I set the ENV var in staging so that it would run the script against demo.commons-archive.org instead of dickinson.hykucommons.org

image

Screenshot

BEFORE

image

AFTER

image

ndroark commented 10 months ago

I am seeing some works in Dickinson that still have the file, e.g. https://dickinson.hykucommons.org/concern/generic_works/933487b5-287d-409d-ad3d-1a221a6778f8?locale=en

kirkkwang commented 10 months ago

@ndroark We did not actually run the script at the time, but i just finished running it, can you check now?

ndroark commented 10 months ago

I was wondering if that was the case. Looks like the file is removed, but on search results I'm seeing a broken link instead of the generic thumbnail. My guess is that the next reindex will take care of that? Screenshot(74)

kirkkwang commented 10 months ago

hmmm that's interesting, i'm not seeing the broken thumbs

image

can you check it cache cleared just in case?