Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Add task to remove placeholder file sets #938

Merged
merged 1 commit into from
Dec 8, 2023

Conversation

kirkkwang
Copy link
Contributor

@kirkkwang kirkkwang commented Dec 8, 2023

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:

REMOVE_PLACEHOLDER_FILE_SETS_FROM="dev.hyku.test" rake hyku:remove_placeholder_file_sets

Ref:

Notes

This should only be run once and future file sets of the placeholder pdf should not appear.

Tested locally and it worked for me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be an auto page size of 10,000 records. Meaning you might need to run this multiple times.

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:
  - #912
@kirkkwang kirkkwang force-pushed the i912-remove-placeholder-files branch from 14ebf96 to 162b148 Compare December 8, 2023 06:35
@kirkkwang kirkkwang merged commit f82f6d8 into main Dec 8, 2023
5 of 7 checks passed
@kirkkwang kirkkwang deleted the i912-remove-placeholder-files branch December 8, 2023 14:30
next unless account.cname == account_cname

begin
switch!(account.cname)
Copy link
Contributor

@ShanaLMoore ShanaLMoore Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it that this task is dynamic and reusable + the query approach. well done! 🎉

Copy link
Contributor

@ShanaLMoore ShanaLMoore Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kirkkwang A few more thoughts:

This works but after going through QA it was kind of a pain having to remember to set the env var to test what I needed.

I think it would be nice if we could pass the cname when calling the rake task command. I also think the file name is a misnomer if we want this to be more dynamic.

Copy link
Contributor

@ShanaLMoore ShanaLMoore Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this but maybe something like this?

# rename file to lib/tasks/remove_placeholders.rake

namespace :hyku do
  desc "Remove Hyku Commons placeholder file sets from tenants"
  task :remove_placeholder_file_sets, [:cnames] => :environment do |t, args|
    cnames = args[:cnames].split(',')
    cnames.each do |cname|
      account = Account.find_by(cname: cname)
      next unless account

      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} **********************"
      end
    end
  end
end

Then we could call the rake task and pass it an array of cnames

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants