Permalink
Browse files

Changed bools to true/false for sqlite compatibility (TODO: add tests…

… about this..)
  • Loading branch information...
jbbarth committed Feb 1, 2009
1 parent 5499499 commit 7e668187ecb070e2fef063d5d894ea1fcde3a4c1
Showing with 20 additions and 20 deletions.
  1. +2 −2 app/controllers/admin/authors_controller.rb
  2. +2 −2 app/models/author.rb
  3. +2 −2 app/models/comment.rb
  4. +14 −14 app/models/post.rb
@@ -81,7 +81,7 @@ def author_edit
def author_update
# find our author
@author = Author.find(params[:id])
- if (Author.find(:all, :conditions => ['is_active = ? and id != ?', 1, params[:id]]).length < 1) and params[:author][:is_active] == '0'
+ if (Author.find(:all, :conditions => ['is_active = ? and id != ?', true, params[:id]]).length < 1) and params[:author][:is_active] == '0'
# trying to set this author to inactive, but it would lock them out of the admin section--don't do it
flash[:notice] = '<span class="red"><b>Failed:</b> Setting that author to inactive would lock you out!</span>'
redirect_to Site.full_url + '/admin/authors'
@@ -103,7 +103,7 @@ def author_update
# destroy an existing author! destroy! destroy! destory!
# check to make sure they're not going to lock themselves out first...
def author_destroy
- if (Author.count < 2) or (Author.find(:all, :conditions => ['is_active = ? and id != ?', 1, params[:id]]).length < 1)
+ if (Author.count < 2) or (Author.find(:all, :conditions => ['is_active = ? and id != ?', true, params[:id]]).length < 1)
flash[:notice] = '<b>Failed:</b> Destroying that author would lock you out!'
if session[:came_from]
# they came from somewhere, let's send them back there
View
@@ -82,13 +82,13 @@ def self.get_all
# get all active authors sorted by name
def self.get_all_active
- self.find(:all, :conditions => ['is_active = ?', 1], :order => 'name asc')
+ self.find(:all, :conditions => ['is_active = ?', true], :order => 'name asc')
end
# authorize a author for access to the admin section and xmlrpc access
def self.authorize(email, pass, do_hash = false, return_id = false)
pass = (do_hash ? self.do_password_hash(pass) : pass)
- @author = Author.find(:first, :conditions => ['email = ? and hashed_pass = ? and is_active = ?', email, pass, 1])
+ @author = Author.find(:first, :conditions => ['email = ? and hashed_pass = ? and is_active = ?', email, pass, true])
return (return_id ? @author : (@author ? true : false))
end
View
@@ -139,7 +139,7 @@ def before_create
# get a list of comments for the feed
def self.find_for_feed
- self.find(:all, :conditions => ['is_approved = ?', 1], :order => 'created_at desc', :limit => 20)
+ self.find(:all, :conditions => ['is_approved = ?', true], :order => 'created_at desc', :limit => 20)
end
# find all comments in the db that contain string
@@ -158,7 +158,7 @@ def self.find_by_string(str, limit = Preference.get_setting('SEARCH_RESULTS'))
# find only unapproved comments
def self.find_unapproved
- self.find(:all, :conditions => ['is_approved = ?', 0])
+ self.find(:all, :conditions => ['is_approved = ?', false])
end
end
View
@@ -32,7 +32,7 @@ class Post < ActiveRecord::Base
# associations
belongs_to :author
- has_many :comments, :conditions => ['is_approved = ?', 1], :dependent => :destroy
+ has_many :comments, :conditions => ['is_approved = ?', true], :dependent => :destroy
# validations
validates_presence_of :author_id, :title, :body_raw
@@ -283,54 +283,54 @@ def before_update
# get a list of posts for the index page, based on active, current posts (configure how many in preferences)
def self.find_current
- self.find(:all, :conditions => ['is_active = ? and created_at <= ?', 1, Time.sl_local], :order => 'created_at desc', :limit => Preference.get_setting('ITEMS_ON_INDEX').to_i)
+ self.find(:all, :conditions => ['is_active = ? and created_at <= ?', true, Time.sl_local], :order => 'created_at desc', :limit => Preference.get_setting('ITEMS_ON_INDEX').to_i)
end
# get a list of all posts for the archives page
def self.find_all_posts(only_active = true)
if only_active
- self.find(:all, :conditions => ['is_active = ? and created_at <= ?', 1, Time.sl_local], :order => 'created_at desc')
+ self.find(:all, :conditions => ['is_active = ? and created_at <= ?', true, Time.sl_local], :order => 'created_at desc')
else
self.find(:all, :order => 'created_at desc')
end
end
# get a list of posts for the feed
def self.find_for_feed
- self.find(:all, :conditions => ['is_active = ? and created_at <= ?', 1, Time.sl_local], :order => 'created_at desc', :limit => Preference.get_setting('ITEMS_IN_FEED').to_i)
+ self.find(:all, :conditions => ['is_active = ? and created_at <= ?', true, Time.sl_local], :order => 'created_at desc', :limit => Preference.get_setting('ITEMS_IN_FEED').to_i)
end
# get a list of posts written in a certain year
def self.find_by_year(y)
first_year = Time.parse("01/01/#{y}").strftime('%Y-%m-%d %H:%M:%S')
last_year = Time.parse((Date.parse("01/01/#{y}")>>12).to_s).strftime('%Y-%m-%d %H:%M:%S')
- self.find(:all, :conditions => ['is_active = ? and (created_at >= ? and created_at < ?) and created_at <= ?', 1, first_year, last_year, Time.sl_local], :order => 'created_at desc')
+ self.find(:all, :conditions => ['is_active = ? and (created_at >= ? and created_at < ?) and created_at <= ?', true, first_year, last_year, Time.sl_local], :order => 'created_at desc')
end
# get a list of posts written in a certain month
def self.find_by_month(m, y)
first_month = Time.parse("#{m}/01/#{y}").strftime('%Y-%m-%d %H:%M:%S')
last_month = Time.parse((Date.parse("#{m}/01/#{y}")>>1).to_s).strftime('%Y-%m-%d %H:%M:%S')
- self.find(:all, :conditions => ['is_active = ? and (created_at >= ? and created_at < ?) and created_at <= ?', 1, first_month, last_month, Time.sl_local], :order => 'created_at desc')
+ self.find(:all, :conditions => ['is_active = ? and (created_at >= ? and created_at < ?) and created_at <= ?', true, first_month, last_month, Time.sl_local], :order => 'created_at desc')
end
# get a list of posts written on a certain day
def self.find_by_day(d, m, y)
first_day = Time.parse("#{m}/#{d}/#{y}").strftime('%Y-%m-%d %H:%M:%S')
last_day = Time.parse((Date.parse("#{m}/#{d}/#{y}")+1).to_s).strftime('%Y-%m-%d %H:%M:%S')
- self.find(:all, :conditions => ['is_active = ? and (created_at >= ? and created_at < ?) and created_at <= ?', 1, first_day, last_day, Time.sl_local], :order => 'created_at desc')
+ self.find(:all, :conditions => ['is_active = ? and (created_at >= ? and created_at < ?) and created_at <= ?', true, first_day, last_day, Time.sl_local], :order => 'created_at desc')
end
# get a list of posts written by `author`
def self.find_by_author(author)
- self.find(:all, :conditions => ['is_active = ? and author_id = ? and created_at <= ?', 1, author, Time.sl_local], :order => 'created_at desc')
+ self.find(:all, :conditions => ['is_active = ? and author_id = ? and created_at <= ?', true, author, Time.sl_local], :order => 'created_at desc')
end
# get a list of posts tagged with `tag`
def self.find_by_tag(tag, only_active = true)
tag = tag.gsub("'", "''") # protect against quotes
#if only_active
- # self.find_tagged_with(:all => tag, :conditions => ['is_active = ? and created_at <= ?', 1, Time.sl_local], :order => 'created_at desc')
+ # self.find_tagged_with(:all => tag, :conditions => ['is_active = ? and created_at <= ?', true, Time.sl_local], :order => 'created_at desc')
#else
# self.find_tagged_with(:all => tag, :order => 'created_at desc')
#end
@@ -340,30 +340,30 @@ def self.find_by_tag(tag, only_active = true)
# get a single post based on permalink
def self.find_individual(permalink)
- self.find(:all, :conditions => ['is_active = ? and permalink = ? and created_at <= ?', 1, permalink, Time.sl_local])
+ self.find(:all, :conditions => ['is_active = ? and permalink = ? and created_at <= ?', true, permalink, Time.sl_local])
end
# find the previous active post
def self.find_previous(post)
- self.find(:all, :conditions => ['is_active = ? and created_at < ? and created_at <= ?', 1, post.created_at.strftime('%Y-%m-%d %H:%M:%S'), Time.sl_local], :order => 'created_at desc', :limit => 1)
+ self.find(:all, :conditions => ['is_active = ? and created_at < ? and created_at <= ?', true, post.created_at.strftime('%Y-%m-%d %H:%M:%S'), Time.sl_local], :order => 'created_at desc', :limit => 1)
end
# find the next active post
def self.find_next(post)
- self.find(:all, :conditions => ['is_active = ? and created_at > ? and created_at <= ?', 1, post.created_at.strftime('%Y-%m-%d %H:%M:%S'), Time.sl_local], :order => 'created_at asc', :limit => 1)
+ self.find(:all, :conditions => ['is_active = ? and created_at > ? and created_at <= ?', true, post.created_at.strftime('%Y-%m-%d %H:%M:%S'), Time.sl_local], :order => 'created_at asc', :limit => 1)
end
# find all posts in the db that contain string
def self.find_by_string(str, limit = Preference.get_setting('SEARCH_RESULTS'), active_only = true)
# use the search lib to run this search
- results = self.search(str, {:conditions => (active_only ? ["is_active = ? and created_at <= '#{Time.sl_local_db}'", 1] : nil), :limit => limit})
+ results = self.search(str, {:conditions => (active_only ? ["is_active = ? and created_at <= '#{Time.sl_local_db}'", true] : nil), :limit => limit})
if (results.length > 1) or (str.downcase.index(' and '))
# if the first search returned something or there was an AND operator
return results
else
# first search didn't find anthing, let's try it with the OR operator
simple_str = str.gsub(' ',' OR ')
- return self.search(simple_str, {:conditions => (active_only ? ["is_active = ? and created_at <= '#{Time.sl_local_db}'", 1] : nil), :limit => limit})
+ return self.search(simple_str, {:conditions => (active_only ? ["is_active = ? and created_at <= '#{Time.sl_local_db}'", true] : nil), :limit => limit})
end
end
def self.find_by_string_full(str, limit = Preference.get_setting('SEARCH_RESULTS_FULL'))

0 comments on commit 7e66818

Please sign in to comment.