diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1f296767e0..69e2fcef46 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -14,15 +14,15 @@ def set_sidebar(type = :generic, data = :all, args = {}) args[:note_count] ||= 8 if type == :tags # accepts data of array of tag names as strings if params[:controller] == 'questions' - @notes = @notes || DrupalTag.find_nodes_by_type(data, 'note', args[:note_count]) + @notes = @notes || Tag.find_nodes_by_type(data, 'note', args[:note_count]) else - @notes = @notes || DrupalTag.find_research_notes(data, args[:note_count]) + @notes = @notes || Tag.find_research_notes(data, args[:note_count]) end @notes = @notes.where('node.nid != (?)', @node.nid) if @node - @wikis = DrupalTag.find_pages(data,10) - @videos = DrupalTag.find_nodes_by_type_with_all_tags(['video']+data,'note',8) if args[:videos] && data.length > 1 - @maps = DrupalTag.find_nodes_by_type(data,'map',20) + @wikis = Tag.find_pages(data,10) + @videos = Tag.find_nodes_by_type_with_all_tags(['video']+data,'note',8) if args[:videos] && data.length > 1 + @maps = Tag.find_nodes_by_type(data,'map',20) else # type is generic # remove "classroom" postings; also switch to an EXCEPT operator in sql, see https://github.com/publiclab/plots2/issues/375 hidden_nids = DrupalNode.joins(:drupal_node_community_tag) @@ -192,7 +192,7 @@ def sort_question_by_tags @session_tags = session[:tags] qids = @questions.collect(&:nid) @questions = DrupalNode.where(status: 1, type: 'note') - .joins(:drupal_tag) + .joins(:tag) .where('term_data.name IN (?)', @session_tags.values) .where('node.nid IN (?)', qids) .group('node.nid') diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 6ec7e9ef85..584b28b76e 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -48,7 +48,7 @@ def dashboard @wiki_count = DrupalNodeRevision.select(:timestamp) .where(timestamp: Time.now.to_i - 1.weeks.to_i..Time.now.to_i) .count - @blog = DrupalTag.find_nodes_by_type('blog', 'note', 1).first + @blog = Tag.find_nodes_by_type('blog', 'note', 1).first # remove "classroom" postings; also switch to an EXCEPT operator in sql, see https://github.com/publiclab/plots2/issues/375 hidden_nids = DrupalNode.joins(:drupal_node_community_tag) .joins("LEFT OUTER JOIN term_data ON term_data.tid = community_tags.tid") diff --git a/app/controllers/map_controller.rb b/app/controllers/map_controller.rb index 6ef5424822..95acd6d086 100644 --- a/app/controllers/map_controller.rb +++ b/app/controllers/map_controller.rb @@ -6,13 +6,13 @@ def index .order("nid DESC") .where(type: 'map', status: 1) - # I'm not sure if this is actually eager loading the drupal_tags... - @maps = DrupalNode.joins(:drupal_tag) + # I'm not sure if this is actually eager loading the tags... + @maps = DrupalNode.joins(:tag) .where('type = "map" AND status = 1 AND (term_data.name LIKE ? OR term_data.name LIKE ?)', 'lat:%', 'lon:%') .uniq # This is supposed to eager load the url_aliases, and seems to run, but doesn't actually eager load them...? - #@maps = DrupalNode.select("node.*,url_alias.dst AS dst").joins(:drupal_tag).where('type = "map" AND status = 1 AND (term_data.name LIKE ? OR term_data.name LIKE ?)', 'lat:%', 'lon:%').joins("INNER JOIN url_alias ON url_alias.src = CONCAT('node/',node.nid)") + #@maps = DrupalNode.select("node.*,url_alias.dst AS dst").joins(:tag).where('type = "map" AND status = 1 AND (term_data.name LIKE ? OR term_data.name LIKE ?)', 'lat:%', 'lon:%').joins("INNER JOIN url_alias ON url_alias.src = CONCAT('node/',node.nid)") end def show @@ -206,7 +206,7 @@ def tag set_sidebar :tags, [params[:id]], {:note_count => 20} @tagnames = params[:id].split(',') - nids = DrupalTag.find_nodes_by_type(params[:id],'map',20).collect(&:nid) + nids = Tag.find_nodes_by_type(params[:id],'map',20).collect(&:nid) @notes = DrupalNode.paginate(page: params[:page]) .where('nid in (?)', nids) .order("nid DESC") diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index bc7150156f..c7a9f70e68 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -11,7 +11,7 @@ def index def methods @title = "Methods" @notes = DrupalNode.where(status: 1, type: ['page','tool']) - .includes(:drupal_node_revision, :drupal_tag) + .includes(:drupal_node_revision, :tag) .where('term_data.name = ?','tool') .page(params[:page]) .order("node_revisions.timestamp DESC") @@ -29,7 +29,7 @@ def techniques def places @title = "Places" @notes = DrupalNode.where(status: 1, type: ['page','place']) - .includes(:drupal_node_revision, :drupal_tag) + .includes(:drupal_node_revision, :tag) .where('term_data.name = ?','chapter') .page(params[:page]) .order("node_revisions.timestamp DESC") diff --git a/app/controllers/questions_search_controller.rb b/app/controllers/questions_search_controller.rb index 7bbf0b82d8..cbc4c9ae6c 100644 --- a/app/controllers/questions_search_controller.rb +++ b/app/controllers/questions_search_controller.rb @@ -13,7 +13,7 @@ def index 'type = "note" AND node.status = 1 AND title LIKE ?', "%" + params[:id] + "%" ) - .joins(:drupal_tag) + .joins(:tag) .where('term_data.name LIKE ?', 'question:%') .order('node.nid DESC') .page(params[:page]) @@ -32,7 +32,7 @@ def typeahead 'type = "note" AND node.status = 1 AND title LIKE ?', "%" + params[:id] + "%" ) - .joins(:drupal_tag) + .joins(:tag) .where('term_data.name LIKE ?', 'question:%') .order('node.nid DESC') .limit(25) diff --git a/app/controllers/subscription_controller.rb b/app/controllers/subscription_controller.rb index be969ba25a..8c54a3084f 100644 --- a/app/controllers/subscription_controller.rb +++ b/app/controllers/subscription_controller.rb @@ -34,11 +34,11 @@ def add if current_user # assume tag, for now if params[:type] == "tag" - tag = DrupalTag.find_by_name(params[:name]) + tag = Tag.find_by_name(params[:name]) if tag.nil? # if the tag doesn't exist, we should create it! # this could fail validations; error out if so... - tag = DrupalTag.new({ + tag = Tag.new({ :vid => 3, # vocabulary id :name => params[:name], :description => "", @@ -86,7 +86,7 @@ def add def delete # assume tag, for now if params[:type] == "tag" - id = DrupalTag.find_by_name(params[:name]).tid + id = Tag.find_by_name(params[:name]).tid end if id.nil? flash[:error] = "You are not subscribed to '#{params[:name]}'" @@ -114,7 +114,7 @@ def delete def set_following(value,type,id) # add swtich statement for different types: tag, node, user - if type == 'tag' && DrupalTag.find_by_tid(id) + if type == 'tag' && Tag.find_by_tid(id) # Create the entry if it isn't already created. # assume tag, for now: subscription = TagSelection.where(:user_id => current_user.uid, @@ -123,7 +123,7 @@ def set_following(value,type,id) # Check if the value changed. if subscription.following_changed? - #tag = DrupalTag.find(id) + #tag = Tag.find(id) # we have to implement caching for tags if we want to adapt this code: #if subscription.following # node.cached_likes = node.cached_likes + 1 diff --git a/app/controllers/tag_controller.rb b/app/controllers/tag_controller.rb index c0eac8e907..45a51cd920 100644 --- a/app/controllers/tag_controller.rb +++ b/app/controllers/tag_controller.rb @@ -6,7 +6,7 @@ class TagController < ApplicationController def index @title = I18n.t('tag_controller.tags') @paginated = true - @tags = DrupalTag.joins(:drupal_node_community_tag, :drupal_node) + @tags = Tag.joins(:drupal_node_community_tag, :drupal_node) .where('node.status = ?', 1) .paginate(:page => params[:page]) .order('count DESC') @@ -27,16 +27,16 @@ def show qids = DrupalNode.questions.where(status: 1).collect(&:nid) if params[:id][-1..-1] == "*" # wildcard tags @wildcard = true - @tags = DrupalTag.where('name LIKE (?)', params[:id][0..-2] + '%') + @tags = Tag.where('name LIKE (?)', params[:id][0..-2] + '%') nodes = DrupalNode.where(status: 1, type: node_type) - .includes(:drupal_node_revision, :drupal_tag) + .includes(:drupal_node_revision, :tag) .where('term_data.name LIKE (?) OR term_data.parent LIKE (?)', params[:id][0..-2] + '%', params[:id][0..-2] + '%') .page(params[:page]) .order("node_revisions.timestamp DESC") else - @tags = DrupalTag.find_all_by_name params[:id] + @tags = Tag.find_all_by_name params[:id] nodes = DrupalNode.where(status: 1, type: node_type) - .includes(:drupal_node_revision, :drupal_tag) + .includes(:drupal_node_revision, :tag) .where('term_data.name = ? OR term_data.parent = ?', params[:id], params[:id]) .page(params[:page]) .order("node_revisions.timestamp DESC") @@ -67,7 +67,7 @@ def show def widget num = params[:n] || 4 - nids = DrupalTag.find_nodes_by_type(params[:id],'note',num).collect(&:nid) + nids = Tag.find_nodes_by_type(params[:id],'note',num).collect(&:nid) @notes = DrupalNode.page(params[:page]) .where('status = 1 AND nid in (?)', nids) .order("nid DESC") @@ -75,11 +75,11 @@ def widget end def blog - nids = DrupalTag.find_nodes_by_type(params[:id],'note',20).collect(&:nid) + nids = Tag.find_nodes_by_type(params[:id],'note',20).collect(&:nid) @notes = DrupalNode.paginate(:page => params[:page], :per_page => 6) .where('status = 1 AND nid in (?)', nids) .order("nid DESC") - @tags = DrupalTag.find_all_by_name params[:id] + @tags = Tag.find_all_by_name params[:id] @tagnames = @tags.collect(&:name).uniq! || [] @title = @tagnames.join(',') + " Blog" if @tagnames end @@ -91,7 +91,7 @@ def author def barnstar node = DrupalNode.find params[:nid] tagname = "barnstar:"+params[:star] - if DrupalTag.exists?(tagname,params[:nid]) + if Tag.exists?(tagname,params[:nid]) flash[:error] = I18n.t('tag_controller.tag_already_exists') elsif !node.add_barnstar(tagname.strip,current_user) flash[:error] = I18n.t('tag_controller.barnstar_not_created') @@ -122,7 +122,7 @@ def create # this should all be done in the model: - if DrupalTag.exists?(tagname, params[:nid]) + if Tag.exists?(tagname, params[:nid]) @output[:errors] << I18n.t('tag_controller.tag_already_exists') elsif node.can_tag(tagname, current_user) === true || current_user.role == "admin"# || current_user.role == "moderator" saved, tag = node.add_tag(tagname.strip, current_user) @@ -178,7 +178,7 @@ def suggested if params[:id].length > 2 @suggestions = [] # filtering out tag spam by requiring tags attached to a published node - DrupalTag.where('name LIKE ?', "%" + params[:id] + "%") + Tag.where('name LIKE ?', "%" + params[:id] + "%") .includes(:drupal_node) .where('node.status = 1') .limit(10).each do |tag| @@ -193,12 +193,12 @@ def suggested def rss if params[:tagname][-1..-1] == "*" @notes = DrupalNode.where(:status => 1, :type => 'note') - .includes(:drupal_node_revision,:drupal_tag) + .includes(:drupal_node_revision,:tag) .where('term_data.name LIKE (?)', params[:tagname][0..-2]+'%') .limit(20) .order("node_revisions.timestamp DESC") else - @notes = DrupalTag.find_nodes_by_type([params[:tagname]],'note',20) + @notes = Tag.find_nodes_by_type([params[:tagname]],'note',20) end respond_to do |format| format.rss { @@ -217,9 +217,9 @@ def rss def contributors set_sidebar :tags, [params[:id]], {:note_count => 20} @tagnames = [params[:id]] - @tag = DrupalTag.find_by_name params[:id] + @tag = Tag.find_by_name params[:id] @notes = DrupalNode.where(:status => 1, :type => 'note') - .includes(:drupal_node_revision,:drupal_tag) + .includes(:drupal_node_revision,:tag) .where('term_data.name = ?', params[:id]) .order("node_revisions.timestamp DESC") @users = @notes.collect(&:author).uniq @@ -232,10 +232,10 @@ def contributors_index @tags = [] @tagnames.each do |tagname| - tag = DrupalTag.find_by_name(tagname) + tag = Tag.find_by_name(tagname) @tags << tag if tag @tagdata[tagname] = {} - t = DrupalTag.find :all, :conditions => {:name => tagname} + t = Tag.find :all, :conditions => {:name => tagname} nct = DrupalNodeCommunityTag.find :all, :conditions => ['tid in (?)',t.collect(&:tid)] @tagdata[tagname][:users] = DrupalNode.find(:all, :conditions => ['nid IN (?)',(nct).collect(&:nid)]).collect(&:author).uniq.length @tagdata[tagname][:wikis] = DrupalNode.count :all, :conditions => ["nid IN (?) AND (type = 'page' OR type = 'tool' OR type = 'place')", (nct).collect(&:nid)] @@ -252,7 +252,7 @@ def add_tag end tagnames = params[:name].split(',') tagnames.each do |tagname| - tag = DrupalTag.find_by_name(tagname) + tag = Tag.find_by_name(tagname) if tag session[:tags][tag.tid.to_s] = tagname else diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 28806563c6..633248481d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -143,7 +143,7 @@ def profile def likes @user = DrupalUsers.find_by_name(params[:id]) @title = "Liked by "+@user.name - @notes = @user.liked_notes.includes([:drupal_tag, :comments]) + @notes = @user.liked_notes.includes([:tag, :comments]) .paginate(page: params[:page], per_page: 20) @wikis = @user.liked_pages @tagnames = [] diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 05865bd362..9834398111 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -43,7 +43,7 @@ def show return if check_and_redirect_node(@node) if !@node.nil? # it's a place page! @tags = @node.tags - @tags += [DrupalTag.find_by_name(params[:id])] if DrupalTag.find_by_name(params[:id]) + @tags += [Tag.find_by_name(params[:id])] if Tag.find_by_name(params[:id]) else # it's a new wiki page! @title = I18n.t('wiki_controller.new_wiki_page') if current_user @@ -61,7 +61,7 @@ def show end @tagnames = @tags.collect(&:name) set_sidebar :tags, @tagnames, {:videos => true} - @wikis = DrupalTag.find_pages(@node.slug_from_path,30) if @node.has_tag('chapter') || @node.has_tag('tabbed:wikis') + @wikis = Tag.find_pages(@node.slug_from_path,30) if @node.has_tag('chapter') || @node.has_tag('tabbed:wikis') impressionist(@node.drupal_node_counter) @revision = @node.latest @@ -111,9 +111,9 @@ def new .order("node.nid DESC") .where('type = "page" AND node.status = 1 AND (node.title LIKE ? OR node_revisions.body LIKE ?)', "%" + title + "%","%" + title + "%") .includes(:drupal_node_revision) - tag = DrupalTag.find_by_name(params[:id]) # add page name as a tag, too + tag = Tag.find_by_name(params[:id]) # add page name as a tag, too @tags << tag if tag - @related += DrupalTag.find_nodes_by_type(@tags.collect(&:name),'page',10) + @related += Tag.find_nodes_by_type(@tags.collect(&:name),'page',10) end render :template => 'wiki/edit' end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fb6e0cbd48..826bccc47a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -40,7 +40,7 @@ def insert_extras(body) output += ' Likes' output += ' ' nodes = DrupalNode.where(status: 1, type: 'note') - .includes(:drupal_node_revision, :drupal_tag) + .includes(:drupal_node_revision, :tag) .where('term_data.name = ?', $1) .page(params[:page]) .order("node_revisions.timestamp DESC") diff --git a/app/mailers/subscription_mailer.rb b/app/mailers/subscription_mailer.rb index eee80732d2..b21dff6257 100644 --- a/app/mailers/subscription_mailer.rb +++ b/app/mailers/subscription_mailer.rb @@ -6,7 +6,7 @@ class SubscriptionMailer < ActionMailer::Base def notify_node_creation(node) subject = "[PublicLab] " + (node.has_power_tag('question') ? "Question: " : "") + node.title - DrupalTag.subscribers(node.tags).each do |key,val| + Tag.subscribers(node.tags).each do |key,val| @user = val[:user] @node = node @tags = val[:tags] diff --git a/app/models/drupal_node.rb b/app/models/drupal_node.rb index 36e229b9ed..ddfd3a02fe 100644 --- a/app/models/drupal_node.rb +++ b/app/models/drupal_node.rb @@ -69,9 +69,9 @@ def friendly_id_string has_many :drupal_upload, :foreign_key => 'nid', :dependent => :destroy has_many :drupal_files, :through => :drupal_upload has_many :drupal_node_community_tag, :foreign_key => 'nid', :dependent => :destroy - has_many :drupal_tag, :through => :drupal_node_community_tag + has_many :tag, :through => :drupal_node_community_tag # these override the above... have to do it manually: - # has_many :drupal_tag, :through => :drupal_node_tag + # has_many :tag, :through => :drupal_node_tag has_many :comments, :foreign_key => 'nid', :dependent => :destroy has_many :drupal_content_type_map, :foreign_key => 'nid', :dependent => :destroy has_many :drupal_content_field_mappers, :foreign_key => 'nid', :dependent => :destroy @@ -337,21 +337,21 @@ def responded_to(key = 'response') # Nodes that respond to this node with a `response:` power tag; # The key word "response" can be customized, i.e. `replication:` for other uses. def responses(key = 'response') - DrupalTag.find_nodes_by_type([key+":"+self.id.to_s]) + Tag.find_nodes_by_type([key+":"+self.id.to_s]) end # Nodes that respond to this node with a `response:` power tag; # The key word "response" can be customized, i.e. `replication:` for other uses. def response_count(key = 'response') DrupalNode.where(status: 1, type: 'note') - .includes(:drupal_node_revision, :drupal_tag) + .includes(:drupal_node_revision, :tag) .where('term_data.name = ?', "#{key}:#{self.id}") .count end # power tags have "key:value" format, and should be searched with a "key:*" wildcard def has_power_tag(key) - tids = DrupalTag.includes(:drupal_node_community_tag) + tids = Tag.includes(:drupal_node_community_tag) .where("community_tags.nid = ? AND name LIKE ?", self.id, key + ":%") .collect(&:tid) DrupalNodeCommunityTag.where('nid = ? AND tid IN (?)', self.id, tids).length > 0 @@ -359,7 +359,7 @@ def has_power_tag(key) # returns the value for the most recent power tag of form key:value def power_tag(tag) - tids = DrupalTag.includes(:drupal_node_community_tag) + tids = Tag.includes(:drupal_node_community_tag) .where("community_tags.nid = ? AND name LIKE ?", self.id, tag+":%") .collect(&:tid) node_tag = DrupalNodeCommunityTag.where('nid = ? AND tid IN (?)', self.id, tids) @@ -373,7 +373,7 @@ def power_tag(tag) # returns all tagnames for a given power tag def power_tags(tag) - tids = DrupalTag.includes(:drupal_node_community_tag) + tids = Tag.includes(:drupal_node_community_tag) .where("community_tags.nid = ? AND name LIKE ?", self.id, tag+":%") .collect(&:tid) node_tags = DrupalNodeCommunityTag.where('nid = ? AND tid IN (?)', self.id, tids) @@ -386,7 +386,7 @@ def power_tags(tag) # returns all power tag results as whole community_tag objects def power_tag_objects(tag) - tids = DrupalTag.includes(:drupal_node_community_tag) + tids = Tag.includes(:drupal_node_community_tag) .where("community_tags.nid = ? AND name LIKE ?", self.id, tag+":%") .collect(&:tid) DrupalNodeCommunityTag.where('nid = ? AND tid IN (?)', self.id, tids) @@ -394,7 +394,7 @@ def power_tag_objects(tag) # return whole community_tag objects but no powertags or "event" def normal_tags - tids = DrupalTag.includes(:drupal_node_community_tag) + tids = Tag.includes(:drupal_node_community_tag) .where("community_tags.nid = ? AND name LIKE ?", self.id, "%:%") .collect(&:tid) DrupalNodeCommunityTag.where('nid = ? AND tid NOT IN (?)', self.id, tids) @@ -406,26 +406,26 @@ def normal_tags def has_tag(tagname) tags = self.get_matching_tags_without_aliasing(tagname) # search for tags with parent matching this - tags += DrupalTag.includes(:drupal_node_community_tag) + tags += Tag.includes(:drupal_node_community_tag) .where("community_tags.nid = ? AND parent LIKE ?", self.id, tagname) # search for parent tag of this, if exists - #tag = DrupalTag.where(name: tagname).try(:first) + #tag = Tag.where(name: tagname).try(:first) #if tag && tag.parent - # tags += DrupalTag.includes(:drupal_node_community_tag) + # tags += Tag.includes(:drupal_node_community_tag) # .where("community_tags.nid = ? AND name LIKE ?", self.id, tag.parent) #end tids = tags.collect(&:tid).uniq DrupalNodeCommunityTag.where('nid IN (?) AND tid IN (?)', self.id, tids).length > 0 end - # can return multiple DrupalTag records -- we don't yet hard-enforce uniqueness, but should soon - # then, this would just be replaced by DrupalTag.where(name: tagname).first + # can return multiple Tag records -- we don't yet hard-enforce uniqueness, but should soon + # then, this would just be replaced by Tag.where(name: tagname).first def get_matching_tags_without_aliasing(tagname) - tags = DrupalTag.includes(:drupal_node_community_tag) + tags = Tag.includes(:drupal_node_community_tag) .where("community_tags.nid = ? AND name LIKE ?", self.id, tagname) # search for tags which end in wildcards if tagname[-1] == '*' - tags += DrupalTag.includes(:drupal_node_community_tag) + tags += Tag.includes(:drupal_node_community_tag) .where("community_tags.nid = ? AND (name LIKE ? OR name LIKE ?)", self.id, tagname, tagname.gsub('*', '%')) end tags @@ -462,7 +462,7 @@ def icon end def tags - self.drupal_tag + self.tag end def community_tags @@ -695,7 +695,7 @@ def add_tag(tagname,user) tagname = tagname.downcase unless self.has_tag_without_aliasing(tagname) saved = false - tag = DrupalTag.find_by_name(tagname) || DrupalTag.new({ + tag = Tag.find_by_name(tagname) || Tag.new({ vid: 3, # vocabulary id; 1 name: tagname, description: "", @@ -742,7 +742,7 @@ def self.find_wiki(title) def self.research_notes nids = DrupalNode.where(type: 'note') - .joins(:drupal_tag) + .joins(:tag) .where('term_data.name LIKE ?', 'question:%') .group('node.nid') .collect(&:nid) @@ -752,7 +752,7 @@ def self.research_notes def self.questions questions = DrupalNode.where(type: 'note') - .joins(:drupal_tag) + .joins(:tag) .where('term_data.name LIKE ?', 'question:%') .group('node.nid') end @@ -763,13 +763,13 @@ def body_preview def self.activities(tagname) DrupalNode.where(status: 1, type: 'note') - .includes(:drupal_node_revision, :drupal_tag) + .includes(:drupal_node_revision, :tag) .where('term_data.name LIKE ?', "activity:#{tagname}") end def self.upgrades(tagname) DrupalNode.where(status: 1, type: 'note') - .includes(:drupal_node_revision, :drupal_tag) + .includes(:drupal_node_revision, :tag) .where('term_data.name LIKE ?', "upgrade:#{tagname}") end diff --git a/app/models/drupal_node_community_tag.rb b/app/models/drupal_node_community_tag.rb index 01577cdaba..e8190f598f 100644 --- a/app/models/drupal_node_community_tag.rb +++ b/app/models/drupal_node_community_tag.rb @@ -3,9 +3,9 @@ class DrupalNodeCommunityTag < ActiveRecord::Base self.table_name = 'community_tags' self.primary_keys = :tid, :nid belongs_to :drupal_node, :foreign_key => 'nid' - belongs_to :drupal_tag, :foreign_key => 'tid' + belongs_to :tag, :foreign_key => 'tid' belongs_to :drupal_users, :foreign_key => 'uid' - accepts_nested_attributes_for :drupal_tag + accepts_nested_attributes_for :tag after_create :increment_count @@ -20,10 +20,6 @@ def node self.drupal_node end - def tag - self.drupal_tag - end - def author self.user end @@ -37,7 +33,7 @@ def drupal_user end def name - self.drupal_tag.name + self.tag.name end end diff --git a/app/models/drupal_users.rb b/app/models/drupal_users.rb index 65512c3238..69125aed04 100644 --- a/app/models/drupal_users.rb +++ b/app/models/drupal_users.rb @@ -157,7 +157,7 @@ def notes_for_tags(tagnames) end def tags(limit = 10) - DrupalTag.find :all, :conditions => ['name in (?)',self.tagnames], :limit => limit + Tag.find :all, :conditions => ['name in (?)',self.tagnames], :limit => limit end def tagnames(limit = 20,defaults = true) diff --git a/app/models/drupal_tag.rb b/app/models/tag.rb similarity index 85% rename from app/models/drupal_tag.rb rename to app/models/tag.rb index 7bd5513156..12ed40f95c 100644 --- a/app/models/drupal_tag.rb +++ b/app/models/tag.rb @@ -1,4 +1,4 @@ -class DrupalTag < ActiveRecord::Base +class Tag < ActiveRecord::Base attr_accessible :vid, :name, :description, :weight self.table_name = 'term_data' self.primary_key = 'tid' @@ -64,21 +64,21 @@ def self.find_top_nodes_by_type(tagname, type = "wiki", limit = 10) .where('term_data.name = ?', tagname) .order("node_counter.totalcount DESC") .limit(limit) - .include(:drupal_node_counter, :drupal_node_community_tag, :drupal_tag) + .include(:drupal_node_counter, :drupal_node_community_tag, :tag) end # finds recent nodes - should drop "limit" and allow use of chainable .limit() def self.find_nodes_by_type(tagnames, type = "note", limit = 10) nodes = DrupalNode.where(status: 1, type: type) - .includes(:drupal_node_revision, :drupal_tag) + .includes(:drupal_node_revision, :tag) .where('term_data.name IN (?)', tagnames) # .where('term_data.name IN (?) OR term_data.parent in (?)', tagnames, tagnames) # greedily fetch children - tags = DrupalTag.where('term_data.name IN (?)', tagnames) + tags = Tag.where('term_data.name IN (?)', tagnames) parents = DrupalNode.where(status: 1, type: type) - .includes(:drupal_node_revision, :drupal_tag) + .includes(:drupal_node_revision, :tag) .where('term_data.name IN (?)', tags.collect(&:parent)) DrupalNode.where('node.nid IN (?)', (nodes + parents).collect(&:nid)) - .includes(:drupal_node_revision, :drupal_tag) + .includes(:drupal_node_revision, :tag) .order("node_revisions.timestamp DESC") .limit(limit) end @@ -91,14 +91,14 @@ def self.find_pages(tagnames,limit = 10) def self.find_nodes_by_type_with_all_tags(tagnames, type = "note", limit = 10) nids = [] tagnames.each do |tagname| - #tids = DrupalTag.where('term_data.name IN (?) OR term_data.parent IN (?)', tagnames, tagnames) # greedily fetch children - tids = DrupalTag.where('term_data.name IN (?)', tagnames) + #tids = Tag.where('term_data.name IN (?) OR term_data.parent IN (?)', tagnames, tagnames) # greedily fetch children + tids = Tag.where('term_data.name IN (?)', tagnames) .collect(&:tid) tag_nids = DrupalNodeCommunityTag.where("tid IN (?)", tids) .collect(&:nid) - tag = DrupalTag.where(name: tagname).last + tag = Tag.where(name: tagname).last parents = DrupalNode.where(status: 1, type: type) - .includes(:drupal_node_revision, :drupal_tag) + .includes(:drupal_node_revision, :tag) .where('term_data.name LIKE ?', tag.parent) nids += tag_nids + parents.collect(&:nid) end @@ -112,12 +112,12 @@ def self.find_popular_notes(tagname, views = 20, limit = 10) .where('term_data.name = ? AND node_counter.totalcount > (?)', tagname, views) .order("node.nid DESC") .limit(limit) - .include(:drupal_node_counter, :drupal_node_community_tag, :drupal_tag) + .include(:drupal_node_counter, :drupal_node_community_tag, :tag) end def self.exists?(tagname,nid) DrupalNodeCommunityTag.where('nid = ? AND term_data.name = ?', nid, tagname) - .joins(:drupal_tag) + .joins(:tag) .length != 0 end @@ -126,13 +126,13 @@ def self.is_powertag?(tagname) end def self.follower_count(tagname) - TagSelection.joins(:drupal_tag) + TagSelection.joins(:tag) .where('term_data.name = ?', tagname) .count end def self.followers(tagname) - uids = TagSelection.joins(:drupal_tag) + uids = TagSelection.joins(:tag) .where('term_data.name = ?', tagname) .collect(&:user_id) DrupalUsers.where('uid in (?)', uids) @@ -142,12 +142,12 @@ def self.followers(tagname) # optimize this too! def weekly_tallies(type = "note", span = 52) weeks = {} - tids = DrupalTag.where('name IN (?)', [self.name]) + tids = Tag.where('name IN (?)', [self.name]) .collect(&:tid) nids = DrupalNodeCommunityTag.where("tid IN (?)", tids) .collect(&:nid) (1..span).each do |week| - weeks[span - week] = DrupalTag.nodes_for_period( + weeks[span - week] = Tag.nodes_for_period( type, nids, (Time.now.to_i - week.weeks.to_i).to_s, @@ -170,20 +170,20 @@ def self.nodes_for_period(type, nids, start, finish) # Given a set of tags, return all users following # those tags. Return a dictionary of tags indexed by user. - # Accepts array of DrupalTags, outputs array of users as: + # Accepts array of Tags, outputs array of users as: # {user: , tags: []} # Used in subscription_mailer def self.subscribers(tags) tids = tags.collect(&:tid) # include special tid for indiscriminant subscribers who want it all! - all_tag = DrupalTag.find_by_name("everything") + all_tag = Tag.find_by_name("everything") tids += [all_tag.tid,] if all_tag usertags = TagSelection.where("tid IN (?) AND following = ?", tids, true) d = {} usertags.each do |usertag| # For each row of (user,tag), build a user's tag subscriptions if (usertag.tid == all_tag) and (usertag.tag.nil?) - puts "WARNING: all_tag tid " + String(all_tag) + " not found for DrupalTag! Please correct this!" + puts "WARNING: all_tag tid " + String(all_tag) + " not found for Tag! Please correct this!" next end d[usertag.user.name] = {:user => usertag.user} @@ -195,7 +195,7 @@ def self.subscribers(tags) def self.find_research_notes(tagnames, limit = 10) DrupalNode.research_notes.where(status: 1) - .includes(:drupal_node_revision, :drupal_tag) + .includes(:drupal_node_revision, :tag) .where('term_data.name IN (?)', tagnames) .order("node_revisions.timestamp DESC") .limit(limit) diff --git a/app/models/tag_selection.rb b/app/models/tag_selection.rb index aaa4d46215..899c34b83e 100644 --- a/app/models/tag_selection.rb +++ b/app/models/tag_selection.rb @@ -1,23 +1,19 @@ class TagSelection < ActiveRecord::Base attr_accessible :following self.primary_keys = :user_id, :tid - belongs_to :drupal_tag, :foreign_key => :tid + belongs_to :tag, :foreign_key => :tid has_many :drupal_node_community_tags, :foreign_key => :tid validates :user_id, :presence => :true validates :tid, :presence => :true - validates :drupal_tag, :presence => :true + validates :tag, :presence => :true def user DrupalUsers.find_by_uid self.user_id end - def tag - self.drupal_tag - end - def tagname - self.drupal_tag.name + self.tag.name end end diff --git a/app/models/user.rb b/app/models/user.rb index 376fd92769..dd5fb6378c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -125,7 +125,7 @@ def subscriptions(type = :tag) end def following(tagname) - tids = DrupalTag.find(:all, :conditions => {:name => tagname}).collect(&:tid) + tids = Tag.find(:all, :conditions => {:name => tagname}).collect(&:tid) TagSelection.find(:all, :conditions => {:following => true,:tid => tids, :user_id => self.uid}).length > 0 end @@ -210,7 +210,7 @@ def streak(span = 365) end def barnstars - DrupalNodeCommunityTag.includes(:drupal_node,:drupal_tag).where("type = ? AND term_data.name LIKE ? AND node.uid = ?",'note','barnstar:%',self.uid) + DrupalNodeCommunityTag.includes(:drupal_node,:tag).where("type = ? AND term_data.name LIKE ? AND node.uid = ?",'note','barnstar:%',self.uid) end def photo_path(size = :medium) diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 38661d9691..7a425f5097 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -37,7 +37,7 @@ def find_users(input, limit=5) end def find_tags(input, limit=5) - DrupalTag.includes(:drupal_node) + Tag.includes(:drupal_node) .where('node.status = 1') .limit(limit) .where('name LIKE ?', '%' + input + '%') @@ -174,7 +174,7 @@ def textSearch_tags(srchString) unless srchString.nil? || srchString == 0 # Tags sterms = srchString.split(" ") - tlist= DrupalTag.where({ name: sterms }) + tlist= Tag.where({ name: sterms }) .joins(:drupal_node_community_tag) .joins(:drupal_node) .where('node.status = 1') @@ -194,7 +194,7 @@ def textSearch_questions(srchString) 'type = "note" AND node.status = 1 AND title LIKE ?', "%" + srchString + "%" ) - .joins(:drupal_tag) + .joins(:tag) .where('term_data.name LIKE ?', 'question:%') .order('node.nid DESC') .limit(25) diff --git a/app/services/typeahead_service.rb b/app/services/typeahead_service.rb index 3e50ad773c..66a66e8a24 100644 --- a/app/services/typeahead_service.rb +++ b/app/services/typeahead_service.rb @@ -36,7 +36,7 @@ def find_users(input, limit=5) end def find_tags(input, limit=5) - DrupalTag.includes(:drupal_node) + Tag.includes(:drupal_node) .where('node.status = 1') .limit(limit) .where('name LIKE ?', '%' + input + '%') @@ -139,7 +139,7 @@ def textSearch_tags(srchString, limit=5) sresult = TagList.new unless srchString.nil? || srchString == 0 # Tags - tlist= DrupalTag.includes(:drupal_node) + tlist= Tag.includes(:drupal_node) .where('node.status = 1') .limit(limit) .where('name LIKE ?', '%' + srchString + '%') @@ -161,7 +161,7 @@ def textSearch_questions(srchString, limit=5) 'type = "note" AND node.status = 1 AND title LIKE ?', "%" + srchString + "%" ) - .joins(:drupal_tag) + .joins(:tag) .where('term_data.name LIKE ?', 'question:%') .order('node.nid DESC') .limit(limit) diff --git a/app/views/editor/post.html.erb b/app/views/editor/post.html.erb index 9deb888d89..5dc804ad4d 100644 --- a/app/views/editor/post.html.erb +++ b/app/views/editor/post.html.erb @@ -15,8 +15,8 @@

Ask a question