Module | Cms::Behaviors::Publishing::InstanceMethods |
In: |
lib/cms/behaviors/publishing.rb
|
# File lib/cms/behaviors/publishing.rb, line 116 116: def live? 117: self.class.versioned? ? live_version.version == draft.version && published? : true 118: end
# File lib/cms/behaviors/publishing.rb, line 60 60: def publish 61: publish! 62: true 63: rescue Exception => e 64: logger.warn("Could not publish, #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}") 65: false 66: end
# File lib/cms/behaviors/publishing.rb, line 68 68: def publish! 69: if new_record? 70: self.publish_on_save = true 71: save! 72: else 73: transaction do 74: if self.class.versioned? 75: d = draft 76: 77: # We only need to publish if this isn't already published 78: # or the draft version is greater than the live version 79: if !self.published? || d.version > self.version 80: 81: d.update_attributes(:published => true) 82: 83: # copy values from the draft to the main record 84: quoted_attributes = d.send(:attributes_with_quotes, false, false, self.class.versioned_columns) 85: 86: # Doing the SQL ourselves to avoid callbacks 87: connection.update( 88: "UPDATE #{self.class.quoted_table_name} " + 89: "SET #{quoted_comma_pair_list(connection, quoted_attributes)} " + 90: "WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quote_value(id)}", 91: "#{self.class.name} Publish" 92: ) 93: end 94: else 95: connection.update( 96: "UPDATE #{self.class.quoted_table_name} " + 97: "SET published = #{connection.quote(true, self.class.columns_hash["published"])} " + 98: "WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quote_value(id)}", 99: "#{self.class.name} Publish" 100: ) 101: end 102: after_publish if respond_to?(:after_publish) 103: end 104: self.published = true 105: end 106: end
# File lib/cms/behaviors/publishing.rb, line 51 51: def publish_for_non_versioned 52: unless self.class.versioned? 53: if @publish_on_save 54: publish 55: @publish_on_save = nil 56: end 57: end 58: end
# File lib/cms/behaviors/publishing.rb, line 43 43: def publishable? 44: if self.class.connectable? 45: new_record? ? connect_to_page_id.blank? : connected_page_count < 1 46: else 47: true 48: end 49: end
# File lib/cms/behaviors/publishing.rb, line 108 108: def status 109: live? ? :published : :draft 110: end