diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-06-23 18:04:37 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-06-23 18:04:37 +0200 |
| commit | 6424e10be5a89f175a74c71c55660412a169b8b8 (patch) | |
| tree | ae8c8111bd1e8c6e82c0a5f9a2c4b088c92bafe5 /app/models | |
| parent | 375ed745052148faeb34763087fe04214105f1b8 (diff) | |
Update deployed state to what's currently running
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/node.rb | 29 | ||||
| -rw-r--r-- | app/models/page.rb | 15 |
2 files changed, 38 insertions, 6 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index 6c11fed..75122d1 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -3,11 +3,11 @@ class Node < ActiveRecord::Base | |||
| 3 | acts_as_nested_set | 3 | acts_as_nested_set |
| 4 | 4 | ||
| 5 | # Associations | 5 | # Associations |
| 6 | has_many :pages, :order => "revision ASC" | 6 | has_many :pages, :order => "revision ASC", :dependent => :destroy |
| 7 | belongs_to :head, :class_name => "Page", :foreign_key => :head_id | 7 | belongs_to :head, :class_name => "Page", :foreign_key => :head_id, :dependent => :destroy |
| 8 | belongs_to :draft, :class_name => "Page", :foreign_key => :draft_id | 8 | belongs_to :draft, :class_name => "Page", :foreign_key => :draft_id, :dependent => :destroy |
| 9 | has_many :permissions | 9 | has_many :permissions, :dependent => :destroy |
| 10 | has_one :event | 10 | has_one :event, :dependent => :destroy |
| 11 | belongs_to :lock_owner, :class_name => "User", :foreign_key => :locking_user_id | 11 | belongs_to :lock_owner, :class_name => "User", :foreign_key => :locking_user_id |
| 12 | 12 | ||
| 13 | # Callbacks | 13 | # Callbacks |
| @@ -60,6 +60,7 @@ class Node < ActiveRecord::Base | |||
| 60 | # Instance Methods | 60 | # Instance Methods |
| 61 | 61 | ||
| 62 | def find_or_create_draft current_user | 62 | def find_or_create_draft current_user |
| 63 | self.wipe_draft! | ||
| 63 | if draft && self.lock_owner == current_user | 64 | if draft && self.lock_owner == current_user |
| 64 | draft | 65 | draft |
| 65 | elsif draft && self.lock_owner.nil? | 66 | elsif draft && self.lock_owner.nil? |
| @@ -115,6 +116,24 @@ class Node < ActiveRecord::Base | |||
| 115 | end | 116 | end |
| 116 | end | 117 | end |
| 117 | 118 | ||
| 119 | # removes a draft and the lock if it is older than a day and still | ||
| 120 | # identical to head | ||
| 121 | def wipe_draft! | ||
| 122 | unless self.draft | ||
| 123 | self.unlock! | ||
| 124 | return | ||
| 125 | end | ||
| 126 | return unless self.head | ||
| 127 | return unless self.draft.updated_at < 1.day.ago | ||
| 128 | return if Page.find(self.head).has_changes_to? self.draft | ||
| 129 | |||
| 130 | self.draft.destroy | ||
| 131 | self.draft_id = nil | ||
| 132 | self.unlock! | ||
| 133 | self.save! | ||
| 134 | self.reload | ||
| 135 | end | ||
| 136 | |||
| 118 | def restore_revision! revision | 137 | def restore_revision! revision |
| 119 | if page = self.pages.find_by_revision(revision) | 138 | if page = self.pages.find_by_revision(revision) |
| 120 | self.head = page | 139 | self.head = page |
diff --git a/app/models/page.rb b/app/models/page.rb index 0cfad53..f804353 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -64,7 +64,7 @@ class Page < ActiveRecord::Base | |||
| 64 | 64 | ||
| 65 | Page.heads.paginate( | 65 | Page.heads.paginate( |
| 66 | find_options_for_find_tagged_with( | 66 | find_options_for_find_tagged_with( |
| 67 | options[:tags].gsub(/\s/, ","), :match_all => true | 67 | options[:tags].gsub(/\s/, ","), :match_all => true, :conditions => options[:conditions] |
| 68 | ).merge( | 68 | ).merge( |
| 69 | :page => page, | 69 | :page => page, |
| 70 | :per_page => options[:limit], | 70 | :per_page => options[:limit], |
| @@ -94,6 +94,19 @@ class Page < ActiveRecord::Base | |||
| 94 | end | 94 | end |
| 95 | end | 95 | end |
| 96 | 96 | ||
| 97 | # Is used to compare a node's head with the node's draft | ||
| 98 | |||
| 99 | def has_changes_to? draft | ||
| 100 | return true unless node == draft.node | ||
| 101 | return true unless assets == draft.assets | ||
| 102 | return true unless tag_list == draft.tag_list | ||
| 103 | return true unless template_name == draft.template_name | ||
| 104 | return true unless translated_locales.sort_by(&:to_s) == draft.translated_locales.sort_by(&:to_s) | ||
| 105 | changed = false | ||
| 106 | translated_locales.each { |locale| I18n.with_locale(locale) { changed = true unless title == draft.title && abstract == draft.abstract && body == draft.body } } | ||
| 107 | return changed | ||
| 108 | end | ||
| 109 | |||
| 97 | # Instance Methods | 110 | # Instance Methods |
| 98 | 111 | ||
| 99 | def public_template_path | 112 | def public_template_path |
