app/controllers/collections_controller.rb
# TODO - review these. There are too many and as a result there's some redundancy in, for example, checking whether the user is logged in on unpublished
# collections
review these. There are too many and as a result there's some redundancy in, for example, checking whether the user is logged in on unpublished
collections
review these . There are too many and as a result there ' s some redundancy in for example checking whether the user is logged in on unpublished collections
def quick_copy_entire_collection_and_redirect(source, destinations, options)
    last_collection_item = CollectionItem.last(select: 'id') 
    destinations.each do |destination|
      CollectionItem.connection.execute(
        "INSERT IGNORE INTO collection_items
          (collected_item_type, collected_item_id, collection_id, created_at, updated_at, added_by_user_id)
          (SELECT collected_item_type, collected_item_id, #{destination.id}, NOW(), NOW(), #{current_user.id}
            FROM collection_items WHERE collection_id = #{source.id})"
      )
      destination.update_attribute(collection_items_count, destination.collection_items.count)
      log_activity(collection_id: destination.id, activity: Activity.bulk_add)
    end
    ids = CollectionItem.connection.execute(
      "SELECT id FROM collection_items
       WHERE id > #{last_collection_item.id} AND collection_id IN (#{destinations.map { |d| d.id}.join(',')})"
    ).map { |a| a.first }
    EOL::Solr::CollectionItemsCoreRebuilder.reindex_collection_items_by_ids(ids)
    action = options[:move] ? 'moved' : 'copied'
    if options[:move]
      if destinations.include?(source)
        action = 'copied' 
      else
        source.collection_items.each { |item| item.destroy }
        log_activity(activity: Activity.remove_all)
      end
    end
    if destinations.count == 1
      flash[:notice] = I18n.t("#{action}_all_items_from_collection_with_count", count: ids.count,
                              from: link_to_name(source))
      return redirect_to collection_path(destinations.first), status: :moved_permanently
    else
      flash[:notice] = I18n.t("#{action}_all_items_to_collections", count: destinations.count,
                              name: link_to_name(source))
      return redirect_to collection_path(source), status: :moved_permanently
    end
  end
def quick_copy_entire_collection_and_redirect ( source , destinations , options ) last_collection_item = CollectionItem . last ( select : 'id' ) destinations . each do | destination | CollectionItem . connection . execute ( "INSERT IGNORE INTO collection_items
          (collected_item_type, collected_item_id, collection_id, created_at, updated_at, added_by_user_id)
          (SELECT collected_item_type, collected_item_id, #{destination.id}, NOW(), NOW(), #{current_user.id}
            FROM collection_items WHERE collection_id = #{source.id})" ) destination . update_attribute ( collection_items_count , destination . collection_items . count ) log_activity ( collection_id : destination . id , activity : Activity . bulk_add ) end ids = CollectionItem . connection . execute ( "SELECT id FROM collection_items
       WHERE id > #{last_collection_item.id} AND collection_id IN (#{destinations.map { |d| d.id}.join(',')})" ) . map { | a | a . first } EOL :: Solr :: CollectionItemsCoreRebuilder . reindex_collection_items_by_ids ( ids ) action = options [ :move ] ? 'moved' : 'copied' if options [ :move ] if destinations . include? ( source ) action = 'copied' else source . collection_items . each { | item | item . destroy } log_activity ( activity : Activity . remove_all ) end end if destinations . count == 1 flash [ :notice ] = I18n . t ( "#{action}_all_items_from_collection_with_count" , count : ids . count , from : link_to_name ( source ) ) return redirect_to collection_path ( destinations . first ) , status : :moved_permanently else flash [ :notice ] = I18n . t ( "#{action}_all_items_to_collections" , count : destinations . count , name : link_to_name ( source ) ) return redirect_to collection_path ( source ) , status : :moved_permanently end end
TODO - review these.
TODO - review these .
# Sloppy, but... # Because we did it manually, the count (shown in searches) will be off, so fix it: # TODO - we should actually count the items and store that in the collection activity log. Lots of work: # NOTE - this is pretty brutal. The older method preserves objects that didn't actually move (ie: if they were # duplicates), but I figure that's not entirely desirable, anyway... # Undo the "move"... we can't blow away the items in a source if it's a destination!
source
<not_specific>
destinations
<not_specific>
options
<not_specific>