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

Adds Fedora record removal to DeletePhysicalInstantiations fix #925

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

afred
Copy link
Contributor

@afred afred commented Oct 1, 2024

No description provided.

@afred afred force-pushed the 854-more-more-more-delete-Fedora-hangers-on branch from 1e72e96 to 3bcb39e Compare October 31, 2024 17:49
@afred afred force-pushed the 854-more-more-more-delete-Fedora-hangers-on branch from 3bcb39e to c72ab04 Compare October 31, 2024 18:53
@afred afred force-pushed the 854-more-more-more-delete-Fedora-hangers-on branch from c72ab04 to e95c5b8 Compare November 1, 2024 17:57
@afred afred force-pushed the 854-more-more-more-delete-Fedora-hangers-on branch from e95c5b8 to ddaf04d Compare November 1, 2024 18:33
@afred afred force-pushed the 854-more-more-more-delete-Fedora-hangers-on branch 2 times, most recently from 027cfd9 to 7fbff53 Compare November 4, 2024 16:36
@afred afred force-pushed the 854-more-more-more-delete-Fedora-hangers-on branch from 7fbff53 to 54ee1e2 Compare November 4, 2024 18:45
@afred afred force-pushed the 854-more-more-more-delete-Fedora-hangers-on branch from 54ee1e2 to 5574158 Compare November 5, 2024 17:11
@afred afred force-pushed the 854-more-more-more-delete-Fedora-hangers-on branch 3 times, most recently from 4010868 to 5f46e37 Compare November 7, 2024 15:21
@afred afred marked this pull request as ready for review November 7, 2024 15:48
@afred afred requested review from orangewolf and bkiahstroud and removed request for orangewolf November 7, 2024 15:49
Comment on lines +21 to +27
@members ||= []
member_id_vals = member_ids.map { |id| id.to_s }.to_set
ids_from_members = @members.map { |m| m.id.to_s }.to_set
# If the member_ids do not match the IDs within the members, then re-set the members to be an accurate reflection of the member IDs.
# This allows us to modify resource.member_ids and have #members accurately reflect the changes.
if member_id_vals != ids_from_members
@members = member_ids.map do |id|
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain more about what's happening on these lines and why?

Copy link
Contributor Author

@afred afred Nov 19, 2024

Choose a reason for hiding this comment

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

The WorkBehavior#members is supposed to be a memoized, but accurate, mapping of member_ids to objects returned from Hyrax.query_service. When deleting members, I remove their IDs from the member_ids array of the parent (we could not use the Hyrax transaction for reasons I can explain if you want).

But then the #members would be out of sync. So I fixed the cache-busting condition to just detect if the @members and member_ids are different, and if so, reset @members to accurately reflect member_ids.

def destroy_work_and_members(resource:)
result = { resource: resource }
resource.members.each do |member|
resource.members.delete(member)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please explain the purpose of this line? (28)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's supposed to be removing the child from the parent, but if you are thinking it should be deleting from member_ids instead of members, I think you are correct.

This delete_asset_resources is code I added as a consolidation/replacement for other Asset deleting scripts we have that can be run from command line. This one does a recursive delete to get at EssenceTracks which were being left behind, and I was using it a lot in the course of testing so that's why it's included here. Could be a separate PR but hoping to save a little time by combining. It is stand alone and shouldn't affect the script for deleting physical instantiations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, since this is doing a depth-first recursive call to traverse the tree, removing that line really has no effect -- the everything gets deleted, children first. Removing.

lib/fix/sample_data.rb Outdated Show resolved Hide resolved
Fedora records were not being deleted and were then being retreived by PhysicalInstantiationResource
models, effectively getting stuck on the parent Asset.

This allows the Fix::DeletePhysicalInstantiaton class to remove PhysicalInstantiations of a give
media type from a set of AssetResources identified by an ID list.

Usage:

    ruby lib/fix/delete_physical_instantiations --file aapb_ids.txt --media-type 'Moving Image'

Also,
* Includes class SampleData class for finding test data sets within an existing repository (e.g. demo).
@afred afred force-pushed the 854-more-more-more-delete-Fedora-hangers-on branch from 5f46e37 to b235a80 Compare December 5, 2024 16:52
@foglabs foglabs merged commit fc3dbd0 into develop Dec 5, 2024
6 checks passed
@foglabs foglabs deleted the 854-more-more-more-delete-Fedora-hangers-on branch December 5, 2024 17:16
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