Commit 949d93fa9886d60298d6345c5d1025011a11d59b
1 parent
9c81f9f2
Exists in
staging
and in
3 other branches
Fix merge with master
Showing
1 changed file
with
36 additions
and
4 deletions
Show diff stats
app/models/article.rb
| ... | ... | @@ -77,6 +77,10 @@ class Article < ActiveRecord::Base |
| 77 | 77 | belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id' |
| 78 | 78 | belongs_to :created_by, :class_name => 'Person', :foreign_key => 'created_by_id' |
| 79 | 79 | |
| 80 | + #Article followers relation | |
| 81 | + has_many :article_followers, :dependent => :destroy | |
| 82 | + has_many :person_followers, :class_name => 'Person', :through => :article_followers, :source => :person | |
| 83 | + | |
| 80 | 84 | has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' |
| 81 | 85 | |
| 82 | 86 | has_many :article_categorizations, -> { where 'articles_categories.virtual = ?', false } |
| ... | ... | @@ -152,6 +156,8 @@ class Article < ActiveRecord::Base |
| 152 | 156 | validate :no_self_reference |
| 153 | 157 | validate :no_cyclical_reference, :if => 'parent_id.present?' |
| 154 | 158 | |
| 159 | + validate :parent_archived? | |
| 160 | + | |
| 155 | 161 | def no_self_reference |
| 156 | 162 | errors.add(:parent_id, _('self-reference is not allowed.')) if id && parent_id == id |
| 157 | 163 | end |
| ... | ... | @@ -486,6 +492,10 @@ class Article < ActiveRecord::Base |
| 486 | 492 | end |
| 487 | 493 | end |
| 488 | 494 | |
| 495 | + def archived? | |
| 496 | + (self.parent && self.parent.archived) || self.archived | |
| 497 | + end | |
| 498 | + | |
| 489 | 499 | def self.folder_types |
| 490 | 500 | ['Folder', 'Blog', 'Forum', 'Gallery'] |
| 491 | 501 | end |
| ... | ... | @@ -632,13 +642,21 @@ class Article < ActiveRecord::Base |
| 632 | 642 | end |
| 633 | 643 | |
| 634 | 644 | def hit |
| 635 | - self.class.connection.execute('update articles set hits = hits + 1 where id = %d' % self.id.to_i) | |
| 636 | - self.hits += 1 | |
| 645 | + if !archived? | |
| 646 | + self.class.connection.execute('update articles set hits = hits + 1 where id = %d' % self.id.to_i) | |
| 647 | + self.hits += 1 | |
| 648 | + end | |
| 637 | 649 | end |
| 638 | 650 | |
| 639 | 651 | def self.hit(articles) |
| 640 | - Article.where(:id => articles.map(&:id)).update_all('hits = hits + 1') | |
| 641 | - articles.each { |a| a.hits += 1 } | |
| 652 | + ids = [] | |
| 653 | + articles.each do |article| | |
| 654 | + if !article.archived? | |
| 655 | + ids << article.id | |
| 656 | + article.hits += 1 | |
| 657 | + end | |
| 658 | + end | |
| 659 | + Article.where(:id => ids).update_all('hits = hits + 1') if !ids.empty? | |
| 642 | 660 | end |
| 643 | 661 | |
| 644 | 662 | def can_display_hits? |
| ... | ... | @@ -828,6 +846,14 @@ class Article < ActiveRecord::Base |
| 828 | 846 | true |
| 829 | 847 | end |
| 830 | 848 | |
| 849 | + def view_page | |
| 850 | + "content_viewer/view_page" | |
| 851 | + end | |
| 852 | + | |
| 853 | + def to_liquid | |
| 854 | + HashWithIndifferentAccess.new :name => name, :abstract => abstract, :body => body, :id => id, :parent_id => parent_id, :author => author | |
| 855 | + end | |
| 856 | + | |
| 831 | 857 | private |
| 832 | 858 | |
| 833 | 859 | def sanitize_tag_list |
| ... | ... | @@ -844,4 +870,10 @@ class Article < ActiveRecord::Base |
| 844 | 870 | sanitizer.sanitize(text) |
| 845 | 871 | end |
| 846 | 872 | |
| 873 | + def parent_archived? | |
| 874 | + if self.parent_id_changed? && self.parent && self.parent.archived? | |
| 875 | + errors.add(:parent_folder, N_('is archived!!')) | |
| 876 | + end | |
| 877 | + end | |
| 878 | + | |
| 847 | 879 | end | ... | ... |