Skip to content

Commit

Permalink
fix: add check if works or child works are empty continue with deleteion
Browse files Browse the repository at this point in the history
  • Loading branch information
pghorpade committed Dec 4, 2023
1 parent b03fcf9 commit 1b2b40d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/lib/californica/deleter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def delete
# Modified to ensure all works are deleted before deleting the collection
def delete_collection_with_works(of_type: nil)
log('In delete_collection_with_works start.')
all_works_deleted = delete_works(of_type: of_type)
works = work_id_list
all_works_deleted = works.empty? || delete_works(of_type: of_type)
if all_works_deleted && (of_type.nil? || record.is_a?(of_type))
delete
true
Expand All @@ -33,7 +34,7 @@ def delete_collection_with_works(of_type: nil)

# Ensures all works are deleted; returns true if successful
def delete_works(of_type: nil)
work_id_list.all? do |work_id|
work_id_list.empty? || work_id_list.all? do |work_id|
Californica::Deleter.new(id: work_id, logger: logger)
.delete_with_children(of_type: of_type)
end
Expand All @@ -42,7 +43,8 @@ def delete_works(of_type: nil)
# Modified to ensure all works are deleted before deleting the collection
def delete_with_children(of_type: nil)
log('In delete_with_children start.')
all_children_deleted = delete_children(of_type: of_type)
children = record&.member_ids
all_children_deleted = children.nil? || children.empty? || delete_children(of_type: of_type)
if all_children_deleted && (of_type.nil? || record.is_a?(of_type))
delete
true
Expand All @@ -54,7 +56,7 @@ def delete_with_children(of_type: nil)

# Ensures all child works are deleted; returns true if successful
def delete_children(of_type: nil)
record&.member_ids&.all? do |child_id|
record&.member_ids&.empty? || record&.member_ids&.all? do |child_id|
Californica::Deleter.new(id: child_id, logger: logger)
.delete_with_children(of_type: of_type)
end
Expand Down

0 comments on commit 1b2b40d

Please sign in to comment.