app/controllers/application_controller.rb
# Ensure that the user has this in their watch_colleciton, so they will get replies in their newsfeed:
Ensure that the user has this in their watch_colleciton, so they will get replies in their newsfeed.
Ensure that the user has this in their watch_colleciton so they will get replies in their newsfeed .
def auto_collect(what, options = {})
    return if what === current_user
    watchlist = current_user.watch_collection
    if what.class == DataObject
      all_revision_ids = DataObject.find_all_by_guid_and_language_id(what.guid, what.language_id, select: 'id').map { |d| d.id }
      collection_item = CollectionItem.where(['collection_id = ? AND collected_item_id IN (?) AND collected_item_type = ?',
                                             watchlist.id, all_revision_ids, what.class.name]).first
    else
      collection_item = CollectionItem.where(['collection_id = ? AND collected_item_id = ? AND collected_item_type = ?', watchlist.id, what.id, what.class.name])
    end
    if collection_item.nil?
      collection_item = begin 
        CollectionItem.create(annotation: options[:annotation], collected_item: what, collection_id: watchlist.id)
      rescue => e
        Rails.logger.error "** ERROR COLLECTING: #{e.message} FROM #{e.backtrace.first}"
        nil
      end
      if collection_item && collection_item.save
        return unless what.respond_to?(:summary_name) 
        flash[:notice] ||= ''
        flash[:notice] += ' '
        flash[:notice] += I18n.t(:item_added_to_watch_collection_notice,
                                 collection_name: self.class.helpers.link_to(watchlist.name,
                                                                                collection_path(watchlist)),
                                 item_name: what.summary_name)
        CollectionActivityLog.create(collection: watchlist, user_id: current_user.id,
                             activity: Activity.collect, collection_item: collection_item)
      end
    end
  end
def auto_collect ( what , options = { } ) return if what === current_user watchlist = current_user . watch_collection if what . class == DataObject all_revision_ids = DataObject . find_all_by_guid_and_language_id ( what . guid , what . language_id , select : 'id' ) . map { | d | d . id } collection_item = CollectionItem . where ( [ 'collection_id = ? AND collected_item_id IN (?) AND collected_item_type = ?' , watchlist . id , all_revision_ids , what . class . name ] ) . first else collection_item = CollectionItem . where ( [ 'collection_id = ? AND collected_item_id = ? AND collected_item_type = ?' , watchlist . id , what . id , what . class . name ] ) end if collection_item . nil? collection_item = begin CollectionItem . create ( annotation : options [ :annotation ] , collected_item : what , collection_id : watchlist . id ) rescue => e Rails . logger . error "** ERROR COLLECTING: #{e.message} FROM #{e.backtrace.first}" nil end if collection_item && collection_item . save return unless what . respond_to? ( :summary_name ) flash [ :notice ] ||= '' flash [ :notice ] += ' ' flash [ :notice ] += I18n . t ( :item_added_to_watch_collection_notice , collection_name : self . class . helpers . link_to ( watchlist . name , collection_path ( watchlist ) ) , item_name : what . summary_name ) CollectionActivityLog . create ( collection : watchlist , user_id : current_user . id , activity : Activity . collect , collection_item : collection_item ) end end end
Ensure that the user has this in their watch_colleciton, so they will get replies in their newsfeed:
Ensure that the user has this in their watch_colleciton so they will get replies in their newsfeed :
# We do not care if this fails. # Failsafe.  Most things should.
what
<not_specific>
options
<not_specific>