fix deprecation warnings

This commit is contained in:
Reinier Balt 2013-09-13 16:44:59 +02:00
parent b343d0a09e
commit eaa66be698
19 changed files with 37 additions and 33 deletions

View file

@ -272,7 +272,8 @@ class ApplicationController < ActionController::Base
@source_view = object_name @source_view = object_name
@page_title = t("#{object_name.pluralize}.all_completed_tasks_title", "#{object_name}_name".to_sym => object.name) @page_title = t("#{object_name.pluralize}.all_completed_tasks_title", "#{object_name}_name".to_sym => object.name)
@done = object.todos.completed.paginate :page => params[:page], :per_page => 20, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES @done = object.todos.completed.reorder('completed_at DESC').includes(Todo::DEFAULT_INCLUDES).
paginate(:page => params[:page], :per_page => 20)
@count = @done.size @count = @done.size
render :template => 'todos/all_done' render :template => 'todos/all_done'
end end

View file

@ -1270,21 +1270,21 @@ end
# all completed todos [today@00:00, today@now] # all completed todos [today@00:00, today@now]
def get_done_today(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES}) def get_done_today(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
start_of_this_day = Time.zone.now.beginning_of_day start_of_this_day = Time.zone.now.beginning_of_day
completed_todos.completed_after(start_of_this_day).all(includes) completed_todos.completed_after(start_of_this_day).includes(includes[:include])
end end
# all completed todos [begin_of_week, start_of_today] # all completed todos [begin_of_week, start_of_today]
def get_done_rest_of_week(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES}) def get_done_rest_of_week(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
start_of_this_week = Time.zone.now.beginning_of_week start_of_this_week = Time.zone.now.beginning_of_week
start_of_this_day = Time.zone.now.beginning_of_day start_of_this_day = Time.zone.now.beginning_of_day
completed_todos.completed_before(start_of_this_day).completed_after(start_of_this_week).all(includes) completed_todos.completed_before(start_of_this_day).completed_after(start_of_this_week).includes(includes[:include])
end end
# all completed todos [begin_of_month, begin_of_week] # all completed todos [begin_of_month, begin_of_week]
def get_done_rest_of_month(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES}) def get_done_rest_of_month(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
start_of_this_month = Time.zone.now.beginning_of_month start_of_this_month = Time.zone.now.beginning_of_month
start_of_this_week = Time.zone.now.beginning_of_week start_of_this_week = Time.zone.now.beginning_of_week
completed_todos.completed_before(start_of_this_week).completed_after(start_of_this_month).all(includes) completed_todos.completed_before(start_of_this_week).completed_after(start_of_this_month).includes(includes[:include])
end end
def get_not_done_todos def get_not_done_todos

View file

@ -8,9 +8,9 @@ class AddUserId < ActiveRecord::Migration
add_column :contexts, :user_id, :integer, :default => 1 add_column :contexts, :user_id, :integer, :default => 1
add_column :projects, :user_id, :integer, :default => 1 add_column :projects, :user_id, :integer, :default => 1
add_column :todos, :user_id, :integer, :default => 1 add_column :todos, :user_id, :integer, :default => 1
Context.find(:all).each { |context| context.user_id = 1 } Context.all.each { |context| context.user_id = 1 }
Project.find(:all).each { |project| project.user_id = 1 } Project.all.each { |project| project.user_id = 1 }
Todo.find(:all).each { |todo| todo.user_id = 1 } Todo.all.each { |todo| todo.user_id = 1 }
end end
def self.down def self.down

View file

@ -4,7 +4,7 @@ class AddPreferencesToUserTable < ActiveRecord::Migration
def self.up def self.up
add_column :users, :preferences, :text add_column :users, :preferences, :text
@users = User.find(:all) @users = User.all
@users.each do |u| @users.each do |u|
u.preferences = { "date_format" => "%d/%m/%Y", "week_starts" => "1", "no_completed" => "5", "staleness_starts" => "7", "due_style" => "1", "admin_email" => "butshesagirl@rousette.org.uk"} u.preferences = { "date_format" => "%d/%m/%Y", "week_starts" => "1", "no_completed" => "5", "staleness_starts" => "7", "due_style" => "1", "admin_email" => "butshesagirl@rousette.org.uk"}
u.save u.save

View file

@ -6,7 +6,7 @@ class AddSubclassAttrToTodos < ActiveRecord::Migration
def self.up def self.up
add_column :todos, :type, :string, :null => false, :default => "Immediate" add_column :todos, :type, :string, :null => false, :default => "Immediate"
add_column :todos, :show_from, :date add_column :todos, :show_from, :date
Todo.find(:all).each { |todo| todo.type = "Immediate" } Todo.all.each { |todo| todo.type = "Immediate" }
end end
def self.down def self.down

View file

@ -3,7 +3,7 @@ class AddUserPrefRefresh < ActiveRecord::Migration
class User < ActiveRecord::Base; serialize :preferences; end class User < ActiveRecord::Base; serialize :preferences; end
def self.up def self.up
@users = User.find(:all) @users = User.all
@users.each do |user| @users.each do |user|
user.preferences.merge!({"refresh" => "0"}) user.preferences.merge!({"refresh" => "0"})
user.save user.save

View file

@ -3,7 +3,7 @@ class PrefToShowHideSidebarItems < ActiveRecord::Migration
class User < ActiveRecord::Base; serialize :preferences; end class User < ActiveRecord::Base; serialize :preferences; end
def self.up def self.up
@users = User.find(:all) @users = User.all
@users.each do |user| @users.each do |user|
user.preferences.merge!({"show_completed_projects_in_sidebar" => true}) user.preferences.merge!({"show_completed_projects_in_sidebar" => true})
user.preferences.merge!({"show_hidden_contexts_in_sidebar" => true}) user.preferences.merge!({"show_hidden_contexts_in_sidebar" => true})
@ -12,7 +12,7 @@ class PrefToShowHideSidebarItems < ActiveRecord::Migration
end end
def self.down def self.down
@users = User.find(:all) @users = User.all
@users.each do |user| @users.each do |user|
user.preferences.delete("show_completed_projects_in_sidebar") user.preferences.delete("show_completed_projects_in_sidebar")
user.preferences.delete("show_hidden_contexts_in_sidebar") user.preferences.delete("show_hidden_contexts_in_sidebar")

View file

@ -3,7 +3,7 @@ class ConvertPreferences < ActiveRecord::Migration
class User < ActiveRecord::Base; has_one :preference; serialize :preferences; end class User < ActiveRecord::Base; has_one :preference; serialize :preferences; end
def self.up def self.up
@users = User.find(:all) @users = User.all
@users.each do |user| @users.each do |user|
user.create_preference user.create_preference
user.preference.date_format = user.preferences['date_format'] user.preference.date_format = user.preferences['date_format']
@ -27,7 +27,7 @@ class ConvertPreferences < ActiveRecord::Migration
def self.down def self.down
add_column :users, :preferences, :text add_column :users, :preferences, :text
@users = User.find(:all) @users = User.all
@users.each do |user| @users.each do |user|
user.preferences = { "date_format" => "#{user.preference.date_format}", user.preferences = { "date_format" => "#{user.preference.date_format}",
"week_starts" => "#{user.preference.week_starts}", "week_starts" => "#{user.preference.week_starts}",

View file

@ -4,7 +4,7 @@ class ConvertProjectToStateMachine < ActiveRecord::Migration
def self.up def self.up
add_column :projects, :state, :string, :limit => 20, :default => "active", :null => false add_column :projects, :state, :string, :limit => 20, :default => "active", :null => false
@projects = Project.find(:all) @projects = Project.all
@projects.each do |project| @projects.each do |project|
project.state = project.done? ? 'completed' : 'active' project.state = project.done? ? 'completed' : 'active'
project.save project.save
@ -14,7 +14,7 @@ class ConvertProjectToStateMachine < ActiveRecord::Migration
def self.down def self.down
add_column :projects, :done, :integer, :limit => 4, :default => 0, :null => false add_column :projects, :done, :integer, :limit => 4, :default => 0, :null => false
@projects = Project.find(:all) @projects = Project.all
@projects.each do |project| @projects.each do |project|
project.done = project.state == 'completed' project.done = project.state == 'completed'
project.save project.save

View file

@ -7,7 +7,7 @@ class ConvertTodoToStateMachine < ActiveRecord::Migration
def self.up def self.up
add_column :todos, :state, :string, :limit => 20, :default => "immediate", :null => false add_column :todos, :state, :string, :limit => 20, :default => "immediate", :null => false
@todos = Todo.find(:all) @todos = Todo.all
@todos.each do |todo| @todos.each do |todo|
if todo.done? if todo.done?
todo.state = 'completed' todo.state = 'completed'
@ -29,7 +29,7 @@ class ConvertTodoToStateMachine < ActiveRecord::Migration
add_column :todos, :done, :integer, :limit => 4, :default => 0, :null => false add_column :todos, :done, :integer, :limit => 4, :default => 0, :null => false
add_column :todos, :type, :string, :default => "Immediate", :null => false add_column :todos, :type, :string, :default => "Immediate", :null => false
rename_column :todos, 'completed_at', 'completed' #bug in sqlite requires column names as strings rename_column :todos, 'completed_at', 'completed' #bug in sqlite requires column names as strings
@todos = Todo.find(:all) @todos = Todo.all
@todos.each do |todo| @todos.each do |todo|
todo.done = todo.state == 'completed' todo.done = todo.state == 'completed'
todo.type = todo.type == 'deferred' ? 'Deferred' : 'Immediate' todo.type = todo.type == 'deferred' ? 'Deferred' : 'Immediate'

View file

@ -5,16 +5,16 @@ class SetNilTimestamps < ActiveRecord::Migration
class Context < ActiveRecord::Base; end class Context < ActiveRecord::Base; end
def self.up def self.up
Project.find(:all, :conditions => { :created_at => nil }).each do |p| Project.where(:created_at => nil ).each do |p|
Project.update( p.id, {:created_at => Time.now.utc} ) Project.update( p.id, {:created_at => Time.now.utc} )
end end
Project.find(:all, :conditions => { :created_at => nil }).each do |p| Project.where(:created_at => nil ).each do |p|
Project.update( p.id, {:updated_at => Time.now.utc} ) Project.update( p.id, {:updated_at => Time.now.utc} )
end end
Context.find(:all, :conditions => { :created_at => nil }).each do |p| Context.where(:created_at => nil ).each do |p|
Context.update( p.id, {:created_at => Time.now.utc} ) Context.update( p.id, {:created_at => Time.now.utc} )
end end
Context.find(:all, :conditions => { :created_at => nil }).each do |p| Context.where(:created_at => nil ).each do |p|
Context.update( p.id, {:updated_at => Time.now.utc} ) Context.update( p.id, {:updated_at => Time.now.utc} )
end end

View file

@ -16,7 +16,7 @@ class UpdateOpenIdUrls < ActiveRecord::Migration
end end
def self.up def self.up
User.find(:all).each do |user| User.all.each do |user|
original = user.open_id_url original = user.open_id_url
user.normalize_open_id_url user.normalize_open_id_url
say "#{original} -> #{user.open_id_url}" say "#{original} -> #{user.open_id_url}"

View file

@ -4,7 +4,7 @@ class AddProjectCompletedAtColumn < ActiveRecord::Migration
def self.up def self.up
add_column :projects, :completed_at, :datetime add_column :projects, :completed_at, :datetime
@projects = Project.find(:all) @projects = Project.all
@projects.select{ |project| project.state == 'completed'}.each do |project| @projects.select{ |project| project.state == 'completed'}.each do |project|
project.completed_at = project.updated_at project.completed_at = project.updated_at
project.save project.save

View file

@ -5,7 +5,7 @@ class ChangeDatesToDatetimes < ActiveRecord::Migration
change_column :recurring_todos, :start_from, :datetime change_column :recurring_todos, :start_from, :datetime
change_column :recurring_todos, :end_date, :datetime change_column :recurring_todos, :end_date, :datetime
User.all(:include => [:todos, :recurring_todos]).each do |user| User.includes(:todos, :recurring_todos).each do |user|
if !user.prefs ## ugly hack for strange edge-case of not having preferences object if !user.prefs ## ugly hack for strange edge-case of not having preferences object
user.instance_eval do user.instance_eval do
def at_midnight(date) def at_midnight(date)

View file

@ -1,11 +1,11 @@
class FixIncorrectlyHiddenTodos < ActiveRecord::Migration class FixIncorrectlyHiddenTodos < ActiveRecord::Migration
def self.up def self.up
hidden_todos_without_project = hidden_todos_without_project =
Todo.find(:all, :conditions => "state='project_hidden' AND project_id IS NULL") Todo.where(:state => 'project_hidden', :project_id => nil)
active_projects = Project.find(:all, :conditions => "state='active'") active_projects = Project.where(:state => 'active')
hidden_todos_in_active_projects = hidden_todos_in_active_projects =
Todo.find(:all, :conditions => ["state='project_hidden' AND project_id IN (?)", active_projects]) Todo.where(:state => 'project_hidden').where("project_id IN (?)", active_projects)
todos_to_fix = hidden_todos_without_project + hidden_todos_in_active_projects todos_to_fix = hidden_todos_without_project + hidden_todos_in_active_projects
todos_to_fix.each do |todo| todos_to_fix.each do |todo|

View file

@ -1,7 +1,7 @@
class AddShowAlwaysToRecurringTodo < ActiveRecord::Migration class AddShowAlwaysToRecurringTodo < ActiveRecord::Migration
def self.up def self.up
add_column :recurring_todos, :show_always, :boolean add_column :recurring_todos, :show_always, :boolean
recurring_todos = RecurringTodo.find(:all) recurring_todos = RecurringTodo.all
recurring_todos.each do |recurring_todo| recurring_todos.each do |recurring_todo|
if recurring_todo.show_from_delta == 0 or recurring_todo.show_from_delta.nil? if recurring_todo.show_from_delta == 0 or recurring_todo.show_from_delta.nil?
recurring_todo.show_always = true recurring_todo.show_always = true

View file

@ -1,6 +1,6 @@
class MakeOldRecurringTodosValidate < ActiveRecord::Migration class MakeOldRecurringTodosValidate < ActiveRecord::Migration
def self.up def self.up
RecurringTodo.find(:all).each do |rt| RecurringTodo.all.each do |rt|
# show_always may not be nil # show_always may not be nil
rt.show_always = false if rt.show_always.nil? rt.show_always = false if rt.show_always.nil?
# start date should be filled # start date should be filled

View file

@ -6,7 +6,8 @@ class AddRenderedNotes < ActiveRecord::Migration
say "Clearing show_from dates from completed todos" say "Clearing show_from dates from completed todos"
# clear up completed todos that have show_from set. These could have been left over from before the AASM migration # clear up completed todos that have show_from set. These could have been left over from before the AASM migration
Todo.completed.find(:all, :conditions =>[ "NOT(show_from IS NULL)"]).each {|t| t.show_from=nil; t.save!} Todo.completed.where( "NOT(show_from IS NULL)" ).each {|t| t.show_from=nil; t.save!}
say "Generating new column values from notes. This may take a while." say "Generating new column values from notes. This may take a while."
# Call save! on each todo to force generation of rendered_todos # Call save! on each todo to force generation of rendered_todos
i=0; max = Todo.all.count; start = Time.now i=0; max = Todo.all.count; start = Time.now

View file

@ -6,7 +6,8 @@ class DoneTodos
def self.done_today(todos, includes = {:include => Todo::DEFAULT_INCLUDES}) def self.done_today(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
start_of_this_day = Time.zone.now.beginning_of_day start_of_this_day = Time.zone.now.beginning_of_day
todos.completed_after(start_of_this_day).all(includes) # TODO: refactor to remove outer hash from includes param
todos.completed_after(start_of_this_day).includes(includes[:include])
end end
def self.done_rest_of_week(todos, includes = {:include => Todo::DEFAULT_INCLUDES}) def self.done_rest_of_week(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
@ -37,6 +38,7 @@ class DoneTodos
private private
def self.done_between(todos, includes, start_date, end_date) def self.done_between(todos, includes, start_date, end_date)
todos.completed_before(start_date).completed_after(end_date).all(includes) # TODO: refactor to remove outer hash from includes param
todos.completed_before(start_date).completed_after(end_date).includes(includes[:include])
end end
end end