Replaces find(:all) calls.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10918 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-12-02 20:28:37 +00:00
parent 536747b747
commit abd921736b
16 changed files with 21 additions and 21 deletions

View File

@ -28,7 +28,7 @@ class CreateJournals < ActiveRecord::Migration
Permission.create :controller => "issues", :action => "history", :description => "label_history", :sort => 1006, :is_public => true, :mail_option => 0, :mail_enabled => 0 Permission.create :controller => "issues", :action => "history", :description => "label_history", :sort => 1006, :is_public => true, :mail_option => 0, :mail_enabled => 0
# data migration # data migration
IssueHistory.find(:all, :include => :issue).each {|h| IssueHistory.all.each {|h|
j = Journal.new(:journalized => h.issue, :user_id => h.author_id, :notes => h.notes, :created_on => h.created_on) j = Journal.new(:journalized => h.issue, :user_id => h.author_id, :notes => h.notes, :created_on => h.created_on)
j.details << JournalDetail.new(:property => 'attr', :prop_key => 'status_id', :value => h.status_id) j.details << JournalDetail.new(:property => 'attr', :prop_key => 'status_id', :value => h.status_id)
j.save j.save

View File

@ -1,7 +1,7 @@
class AddIssueStatusPosition < ActiveRecord::Migration class AddIssueStatusPosition < ActiveRecord::Migration
def self.up def self.up
add_column :issue_statuses, :position, :integer, :default => 1 add_column :issue_statuses, :position, :integer, :default => 1
IssueStatus.find(:all).each_with_index {|status, i| status.update_attribute(:position, i+1)} IssueStatus.all.each_with_index {|status, i| status.update_attribute(:position, i+1)}
end end
def self.down def self.down

View File

@ -1,7 +1,7 @@
class AddTrackerPosition < ActiveRecord::Migration class AddTrackerPosition < ActiveRecord::Migration
def self.up def self.up
add_column :trackers, :position, :integer, :default => 1 add_column :trackers, :position, :integer, :default => 1
Tracker.find(:all).each_with_index {|tracker, i| tracker.update_attribute(:position, i+1)} Tracker.all.each_with_index {|tracker, i| tracker.update_attribute(:position, i+1)}
end end
def self.down def self.down

View File

@ -1,6 +1,6 @@
class SerializePossiblesValues < ActiveRecord::Migration class SerializePossiblesValues < ActiveRecord::Migration
def self.up def self.up
CustomField.find(:all).each do |field| CustomField.all.each do |field|
if field.possible_values and field.possible_values.is_a? String if field.possible_values and field.possible_values.is_a? String
field.possible_values = field.possible_values.split('|') field.possible_values = field.possible_values.split('|')
field.save field.save

View File

@ -2,7 +2,7 @@ class AddSettingsUpdatedOn < ActiveRecord::Migration
def self.up def self.up
add_column :settings, :updated_on, :timestamp add_column :settings, :updated_on, :timestamp
# set updated_on # set updated_on
Setting.find(:all).each(&:save) Setting.all.each(&:save)
end end
def self.down def self.down

View File

@ -7,7 +7,7 @@ class CreateEnabledModules < ActiveRecord::Migration
add_index :enabled_modules, [:project_id], :name => :enabled_modules_project_id add_index :enabled_modules, [:project_id], :name => :enabled_modules_project_id
# Enable all modules for existing projects # Enable all modules for existing projects
Project.find(:all).each do |project| Project.all.each do |project|
project.enabled_module_names = Redmine::AccessControl.available_project_modules project.enabled_module_names = Redmine::AccessControl.available_project_modules
end end
end end

View File

@ -1,7 +1,7 @@
class AddEnumerationsPosition < ActiveRecord::Migration class AddEnumerationsPosition < ActiveRecord::Migration
def self.up def self.up
add_column(:enumerations, :position, :integer, :default => 1) unless Enumeration.column_names.include?('position') add_column(:enumerations, :position, :integer, :default => 1) unless Enumeration.column_names.include?('position')
Enumeration.find(:all).group_by(&:opt).each do |opt, enums| Enumeration.all.group_by(&:opt).each do |opt, enums|
enums.each_with_index do |enum, i| enums.each_with_index do |enum, i|
# do not call model callbacks # do not call model callbacks
Enumeration.update_all "position = #{i+1}", {:id => enum.id} Enumeration.update_all "position = #{i+1}", {:id => enum.id}

View File

@ -1,7 +1,7 @@
class AddCustomFieldsPosition < ActiveRecord::Migration class AddCustomFieldsPosition < ActiveRecord::Migration
def self.up def self.up
add_column(:custom_fields, :position, :integer, :default => 1) add_column(:custom_fields, :position, :integer, :default => 1)
CustomField.find(:all).group_by(&:type).each do |t, fields| CustomField.all.group_by(&:type).each do |t, fields|
fields.each_with_index do |field, i| fields.each_with_index do |field, i|
# do not call model callbacks # do not call model callbacks
CustomField.update_all "position = #{i+1}", {:id => field.id} CustomField.update_all "position = #{i+1}", {:id => field.id}

View File

@ -7,8 +7,8 @@ class CreateProjectsTrackers < ActiveRecord::Migration
add_index :projects_trackers, :project_id, :name => :projects_trackers_project_id add_index :projects_trackers, :project_id, :name => :projects_trackers_project_id
# Associates all trackers to all projects (as it was before) # Associates all trackers to all projects (as it was before)
tracker_ids = Tracker.find(:all).collect(&:id) tracker_ids = Tracker.all.collect(&:id)
Project.find(:all).each do |project| Project.all.each do |project|
project.tracker_ids = tracker_ids project.tracker_ids = tracker_ids
end end
end end

View File

@ -1,12 +1,12 @@
class AddCommitAccessPermission < ActiveRecord::Migration class AddCommitAccessPermission < ActiveRecord::Migration
def self.up def self.up
Role.find(:all).select { |r| not r.builtin? }.each do |r| Role.all.select { |r| not r.builtin? }.each do |r|
r.add_permission!(:commit_access) r.add_permission!(:commit_access)
end end
end end
def self.down def self.down
Role.find(:all).select { |r| not r.builtin? }.each do |r| Role.all.select { |r| not r.builtin? }.each do |r|
r.remove_permission!(:commit_access) r.remove_permission!(:commit_access)
end end
end end

View File

@ -1,12 +1,12 @@
class AddViewWikiEditsPermission < ActiveRecord::Migration class AddViewWikiEditsPermission < ActiveRecord::Migration
def self.up def self.up
Role.find(:all).each do |r| Role.all.each do |r|
r.add_permission!(:view_wiki_edits) if r.has_permission?(:view_wiki_pages) r.add_permission!(:view_wiki_edits) if r.has_permission?(:view_wiki_pages)
end end
end end
def self.down def self.down
Role.find(:all).each do |r| Role.all.each do |r|
r.remove_permission!(:view_wiki_edits) r.remove_permission!(:view_wiki_edits)
end end
end end

View File

@ -1,12 +1,12 @@
class AddDeleteWikiPagesAttachmentsPermission < ActiveRecord::Migration class AddDeleteWikiPagesAttachmentsPermission < ActiveRecord::Migration
def self.up def self.up
Role.find(:all).each do |r| Role.all.each do |r|
r.add_permission!(:delete_wiki_pages_attachments) if r.has_permission?(:edit_wiki_pages) r.add_permission!(:delete_wiki_pages_attachments) if r.has_permission?(:edit_wiki_pages)
end end
end end
def self.down def self.down
Role.find(:all).each do |r| Role.all.each do |r|
r.remove_permission!(:delete_wiki_pages_attachments) r.remove_permission!(:delete_wiki_pages_attachments)
end end
end end

View File

@ -10,7 +10,7 @@ class AddProjectsTrackersUniqueIndex < ActiveRecord::Migration
# Removes duplicates in projects_trackers table # Removes duplicates in projects_trackers table
def self.remove_duplicates def self.remove_duplicates
Project.find(:all).each do |project| Project.all.each do |project|
ids = project.trackers.collect(&:id) ids = project.trackers.collect(&:id)
unless ids == ids.uniq unless ids == ids.uniq
project.trackers.clear project.trackers.clear

View File

@ -1,7 +1,7 @@
class PopulateMemberRoles < ActiveRecord::Migration class PopulateMemberRoles < ActiveRecord::Migration
def self.up def self.up
MemberRole.delete_all MemberRole.delete_all
Member.find(:all).each do |member| Member.all.each do |member|
MemberRole.create!(:member_id => member.id, :role_id => member.role_id) MemberRole.create!(:member_id => member.id, :role_id => member.role_id)
end end
end end

View File

@ -1,12 +1,12 @@
class AddViewIssuesPermission < ActiveRecord::Migration class AddViewIssuesPermission < ActiveRecord::Migration
def self.up def self.up
Role.find(:all).each do |r| Role.all.each do |r|
r.add_permission!(:view_issues) r.add_permission!(:view_issues)
end end
end end
def self.down def self.down
Role.find(:all).each do |r| Role.all.each do |r|
r.remove_permission!(:view_issues) r.remove_permission!(:view_issues)
end end
end end

View File

@ -1,6 +1,6 @@
class EnableCalendarAndGanttModulesWhereAppropriate < ActiveRecord::Migration class EnableCalendarAndGanttModulesWhereAppropriate < ActiveRecord::Migration
def self.up def self.up
EnabledModule.find(:all, :conditions => ["name = ?", 'issue_tracking']).each do |e| EnabledModule.where(:name => 'issue_tracking').all.each do |e|
EnabledModule.create(:name => 'calendar', :project_id => e.project_id) EnabledModule.create(:name => 'calendar', :project_id => e.project_id)
EnabledModule.create(:name => 'gantt', :project_id => e.project_id) EnabledModule.create(:name => 'gantt', :project_id => e.project_id)
end end