app/models/data_object.rb
# NOTE - you probably want to check that the user performing this has rights to do so, before calling this.
you probably want to check that the user performing this has rights to do so, before calling this.
you probably want to check that the user performing this has rights to do so before calling this .
def replicate(params, options)
    DataObject.set_subtype_if_link_object(params, options)
    DataObject.populate_rights_holder_or_data_subtype(params, options)
    object_is_a_link = (!options[:link_type_id].blank? && options[:link_type_id] != 0)
    params[:source_url] = DataObject.add_http_if_missing(params[:source_url]) if object_is_a_link
    new_dato = DataObject.new(params.reverse_merge!(
      object_created_at: Time.now,
      object_modified_at: Time.now,
      guid: self.guid, published: 1
    ))
    if new_dato.save
      begin
        new_dato.toc_items = Array(TocItem.find(options[:toc_id]))
        new_dato.unpublish_previous_revisions
        if object_is_a_link
          new_dato.data_objects_link_type = DataObjectsLinkType.create(data_object: new_dato, link_type_id: options[:link_type_id])
        end
        new_dato.users_data_object = users_data_object.replicate(new_dato)
        DataObjectsTaxonConcept.find_or_create_by_taxon_concept_id_and_data_object_id(users_data_object.taxon_concept_id, new_dato.id)
        new_dato.recalculate_rating
      rescue => e
        new_dato.update_column(:published, false)
        raise e
      ensure
        new_dato.update_solr_index
      end
    end
    new_dato
  end
def replicate ( params , options ) DataObject . set_subtype_if_link_object ( params , options ) DataObject . populate_rights_holder_or_data_subtype ( params , options ) object_is_a_link = ( ! options [ :link_type_id ] . blank? && options [ :link_type_id ] != 0 ) params [ :source_url ] = DataObject . add_http_if_missing ( params [ :source_url ] ) if object_is_a_link new_dato = DataObject . new ( params . reverse_merge! ( object_created_at : Time . now , object_modified_at : Time . now , guid : self . guid , published : 1 ) ) if new_dato . save begin new_dato . toc_items = Array ( TocItem . find ( options [ :toc_id ] ) ) new_dato . unpublish_previous_revisions if object_is_a_link new_dato . data_objects_link_type = DataObjectsLinkType . create ( data_object : new_dato , link_type_id : options [ :link_type_id ] ) end new_dato . users_data_object = users_data_object . replicate ( new_dato ) DataObjectsTaxonConcept . find_or_create_by_taxon_concept_id_and_data_object_id ( users_data_object . taxon_concept_id , new_dato . id ) new_dato . recalculate_rating rescue => e new_dato . update_column ( :published , false ) raise e ensure new_dato . update_solr_index end end new_dato end
NOTE - you probably want to check that the user performing this has rights to do so, before calling this.
NOTE - you probably want to check that the user performing this has rights to do so before calling this .
# NOTE - associations will be preserved in their current vetted state by # virtue of the GUID. There was once code here to trust all # associations, if the user was a curator or admin. We have since # elucidated that we do NOT want to change the vetted state after an # update.
params
<not_specific>
options
<not_specific>