Skip to content

Commit

Permalink
Delete the list node and indirect container proxy when you purge a fi…
Browse files Browse the repository at this point in the history
…leset (#1368)

* delete the list node and indirect container proxy when you purge a fileset

Our current application isn't cleaning up all the proxies when you purge
a fileset.  This results in an `owning_class` error when trying to
perform a FileAttachementJob. `unlocked_obj.ordered_members.to_a` is `[nil]`

Hydra-works is confusing.  I can see why this might have been missed the
first time around

* fix the moving target bug

The problem with iterating through the proxies and trying to delete the
nil proxies in place is that on any subsequent deletes the index has moved.

For example
uo.ordered_members = [nil, nil]
uo.ordered_member_proxies.delete_at(0)
uo.ordered_members = [nil]
uo.ordered_member_proxies.delete_at(1)
uo.ordered_members = [nil]
etc...
  • Loading branch information
pgwillia authored Jan 7, 2020
1 parent 26c3624 commit f2b3f7a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and releases in Jupiter project adheres to [Semantic Versioning](http://semver.o

## [Unreleased]

### Fixed
- delete the list node and indirect container proxy when you purge a fileset [#1354](https://github.com/ualbertalib/jupiter/issues/1354)

## [1.2.18] - 2019-10-22
- Removed Rack Attack

Expand Down
8 changes: 6 additions & 2 deletions app/models/concerns/item_properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,14 @@ def add_communities_and_collections(communities, collections)

def purge_filesets
FileSet.where(item: id).each do |fs|
fs.unlock_and_fetch_ldp_object(&:delete)
fs.unlock_and_fetch_ldp_object do |fileset|
ordered_members.delete(fs) # delete the list node
members.delete(fs) # delete the indirect container proxy
fileset.delete # delete the fileset
end
end

self.ordered_members = []
save
end

def push_item_id_for_preservation
Expand Down
21 changes: 21 additions & 0 deletions lib/tasks/jupiter.rake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ namespace :jupiter do
puts 'Reindex completed!'
end

desc 'cleanup orphaned proxies'
task cleanup_proxies: :environment do
puts 'Visiting all Items and Theses...'
(Item.all + Thesis.all).each do |item|
item.unlock_and_fetch_ldp_object do |uo|
changed = false
indexes = []
uo.ordered_member_proxies.each_with_index do |proxy, index|
next if proxy.proxy_for

indexes << index
puts "#{item.id} has a nil proxy"
changed = true
end
indexes.sort { |a, b| b <=> a }.each { |index| uo.ordered_member_proxies.delete_at(index) }
uo.save! if changed
end
end
puts 'Nil proxy search completed!'
end

desc 'queue all items and theses in the system for preservation'
task preserve_all_items_and_theses: :environment do
puts 'Adding all Items and Theses to preservation queue...'
Expand Down

0 comments on commit f2b3f7a

Please sign in to comment.