From 949d93fa9886d60298d6345c5d1025011a11d59b Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 5 Jan 2016 11:16:22 -0300 Subject: [PATCH] Fix merge with master --- app/models/article.rb | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index ee05df2..8a1cd38 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -77,6 +77,10 @@ class Article < ActiveRecord::Base belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id' belongs_to :created_by, :class_name => 'Person', :foreign_key => 'created_by_id' + #Article followers relation + has_many :article_followers, :dependent => :destroy + has_many :person_followers, :class_name => 'Person', :through => :article_followers, :source => :person + has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' has_many :article_categorizations, -> { where 'articles_categories.virtual = ?', false } @@ -152,6 +156,8 @@ class Article < ActiveRecord::Base validate :no_self_reference validate :no_cyclical_reference, :if => 'parent_id.present?' + validate :parent_archived? + def no_self_reference errors.add(:parent_id, _('self-reference is not allowed.')) if id && parent_id == id end @@ -486,6 +492,10 @@ class Article < ActiveRecord::Base end end + def archived? + (self.parent && self.parent.archived) || self.archived + end + def self.folder_types ['Folder', 'Blog', 'Forum', 'Gallery'] end @@ -632,13 +642,21 @@ class Article < ActiveRecord::Base end def hit - self.class.connection.execute('update articles set hits = hits + 1 where id = %d' % self.id.to_i) - self.hits += 1 + if !archived? + self.class.connection.execute('update articles set hits = hits + 1 where id = %d' % self.id.to_i) + self.hits += 1 + end end def self.hit(articles) - Article.where(:id => articles.map(&:id)).update_all('hits = hits + 1') - articles.each { |a| a.hits += 1 } + ids = [] + articles.each do |article| + if !article.archived? + ids << article.id + article.hits += 1 + end + end + Article.where(:id => ids).update_all('hits = hits + 1') if !ids.empty? end def can_display_hits? @@ -828,6 +846,14 @@ class Article < ActiveRecord::Base true end + def view_page + "content_viewer/view_page" + end + + def to_liquid + HashWithIndifferentAccess.new :name => name, :abstract => abstract, :body => body, :id => id, :parent_id => parent_id, :author => author + end + private def sanitize_tag_list @@ -844,4 +870,10 @@ class Article < ActiveRecord::Base sanitizer.sanitize(text) end + def parent_archived? + if self.parent_id_changed? && self.parent && self.parent.archived? + errors.add(:parent_folder, N_('is archived!!')) + end + end + end -- libgit2 0.21.2