Skip to content

updating works and file sets

James Van Mil edited this page Aug 28, 2018 · 4 revisions

Changing the owner on works and their filesets, removing the previous owner as editor

work_ids = %w{
  id_one id_two id_three
}

new_depositor = "[email protected]"

def update_depositor(work_ids, new_depositor)
  work_ids.each do |id|
    work = Hyrax::WorkRelation.new.find(id)

    old_depositor = work.depositor
    work.depositor = new_depositor

    work.edit_users -= [old_depositor]
    work.edit_users += [new_depositor]

    work.save

    work.file_sets.each do |fs|
      fs.depositor = new_depositor
      fs.edit_users -= [old_depositor]
      fs.edit_users += [new_depositor]
      fs.save
    end
  end
end

update_depositor(work_ids, new_depositor)
Clone this wiki locally