app/models/content.rb in typo-5.4 vs app/models/content.rb in typo-5.4.1
- old
+ new
@@ -6,10 +6,11 @@
has_many :notifications, :foreign_key => 'content_id'
has_many :notify_users, :through => :notifications,
:source => 'notify_user',
:uniq => true
+
def notify_users=(collection)
return notify_users.clear if collection.empty?
self.class.transaction do
self.notifications.clear
collection.uniq.each do |u|
@@ -44,10 +45,13 @@
named_scope :searchstring, lambda {|search_string|
tokens = search_string.split(' ').collect {|c| "%#{c.downcase}%"}
{:conditions => ['state = ? AND ' + (['(LOWER(body) LIKE ? OR LOWER(extended) LIKE ? OR LOWER(title) LIKE ?)']*tokens.size).join(' AND '),
"published", *tokens.collect{ |token| [token] * 3 }.flatten]}
}
+ named_scope :already_published, lambda { {:conditions => ['published = ? AND published_at < ?', true, Time.now],
+ :order => default_order,
+ }}
serialize :whiteboard
attr_accessor :just_changed_published_status
alias_method :just_changed_published_status?, :just_changed_published_status
@@ -120,41 +124,41 @@
at ||= options.delete(:at) || Time.now
with_scope(:find => { :conditions => ['published_at < ?', at]}) do
find_published(what, options)
end
end
-
+
def find_by_published_at(column_name = :published_at)
from_where = "FROM #{self.table_name} WHERE #{column_name} is not NULL AND type='#{self.name}'"
# Implement adapter-specific groupings below, or allow us to fall through to the generic ruby-side grouping
-
+
if defined?(ActiveRecord::ConnectionAdapters::MysqlAdapter) && self.connection.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter)
# MySQL uses date_format
find_by_sql("SELECT date_format(#{column_name}, '%Y-%m') AS publication #{from_where} GROUP BY publication ORDER BY publication DESC")
-
+
elsif defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && self.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
# PostgreSQL uses to_char
find_by_sql("SELECT to_char(#{column_name}, 'YYYY-MM') AS publication #{from_where} GROUP BY publication ORDER BY publication DESC")
-
+
else
# If we don't have an adapter-safe conversion from date -> YYYY-MM,
# we'll do the GROUP BY server-side. There won't be very many objects
# in this array anyway.
date_map = {}
dates = find_by_sql("SELECT #{column_name} AS publication #{from_where}")
-
+
dates.map! do |d|
d.publication = Time.parse(d.publication).strftime('%Y-%m')
d.freeze
if !date_map.has_key?(d.publication)
date_map[d.publication] = true
d
end
end
dates.reject!{|d| d.blank? || d.publication.blank?}
dates.sort!{|a,b| b.publication <=> a.publication}
-
+
dates
end
end
def function_search_no_draft(search_hash)