Skip to content

DrupalNodeRevision => Revision model renam #1496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jQuery(document).ready(function() {
$('.side-dropzone').css('background','#fcc')
alert_notice('Click <b>Publish</b> again to publish without a main image, but it is recommended that you add one.', {'scroll': true})
} else {
$('#new_drupal_node_revision#new_drupal_node_revision,#edit_drupal_node_revision').submit()
$('#new_revision#new_revision,#edit_revision').submit()
}
}
$(".publish").bind("click",publish)
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def spam

def spam_revisions
if current_user && (current_user.role == 'moderator' || current_user.role == 'admin')
@revisions = DrupalNodeRevision.paginate(page: params[:page])
.order('timestamp DESC')
.where(status: 0)
@revisions = Revision.paginate(page: params[:page])
.order('timestamp DESC')
.where(status: 0)
render template: 'admin/spam'
else
flash[:error] = 'Only moderators can moderate revisions.'
Expand Down Expand Up @@ -140,7 +140,7 @@ def publish
end

def mark_spam_revision
@revision = DrupalNodeRevision.find_by_vid params[:vid]
@revision = Revision.find_by_vid params[:vid]
if current_user && (current_user.role == 'moderator' || current_user.role == 'admin')
if @revision.status == 1
@revision.spam
Expand All @@ -163,7 +163,7 @@ def mark_spam_revision

def publish_revision
if current_user && (current_user.role == 'moderator' || current_user.role == 'admin')
@revision = DrupalNodeRevision.find params[:vid]
@revision = Revision.find params[:vid]
@revision.publish
@revision.author.unban
flash[:notice] = 'Item published.'
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def set_sidebar(type = :generic, data = :all, args = {})
.collect(&:nid)
@notes = if params[:controller] == 'questions'
Node.questions
.joins(:drupal_node_revision)
.joins(:revision)
else
Node.research_notes
.joins(:drupal_node_revision)
.joins(:revision)
.order('node.nid DESC')
.paginate(page: params[:page])
end
Expand All @@ -52,7 +52,7 @@ def set_sidebar(type = :generic, data = :all, args = {})
end

@wikis = Node.order('changed DESC')
.joins(:drupal_node_revision)
.joins(:revision)
.where('node_revisions.status = 1 AND node.status = 1 AND type = "page"')
.limit(10)
.group('node_revisions.nid')
Expand Down
22 changes: 11 additions & 11 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def dashboard
@note_count = Node.select(%i[created type status])
.where(type: 'note', status: 1, created: Time.now.to_i - 1.weeks.to_i..Time.now.to_i)
.count
@wiki_count = DrupalNodeRevision.select(:timestamp)
.where(timestamp: Time.now.to_i - 1.weeks.to_i..Time.now.to_i)
.count
@wiki_count = Revision.select(:timestamp)
.where(timestamp: Time.now.to_i - 1.weeks.to_i..Time.now.to_i)
.count
@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 = Node.joins(:node_tag)
Expand All @@ -73,14 +73,14 @@ def dashboard
@wikis = Node.where(type: 'page', status: 1)
.order('nid DESC')
.limit(10)
revisions = DrupalNodeRevision.joins(:node)
.order('timestamp DESC')
.where('type = (?)', 'page')
.where('node.status = 1')
.where('node_revisions.status = 1')
.where('timestamp - node.created > ?', 300) # don't report edits within 5 mins of page creation
.limit(10)
.group('node.title')
revisions = Revision.joins(:node)
.order('timestamp DESC')
.where('type = (?)', 'page')
.where('node.status = 1')
.where('node_revisions.status = 1')
.where('timestamp - node.created > ?', 300) # don't report edits within 5 mins of page creation
.limit(10)
.group('node.title')
# group by day: http://stackoverflow.com/questions/5970938/group-by-day-from-timestamp
revisions = revisions.group('DATE(FROM_UNIXTIME(timestamp))') if Rails.env == 'production'
@wikis += revisions
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def tools
def places
@title = 'Places'
@notes = Node.where(status: 1, type: %w[page place])
.includes(:drupal_node_revision, :tag)
.includes(:revision, :tag)
.where('term_data.name = ?', 'chapter')
.page(params[:page])
.order('node_revisions.timestamp DESC')
Expand Down
24 changes: 12 additions & 12 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def range
@notes = Node.select(%i[created type status])
.where(type: 'note', status: 1, created: @[email protected]_i)
.count
@wikis = DrupalNodeRevision.select(:timestamp)
.where(timestamp: @[email protected]_i)
.count - @notes # because notes each have one revision
@wikis = Revision.select(:timestamp)
.where(timestamp: @[email protected]_i)
.count - @notes # because notes each have one revision
@people = User.where(created_at: @start..@end)
.joins('INNER JOIN users ON users.uid = rusers.id')
.where('users.status = 1')
Expand All @@ -33,19 +33,19 @@ def index
@weekly_notes = Node.select(%i[created type status])
.where(type: 'note', status: 1, created: @time.to_i - [email protected]_i)
.count
@weekly_wikis = DrupalNodeRevision.select(:timestamp)
.where(timestamp: @time.to_i - [email protected]_i)
.count
@weekly_wikis = Revision.select(:timestamp)
.where(timestamp: @time.to_i - [email protected]_i)
.count
@weekly_members = User.where(created_at: @time - 1.weeks..@time)
.joins('INNER JOIN users ON users.uid = rusers.id')
.where('users.status = 1')
.count
@monthly_notes = Node.select(%i[created type status])
.where(type: 'note', status: 1, created: @time.to_i - [email protected]_i)
.count
@monthly_wikis = DrupalNodeRevision.select(:timestamp)
.where(timestamp: @time.to_i - [email protected]_i)
.count
@monthly_wikis = Revision.select(:timestamp)
.where(timestamp: @time.to_i - [email protected]_i)
.count
@monthly_members = User.where(created_at: @time - 1.months..@time)
.joins('INNER JOIN users ON users.uid = rusers.id')
.where('users.status = 1')
Expand All @@ -54,9 +54,9 @@ def index
@notes_per_week_past_year = Node.select(%i[created type status])
.where(type: 'note', status: 1, created: @time.to_i - [email protected]_i)
.count / 52.0
@edits_per_week_past_year = DrupalNodeRevision.select(:timestamp)
.where(timestamp: @time.to_i - [email protected]_i)
.count / 52.0
@edits_per_week_past_year = Revision.select(:timestamp)
.where(timestamp: @time.to_i - [email protected]_i)
.count / 52.0

@graph_notes = Node.weekly_tallies('note', 52, @time).to_a.sort.to_json
@graph_wikis = Node.weekly_tallies('page', 52, @time).to_a.sort.to_json
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ def show
@wildcard = true
@tags = Tag.where('name LIKE (?)', params[:id][0..-2] + '%')
nodes = Node.where(status: 1, type: node_type)
.includes(:drupal_node_revision, :tag)
.includes(: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 = Tag.find_all_by_name params[:id]
nodes = Node.where(status: 1, type: node_type)
.includes(:drupal_node_revision, :tag)
.includes(:revision, :tag)
.where('term_data.name = ? OR term_data.parent = ?', params[:id], params[:id])
.page(params[:page])
.order('node_revisions.timestamp DESC')
Expand Down Expand Up @@ -198,7 +198,7 @@ def suggested
def rss
if params[:tagname][-1..-1] == '*'
@notes = Node.where(status: 1, type: 'note')
.includes(:drupal_node_revision, :tag)
.includes(:revision, :tag)
.where('term_data.name LIKE (?)', params[:tagname][0..-2] + '%')
.limit(20)
.order('node_revisions.timestamp DESC')
Expand All @@ -224,7 +224,7 @@ def contributors
@tagnames = [params[:id]]
@tag = Tag.find_by_name params[:id]
@notes = Node.where(status: 1, type: 'note')
.includes(:drupal_node_revision, :tag)
.includes(:revision, :tag)
.where('term_data.name = ?', params[:id])
.order('node_revisions.timestamp DESC')
@users = @notes.collect(&:author).uniq
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ def profile
.where(status: 1)
.order('node.nid DESC')
@answered_questions = questions.select{|q| q.answers.collect(&:author).include?(@user)}
wikis = DrupalNodeRevision.order("nid DESC")
.where('node.type' => 'page', 'node.status' => 1, uid: @user.uid)
.joins(:node)
.limit(20)
wikis = Revision.order("nid DESC")
.where('node.type' => 'page', 'node.status' => 1, uid: @user.uid)
.joins(:node)
.limit(20)
@wikis = wikis.collect(&:parent).uniq
if @user.status == 0
if current_user && (current_user.role == "admin" || current_user.role == "moderator")
Expand Down
22 changes: 11 additions & 11 deletions app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def show
# display a revision, raw
def raw
response.headers['Content-Type'] = 'text/plain; charset=utf-8'
render text: DrupalNodeRevision.find(params[:id]).body
render text: Revision.find(params[:id]).body
end

def edit
Expand Down Expand Up @@ -121,7 +121,7 @@ def new
@related = Node.limit(10)
.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)
.includes(:revision)
tag = Tag.find_by_name(params[:id]) # add page name as a tag, too
@tags << tag if tag
@related += Tag.find_nodes_by_type(@tags.collect(&:name), 'page', 10)
Expand Down Expand Up @@ -213,7 +213,7 @@ def delete
end

def revert
revision = DrupalNodeRevision.find params[:id]
revision = Revision.find params[:id]
node = revision.parent
if current_user && (current_user.role == 'moderator' || current_user.role == 'admin')
new_rev = revision.dup
Expand Down Expand Up @@ -263,7 +263,7 @@ def revision
@unpaginated = true
@is_revision = true
set_sidebar :tags, @tagnames, videos: true
@revision = DrupalNodeRevision.find_by_nid_and_vid(@node.id, params[:vid])
@revision = Revision.find_by_nid_and_vid(@node.id, params[:vid])
if @revision.nil?
flash[:error] = I18n.t('wiki_controller.revision_not_found')
redirect_to action: 'revisions'
Expand All @@ -277,8 +277,8 @@ def revision
end

def diff
@a = DrupalNodeRevision.find_by_vid(params[:a])
@b = DrupalNodeRevision.find_by_vid(params[:b])
@a = Revision.find_by_vid(params[:a])
@b = Revision.find_by_vid(params[:b])
if @a.body == @b.body
render text: I18n.t('wiki_controller.lead_image_or_title_change').html_safe
else
Expand All @@ -295,7 +295,7 @@ def index
'node_revisions.timestamp DESC'
end

@wikis = Node.includes(:drupal_node_revision)
@wikis = Node.includes(:revision)
.group('node_revisions.nid')
.order(order_string)
.where("node_revisions.status = 1 AND node.status = 1 AND (type = 'page' OR type = 'tool' OR type = 'place')")
Expand All @@ -308,7 +308,7 @@ def popular
@title = I18n.t('wiki_controller.popular_wiki_pages')
@wikis = Node.limit(40)
.order('views DESC')
.joins(:drupal_node_revision)
.joins(:revision)
.group('node_revisions.nid')
.order('node_revisions.timestamp DESC')
.where("node.status = 1 AND node_revisions.status = 1 AND node.nid != 259 AND (type = 'page' OR type = 'tool' OR type = 'place')")
Expand Down Expand Up @@ -349,7 +349,7 @@ def techniques
def methods
@nodes = Node.where(status: 1, type: ['page'])
.where('term_data.name = ?', 'tool')
.includes(:drupal_node_revision, :tag)
.includes(:revision, :tag)
.order('node_revisions.timestamp DESC')
# deprecating the following in favor of javascript implementation in /app/assets/javascripts/methods.js
if params[:topic]
Expand All @@ -361,7 +361,7 @@ def methods
'%' + params[:topic] + '%',
'%' + params[:topic] + '%',
params[:topic])
.includes(:drupal_node_revision, :tag)
.includes(:revision, :tag)
.order('node_revisions.timestamp DESC')
end
if params[:topic]
Expand All @@ -373,7 +373,7 @@ def methods
'%' + params[:topic] + '%',
'%' + params[:topic] + '%',
params[:topic])
.includes(:drupal_node_revision, :tag)
.includes(:revision, :tag)
.order('node_revisions.timestamp DESC')
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/node_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.notes_grid(body, _page = 1)
body.gsub(/[^\>`](\<p\>)?\[notes\:(\S+)\]/) do |_tagname|
tagname = Regexp.last_match(2).parameterize
nodes = Node.where(status: 1, type: 'note')
.includes(:drupal_node_revision, :tag)
.includes(:revision, :tag)
.where('term_data.name = ?', tagname)
.order('node_revisions.timestamp DESC')
output = ''
Expand All @@ -38,7 +38,7 @@ def self.questions_grid(body, _page = 1)
body.gsub(/[^\>`](\<p\>)?\[questions\:(\S+)\]/) do |_tagname|
tagname = Regexp.last_match(2).parameterize
nodes = Node.where(status: 1, type: 'note')
.includes(:drupal_node_revision, :tag)
.includes(:revision, :tag)
.where('term_data.name = ?', "question:#{tagname}")
.order('node_revisions.timestamp DESC')
output = ''
Expand Down
2 changes: 1 addition & 1 deletion app/models/drupal_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def note_count
end

def node_count
Node.count(:all, conditions: { status: 1, uid: uid }) + DrupalNodeRevision.count(:all, conditions: { uid: uid })
Node.count(:all, conditions: { status: 1, uid: uid }) + Revision.count(:all, conditions: { uid: uid })
end

# accepts array of tag names (strings)
Expand Down
Loading