Skip to content

Instantly share code, notes, and snippets.

@rosy1280
Last active August 29, 2015 14:10
Show Gist options
  • Save rosy1280/c301f96660c963592967 to your computer and use it in GitHub Desktop.
Save rosy1280/c301f96660c963592967 to your computer and use it in GitHub Desktop.
bulk close versions via console
druids = ["druid:bt238kw3938", "druid:bw690ww9101", "druid:cc502yd9847", "druid:ch100bz7050"]
druids.each do |druid|
begin
@object=Dor::Item.find(druid)
# for some reason this doesn't seem to work. no idea why...
#Dor::WorkflowService.close_version 'dor', @object.pid, {:description=>'apply apo defaults', :significance=>:minor}
# so instead I'll do the following
@object.versionMetadata.update_current_version({:description=>'apply apo defaults', :significance=>:minor})
@object.save
Dor::WorkflowService.close_version 'dor', @object.pid
end
end
@rosy1280
Copy link
Author

rosy1280 commented Dec 4, 2014

i noticed that the bulk close doesn't work when an object's version metadata is jankey like the below

<?xml version="1.0"?>
<versionMetadata objectId="druid:mv678kn5949">
  <version tag="1.0.0" versionId="1">
    <description>Initial Version</description>
  </version>
  <version tag="1.1.0" versionId="2">
    <description>add collection object</description>
  </version>
  <version versionId="3"/>
</versionMetadata>

this little script when run in console fixes that.

documentation: http://www.rubydoc.info/gems/dor-services/Dor/Versionable:close_version
code: https://github.com/sul-dlss/dor-services/blob/24ec33c8e289e81fe5926b2727a9b3d0b624e40a/lib/dor/models/versionable.rb#L63

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment