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 copy_items_and_redirect(source, destinations, options = {})
    if params[:scope] == 'all_items'
      return quick_copy_entire_collection_and_redirect(source, destinations, options)
    else
      copied = {}
      @copied_to = []
      all_items = []
      Collection.preload_associations(destinations, :collection_items)
      params[:collection_items] = CollectionItem.find(params[:collection_items], include: :collected_item) if params[:collection_items]
      Collection.preload_associations(source, :users)
      destinations.each do |destination|
        begin
          items = copy_items(from: source, to: destination, items: params[:collection_items],
                             scope: params[:scope])
          copied[link_to_name(destination)] = items.count
          all_items += items
        rescue EOL::Exceptions::MaxCollectionItemsExceeded
          flash[:error] = I18n.t(:max_collection_items_error, max: $MAX_COLLECTION_ITEMS_TO_MANIPULATE)
          return redirect_to collection_path(@collection)
        end
      end
      all_items.compact!
      flash_i18n_name = :copied_items_to_collections_with_count_notice
      if all_items.count > 0
        if options[:move]
          remove_items(from: source, items: all_items)
          @collection_items.delete_if { |ci| params['collection_items'].include?(ci.id.to_s) } if @collection_items && params['collection_items']
          if destinations.length == 1
            flash[:notice] = I18n.t(:moved_items_from_collection_with_count_notice, count: all_items.count,
                                    name: link_to_name(source))
            flash[:notice] += " #{I18n.t(:duplicate_items_were_ignored)}" if @duplicates
            return redirect_to collection_path(destinations.first), status: :moved_permanently
          else
            flash_i18n_name = :moved_items_to_collections_with_count_notice
          end
        else
          if destinations.length == 1
            flash[:notice] = I18n.t(:copied_items_from_collection_with_count_notice, count: all_items.count,
                                    name: link_to_name(source))
            flash[:notice] += " #{I18n.t(:duplicate_items_were_ignored)}" if @duplicates
            return redirect_to collection_path(destinations.first), status: :moved_permanently
          end
        end
        flash[:notice] = I18n.t(flash_i18n_name,
                                count: all_items.count,
                                names: copied.keys.map { |c| "#{c} (#{copied[c]})"}.to_sentence)
        flash[:notice] += " #{I18n.t(:duplicate_items_were_ignored)}" if @duplicates
        return redirect_to collection_path(source), status: :moved_permanently
      elsif all_items.count == 0
        flash[:error] = I18n.t(:no_items_were_copied_to_collections_error, names: @no_items_to_collections.to_sentence)
        flash[:error] += " #{I18n.t(:duplicate_items_were_ignored)}" if @duplicates
        return redirect_to collection_path(source), status: :moved_permanently
      else
        return redirect_to collection_path(source), status: :moved_permanently
      end
    end
  end
def copy_items_and_redirect ( source , destinations , options = { } ) if params [ :scope ] == 'all_items' return quick_copy_entire_collection_and_redirect ( source , destinations , options ) else copied = { } @copied_to = [ ] all_items = [ ] Collection . preload_associations ( destinations , :collection_items ) params [ :collection_items ] = CollectionItem . find ( params [ :collection_items ] , include : :collected_item ) if params [ :collection_items ] Collection . preload_associations ( source , :users ) destinations . each do | destination | begin items = copy_items ( from : source , to : destination , items : params [ :collection_items ] , scope : params [ :scope ] ) copied [ link_to_name ( destination ) ] = items . count all_items += items rescue EOL :: Exceptions :: MaxCollectionItemsExceeded flash [ :error ] = I18n . t ( :max_collection_items_error , max : $MAX_COLLECTION_ITEMS_TO_MANIPULATE ) return redirect_to collection_path ( @collection ) end end all_items . compact! flash_i18n_name = :copied_items_to_collections_with_count_notice if all_items . count > 0 if options [ :move ] remove_items ( from : source , items : all_items ) @collection_items . delete_if { | ci | params [ 'collection_items' ] . include? ( ci . id . to_s ) } if @collection_items && params [ 'collection_items' ] if destinations . length == 1 flash [ :notice ] = I18n . t ( :moved_items_from_collection_with_count_notice , count : all_items . count , name : link_to_name ( source ) ) flash [ :notice ] += " #{I18n.t(:duplicate_items_were_ignored)}" if @duplicates return redirect_to collection_path ( destinations . first ) , status : :moved_permanently else flash_i18n_name = :moved_items_to_collections_with_count_notice end else if destinations . length == 1 flash [ :notice ] = I18n . t ( :copied_items_from_collection_with_count_notice , count : all_items . count , name : link_to_name ( source ) ) flash [ :notice ] += " #{I18n.t(:duplicate_items_were_ignored)}" if @duplicates return redirect_to collection_path ( destinations . first ) , status : :moved_permanently end end flash [ :notice ] = I18n . t ( flash_i18n_name , count : all_items . count , names : copied . keys . map { | c | "#{c} (#{copied[c]})" } . to_sentence ) flash [ :notice ] += " #{I18n.t(:duplicate_items_were_ignored)}" if @duplicates return redirect_to collection_path ( source ) , status : :moved_permanently elsif all_items . count == 0 flash [ :error ] = I18n . t ( :no_items_were_copied_to_collections_error , names : @no_items_to_collections . to_sentence ) flash [ :error ] += " #{I18n.t(:duplicate_items_were_ignored)}" if @duplicates return redirect_to collection_path ( source ) , status : :moved_permanently else return redirect_to collection_path ( source ) , status : :moved_permanently end end end
TODO - review these.
TODO - review these .
# TODO - this rescue can cause SOME work to get done and others not.  It should be moved. #.why_am_i_shouting!? # Not handling any weird errors here, to simplify flash notice handling. # Assume the flash message was set by #copy_items
source
<not_specific>
destinations
<not_specific>
options
<not_specific>