Index: app/controllers/versions_controller.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/controllers/versions_controller.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/controllers/versions_controller.rb (revision fed3e767d8c476e6a3bd414a497e179b5c872788) @@ -32,7 +32,7 @@ respond_to do |format| format.html { @trackers = @project.trackers.sorted.to_a - retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?}) + retrieve_selected_tracker_ids(@trackers, @trackers.select { |t| t.is_in_roadmap? }) @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id] @@ -47,13 +47,13 @@ @issues_by_version = {} if @selected_tracker_ids.any? && @versions.any? issues = Issue.visible. - includes(:project, :tracker). - preload(:status, :priority, :fixed_version). - where(:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)). + includes(:project, :tracker). + preload(:status, :priority, :fixed_version). + where(:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)). - order("#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id") + order(Project.arel_table[:lft].asc, Tracker.arel_table[:position].asc, Issue.arel_table[:id].asc) @issues_by_version = issues.group_by(&:fixed_version) end - @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?} + @versions.reject! { |version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank? } } format.api { @versions = @project.shared_versions.to_a @@ -65,10 +65,10 @@ respond_to do |format| format.html { @issues = @version.fixed_issues.visible. - includes(:status, :tracker, :priority). - preload(:project). + includes(:status, :tracker, :priority). + preload(:project). - reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id"). + reorder(Issue.arel_table[:id].asc). - to_a + to_a } format.api end @@ -107,8 +107,8 @@ else respond_to do |format| format.html { render :action => 'new' } - format.js { render :action => 'new' } + format.js { render :action => 'new' } - format.api { render_validation_errors(@version) } + format.api { render_validation_errors(@version) } end end end @@ -128,12 +128,12 @@ flash[:notice] = l(:notice_successful_update) redirect_back_or_default settings_project_path(@project, :tab => 'versions') } - format.api { render_api_ok } + format.api { render_api_ok } end else respond_to do |format| format.html { render :action => 'edit' } - format.api { render_validation_errors(@version) } + format.api { render_validation_errors(@version) } end end end @@ -151,7 +151,7 @@ @version.destroy respond_to do |format| format.html { redirect_back_or_default settings_project_path(@project, :tab => 'versions') } - format.api { render_api_ok } + format.api { render_api_ok } end else respond_to do |format| @@ -159,7 +159,7 @@ flash[:error] = l(:notice_unable_delete_version) redirect_to settings_project_path(@project, :tab => 'versions') } - format.api { head :unprocessable_entity } + format.api { head :unprocessable_entity } end end end @@ -177,7 +177,7 @@ if ids = params[:tracker_ids] @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } else - @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s } + @selected_tracker_ids = (default_trackers || selectable_trackers).collect { |t| t.id.to_s } end end end Index: app/helpers/my_helper.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/helpers/my_helper.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/helpers/my_helper.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a) @@ -37,7 +37,7 @@ limit(10). includes(:status, :project, :tracker, :priority). references(:status, :project, :tracker, :priority). - order("#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC") + order(IssuePriority.arel_table[:position].desc, Issue.arel_table[:updated_on].desc) end def issuesreportedbyme_items @@ -69,7 +69,7 @@ joins(:activity, :project). references(:issue => [:tracker, :status]). includes(:issue => [:tracker, :status]). - order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC"). + order(TimeEntry.arel_table[:spent_on].desc, Project.arel_table[:name].asc, Tracker.arel_table[:position].asc, Issue.arel_table[:id].asc). to_a end end Index: app/models/enumeration.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/enumeration.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) +++ app/models/enumeration.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) @@ -18,7 +18,7 @@ class Enumeration < ActiveRecord::Base include Redmine::SubclassFactory - default_scope lambda {order(:position)} + default_scope lambda { order(:position) } belongs_to :project @@ -27,7 +27,7 @@ acts_as_tree before_destroy :check_integrity - before_save :check_default + before_save :check_default attr_protected :type @@ -39,7 +39,7 @@ scope :sorted, lambda { order(:position) } scope :active, lambda { where(:active => true) } scope :system, lambda { where(:project_id => nil) } - scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} + scope :named, lambda { |arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip) } def self.default # Creates a fake default scope so Enumeration.default will check @@ -93,7 +93,9 @@ position <=> enumeration.position end - def to_s; name end + def to_s; + name + end # Returns the Subclasses of Enumeration. Each Subclass needs to be # required in development mode. @@ -105,7 +107,7 @@ # Does the +new+ Hash override the previous Enumeration? def self.overriding_change?(new, previous) - if (same_active_state?(new['active'], previous.active)) && same_custom_values?(new,previous) + if (same_active_state?(new['active'], previous.active)) && same_custom_values?(new, previous) return false else return true @@ -149,12 +151,10 @@ def update_position super if position_changed? - self.class.where.not(:parent_id => nil).update_all( - "position = coalesce(( - select position - from (select id, position from enumerations) as parent - where parent_id = parent.id), 1)" - ) + from = Enumeration.select(:id, :position) + self.class.where.not(:parent_id => nil).update_all(:position => "coalesce(#{Enumeration.where(nil). + from("(#{from.to_sql}) as parent"). + where('parent_id = parent.id').select(:position).to_sql}), 1)") end end Index: app/models/issue.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/issue.rb (revision 4d10162d2a58c14765bf6abc8b5ed12ea4af73d2) +++ app/models/issue.rb (revision e3cbc3d2f583d6a93fe4c01281991e21d34a88b3) @@ -1537,7 +1537,7 @@ if issue_id && p = Issue.find_by_id(issue_id) if p.priority_derived? # priority = highest priority of open children - if priority_position = p.children.open.joins(:priority).maximum("#{IssuePriority.table_name}.position") + if priority_position = p.children.open.joins(:priority).reorder(nil).select(IssuePriority.arel_table[:position].maximum).first[:max] p.priority = IssuePriority.find_by_position(priority_position) else p.priority = IssuePriority.default Index: app/models/issue_query.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/issue_query.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/models/issue_query.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a) @@ -23,10 +23,10 @@ self.available_columns = [ QueryColumn.new(:id, :sortable => "#{Issue.table_name}.id", :default_order => 'desc', :caption => '#', :frozen => true), QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true), - QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :groupable => true), + QueryColumn.new(:tracker, :sortable => Tracker.arel_table[:position].asc.to_sql, :groupable => true), QueryColumn.new(:parent, :sortable => ["#{Issue.table_name}.root_id", "#{Issue.table_name}.lft ASC"], :default_order => 'desc', :caption => :field_parent_issue), - QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position", :groupable => true), - QueryColumn.new(:priority, :sortable => "#{IssuePriority.table_name}.position", :default_order => 'desc', :groupable => true), + QueryColumn.new(:status, :sortable => IssueStatus.arel_table[:position].asc.to_sql, :groupable => true), + QueryColumn.new(:priority, :sortable => IssuePriority.arel_table[:position].desc.to_sql, :groupable => true), QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"), QueryColumn.new(:author, :sortable => lambda {User.fields_for_order_statement("authors")}, :groupable => true), QueryColumn.new(:assigned_to, :sortable => lambda {User.fields_for_order_statement}, :groupable => true), Index: app/models/issue_status.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/issue_status.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) +++ app/models/issue_status.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) @@ -33,12 +33,12 @@ attr_protected :id scope :sorted, lambda { order(:position) } - scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} + scope :named, lambda { |arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip) } safe_attributes 'name', - 'is_closed', - 'position', - 'default_done_ratio' + 'is_closed', + 'position', + 'default_done_ratio' # Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+ def self.update_issue_done_ratios @@ -55,6 +55,7 @@ def new_statuses_allowed_to(roles, tracker, author=false, assignee=false) self.class.new_statuses_allowed(self, roles, tracker, author, assignee) end + alias :find_new_statuses_allowed_to :new_statuses_allowed_to def self.new_statuses_allowed(status, roles, tracker, author=false, assignee=false) @@ -62,8 +63,8 @@ status_id = status.try(:id) || 0 scope = IssueStatus. - joins(:workflow_transitions_as_new_status). - where(:workflows => {:old_status_id => status_id, :role_id => roles.map(&:id), :tracker_id => tracker.id}) + joins(:workflow_transitions_as_new_status). + where(:workflows => {:old_status_id => status_id, :role_id => roles.map(&:id), :tracker_id => tracker.id}) unless author && assignee if author || assignee @@ -83,7 +84,9 @@ position <=> status.position end - def to_s; name end + def to_s; + name + end private @@ -92,12 +95,11 @@ if is_closed_changed? && is_closed == true # First we update issues that have a journal for when the current status was set, # a subselect is used to update all issues with a single query - subselect = "SELECT MAX(j.created_on) FROM #{Journal.table_name} j" + - " JOIN #{JournalDetail.table_name} d ON d.journal_id = j.id" + - " WHERE j.journalized_type = 'Issue' AND j.journalized_id = #{Issue.table_name}.id" + - " AND d.property = 'attr' AND d.prop_key = 'status_id' AND d.value = :status_id" + subselect = Journal.joins(:details).where(:journalized_type => 'Issue').where("#{Journal.table_name}. +journalized_id = #{Issue.table_name}.id").where(:journal_details => {:property => 'attr', :prop_key => 'status_id', :value => ':status_id'}). + select("MAX(#{Journal.table_name}.created_on)").to_sql.gsub(/':status_id'/, ":status_id") Issue.where(:status_id => id, :closed_on => nil). - update_all(["closed_on = (#{subselect})", {:status_id => id.to_s}]) + update_all(["closed_on = (#{subselect})", {:status_id => id.to_s}]) # Then we update issues that don't have a journal which means the # current status was set on creation Index: app/models/project.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/project.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/models/project.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a) @@ -44,14 +44,14 @@ has_many :documents, :dependent => :destroy has_many :news, lambda {includes(:author)}, :dependent => :destroy has_many :issue_categories, lambda {order("#{IssueCategory.table_name}.name")}, :dependent => :delete_all - has_many :boards, lambda {order("position ASC")}, :dependent => :destroy + has_many :boards, lambda { order(:position) }, :dependent => :destroy has_one :repository, lambda {where(["is_default = ?", true])} has_many :repositories, :dependent => :destroy has_many :changesets, :through => :repository has_one :wiki, :dependent => :destroy # Custom field for the project issues has_and_belongs_to_many :issue_custom_fields, - lambda {order("#{CustomField.table_name}.position")}, + lambda { order(CustomField.arel_table[:position].asc) }, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :association_foreign_key => 'custom_field_id' Index: app/models/query.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/query.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/models/query.rb (revision b795289685e02d24a79a08eacd9d55cabc8bec9e) @@ -823,7 +823,7 @@ def sql_for_custom_field(field, operator, value, custom_field_id) db_table = CustomValue.table_name - db_field = 'value' + db_field = ActiveRecord::Base.connection.quote_column_name('value') filter = @available_filters[field] return nil unless filter if filter[:field].format.target_class && filter[:field].format.target_class <= User @@ -868,7 +868,7 @@ int_values = value.first.to_s.scan(/[+-]?\d+/).map(&:to_i).join(",") if int_values.present? if is_custom_filter - sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) IN (#{int_values}))" + sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) IN (#{int_values}))" else sql = "#{db_table}.#{db_field} IN (#{int_values})" end @@ -877,7 +877,7 @@ end when :float if is_custom_filter - sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5})" + sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5})" else sql = "#{db_table}.#{db_field} BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5}" end @@ -906,7 +906,7 @@ sql = date_clause(db_table, db_field, parse_date(value.first), nil, is_custom_filter) else if is_custom_filter - sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) >= #{value.first.to_f})" + sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) >= #{value.first.to_f})" else sql = "#{db_table}.#{db_field} >= #{value.first.to_f}" end @@ -916,7 +916,7 @@ sql = date_clause(db_table, db_field, nil, parse_date(value.first), is_custom_filter) else if is_custom_filter - sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) <= #{value.first.to_f})" + sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) <= #{value.first.to_f})" else sql = "#{db_table}.#{db_field} <= #{value.first.to_f}" end @@ -926,7 +926,7 @@ sql = date_clause(db_table, db_field, parse_date(value[0]), parse_date(value[1]), is_custom_filter) else if is_custom_filter - sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) BETWEEN #{value[0].to_f} AND #{value[1].to_f})" + sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) BETWEEN #{value[0].to_f} AND #{value[1].to_f})" else sql = "#{db_table}.#{db_field} BETWEEN #{value[0].to_f} AND #{value[1].to_f}" end Index: app/models/repository.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/repository.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/models/repository.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a) @@ -420,12 +420,12 @@ # Notes: # - this hash honnors the users mapping defined for the repository def stats_by_author - commits = Changeset.where("repository_id = ?", id).select("committer, user_id, count(*) as count").group("committer, user_id") + commits = Changeset.where("repository_id = ?", id).select("committer, user_id, count(*)").group("committer, user_id") #TODO: restore ordering ; this line probably never worked #commits.to_a.sort! {|x, y| x.last <=> y.last} - changes = Change.joins(:changeset).where("#{Changeset.table_name}.repository_id = ?", id).select("committer, user_id, count(*) as count").group("committer, user_id") + changes = Change.joins(:changeset).where("#{Changeset.table_name}.repository_id = ?", id).select("committer, user_id, count(*)").group("committer, user_id") user_ids = changesets.map(&:user_id).compact.uniq authors_names = User.where(:id => user_ids).inject({}) do |memo, user| Index: app/models/time_entry_query.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/time_entry_query.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ app/models/time_entry_query.rb (revision 4d10162d2a58c14765bf6abc8b5ed12ea4af73d2) @@ -25,10 +25,10 @@ QueryColumn.new(:spent_on, :sortable => ["#{TimeEntry.table_name}.spent_on", "#{TimeEntry.table_name}.created_on"], :default_order => 'desc', :groupable => true), QueryColumn.new(:tweek, :sortable => ["#{TimeEntry.table_name}.spent_on", "#{TimeEntry.table_name}.created_on"], :caption => l(:label_week)), QueryColumn.new(:user, :sortable => lambda {User.fields_for_order_statement}, :groupable => true), - QueryColumn.new(:activity, :sortable => "#{TimeEntryActivity.table_name}.position", :groupable => true), + QueryColumn.new(:activity, :sortable => TimeEntryActivity.arel_table[:position].asc.to_sql, :groupable => true), QueryColumn.new(:issue, :sortable => "#{Issue.table_name}.id"), - QueryAssociationColumn.new(:issue, :tracker, :caption => :field_tracker, :sortable => "#{Tracker.table_name}.position"), - QueryAssociationColumn.new(:issue, :status, :caption => :field_status, :sortable => "#{IssueStatus.table_name}.position"), + QueryAssociationColumn.new(:issue, :tracker, :caption => :field_tracker, :sortable => Tracker.arel_table[:position].asc.to_sql), + QueryAssociationColumn.new(:issue, :status, :caption => :field_status, :sortable => IssueStatus.arel_table[:position].asc.to_sql), QueryColumn.new(:comments), QueryColumn.new(:hours, :sortable => "#{TimeEntry.table_name}.hours", :totalable => true), ] Index: app/models/user.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/user.rb (revision 33d5ca2997952dc9616bf5df5a1a6a88eddd4b95) +++ app/models/user.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) @@ -683,7 +683,7 @@ # Returns true if the user is allowed to delete the user's own account def own_account_deletable? Setting.unsubscribe? && - (!admin? || User.active.where("admin = ? AND id <> ?", true, id).exists?) + (!admin? || User.active.where("id <> ?", id).where(:admin => true).exists?) end safe_attributes 'firstname', Index: db/migrate/007_create_journals.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- db/migrate/007_create_journals.rb (revision 33d5ca2997952dc9616bf5df5a1a6a88eddd4b95) +++ db/migrate/007_create_journals.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) @@ -22,7 +22,7 @@ end # indexes - add_index "journals", ["journalized_id", "journalized_type"], :name => "journals_journalized_id" + add_index "journals", ["journalized_id", "journalized_type"] add_index "journal_details", ["journal_id"], :name => "journal_details_journal_id" Permission.create :controller => "issues", :action => "history", :description => "label_history", :sort => 1006, :is_public => true, :mail_option => 0, :mail_enabled => 0 Index: db/migrate/107_add_open_id_authentication_tables.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- db/migrate/107_add_open_id_authentication_tables.rb (revision 33d5ca2997952dc9616bf5df5a1a6a88eddd4b95) +++ db/migrate/107_add_open_id_authentication_tables.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) @@ -1,12 +1,12 @@ class AddOpenIdAuthenticationTables < ActiveRecord::Migration def self.up - create_table :open_id_authentication_associations, :force => true do |t| + create_table :open_id_auth_associations, :force => true do |t| t.integer :issued, :lifetime t.string :handle, :assoc_type t.binary :server_url, :secret end - create_table :open_id_authentication_nonces, :force => true do |t| + create_table :open_id_auth_nonces, :force => true do |t| t.integer :timestamp, :null => false t.string :server_url, :null => true t.string :salt, :null => false @@ -14,7 +14,7 @@ end def self.down - drop_table :open_id_authentication_associations - drop_table :open_id_authentication_nonces + drop_table :open_id_auth_associations + drop_table :open_id_auth_nonces end end Index: db/migrate/20130201184705_add_unique_index_on_tokens_value.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- db/migrate/20130201184705_add_unique_index_on_tokens_value.rb (revision 33d5ca2997952dc9616bf5df5a1a6a88eddd4b95) +++ db/migrate/20130201184705_add_unique_index_on_tokens_value.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) @@ -2,7 +2,7 @@ def up say_with_time "Adding unique index on tokens, this may take some time..." do # Just in case - duplicates = Token.connection.select_values("SELECT value FROM #{Token.table_name} GROUP BY value HAVING COUNT(id) > 1") + duplicates = Token.group(:value).having('COUNT(id) > 1').select(:value).to_a Token.where(:value => duplicates).delete_all add_index :tokens, :value, :unique => true, :name => 'tokens_value' Index: db/migrate/20130215111141_populate_issues_closed_on.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- db/migrate/20130215111141_populate_issues_closed_on.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ db/migrate/20130215111141_populate_issues_closed_on.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a) @@ -10,7 +10,7 @@ " AND #{Journal.table_name}.journalized_type = 'Issue' AND #{Journal.table_name}.journalized_id = #{Issue.table_name}.id" + " AND #{JournalDetail.table_name}.property = 'attr' AND #{JournalDetail.table_name}.prop_key = 'status_id'" + " AND #{JournalDetail.table_name}.old_value NOT IN (#{closed_status_values})" + - " AND #{JournalDetail.table_name}.value IN (#{closed_status_values})" + " AND " + JournalDetail.arel_table[:value].in(closed_status_values).to_sql Issue.update_all "closed_on = (#{subselect})" # Then set closed_on for closed issues that weren't up updated by the above UPDATE Index: lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a) @@ -27,7 +27,7 @@ return if self.included_modules.include?(Redmine::Acts::Customizable::InstanceMethods) cattr_accessor :customizable_options self.customizable_options = options - has_many :custom_values, lambda {includes(:custom_field).order("#{CustomField.table_name}.position")}, + has_many :custom_values, lambda { joins(:custom_field).merge(CustomField.order(:position)) }, :as => :customized, :dependent => :delete_all, :validate => false Index: lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) +++ lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb (revision 08bc581cf543157c294f6194f9062d42fcb1652a) @@ -89,17 +89,17 @@ unless options[:attachments] == 'only' r = fetch_ranks_and_ids( - search_scope(user, projects, options). - where(search_tokens_condition(columns, tokens, options[:all_words])), - options[:limit] + search_scope(user, projects, options). + where(search_tokens_condition(columns, tokens, options[:all_words])), + options[:limit] ) queries += 1 if !options[:titles_only] && searchable_options[:search_custom_fields] searchable_custom_fields = CustomField.where(:type => "#{self.name}CustomField", :searchable => true).to_a - + if searchable_custom_fields.any? - fields_by_visibility = searchable_custom_fields.group_by {|field| + fields_by_visibility = searchable_custom_fields.group_by { |field| field.visibility_by_project_condition(searchable_options[:project_key], user, "#{CustomValue.table_name}.custom_field_id") } clauses = [] @@ -107,13 +107,13 @@ clauses << "(#{CustomValue.table_name}.custom_field_id IN (#{fields.map(&:id).join(',')}) AND (#{visibility}))" end visibility = clauses.join(' OR ') - + r |= fetch_ranks_and_ids( - search_scope(user, projects, options). - joins(:custom_values). - where(visibility). + search_scope(user, projects, options). + joins(:custom_values). + where(visibility). - where(search_tokens_condition(["#{CustomValue.table_name}.value"], tokens, options[:all_words])), + where(search_tokens_condition(["#{ActiveRecord::Base.connection.quote_table_name(CustomValue.table_name)}.#{ActiveRecord::Base.connection.quote_column_name('value')}"], tokens, options[:all_words])), - options[:limit] + options[:limit] ) queries += 1 end @@ -121,11 +121,11 @@ if !options[:titles_only] && searchable_options[:search_journals] r |= fetch_ranks_and_ids( - search_scope(user, projects, options). - joins(:journals). - where("#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes)})", false). - where(search_tokens_condition(["#{Journal.table_name}.notes"], tokens, options[:all_words])), - options[:limit] + search_scope(user, projects, options). + joins(:journals). + where("#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes)})", false). + where(search_tokens_condition(["#{Journal.table_name}.notes"], tokens, options[:all_words])), + options[:limit] ) queries += 1 end @@ -133,10 +133,10 @@ if searchable_options[:search_attachments] && (options[:titles_only] ? options[:attachments] == 'only' : options[:attachments] != '0') r |= fetch_ranks_and_ids( - search_scope(user, projects, options). - joins(:attachments). - where(search_tokens_condition(["#{Attachment.table_name}.filename", "#{Attachment.table_name}.description"], tokens, options[:all_words])), - options[:limit] + search_scope(user, projects, options). + joins(:attachments). + where(search_tokens_condition(["#{Attachment.table_name}.filename", "#{Attachment.table_name}.description"], tokens, options[:all_words])), + options[:limit] ) queries += 1 end @@ -152,26 +152,32 @@ end def search_tokens_condition(columns, tokens, all_words) - token_clauses = columns.map {|column| "(#{search_token_match_statement(column)})"} + token_clauses = columns.map { |column| + column = "lower(#{column})" + "(#{search_token_match_statement(column)})" + } sql = (['(' + token_clauses.join(' OR ') + ')'] * tokens.size).join(all_words ? ' AND ' : ' OR ') - [sql, * (tokens.collect {|w| "%#{w}%"} * token_clauses.size).sort] + [sql, * (tokens.collect { |w| "%#{w}%" } * token_clauses.size).sort] end + private :search_tokens_condition def search_token_match_statement(column, value='?') Redmine::Database.like(column, value) end + private :search_token_match_statement def fetch_ranks_and_ids(scope, limit) scope. - reorder(searchable_options[:date_column] => :desc, :id => :desc). - limit(limit). - distinct. - pluck(searchable_options[:date_column], :id). - # converts timestamps to integers for faster sort + reorder(searchable_options[:date_column] => :desc, :id => :desc). + limit(limit). + distinct. + pluck(searchable_options[:date_column], :id). + # converts timestamps to integers for faster sort - map {|timestamp, id| [timestamp.to_i, id]} + map { |timestamp, id| [timestamp.to_i, id] } end + private :fetch_ranks_and_ids # Returns the search scope for user and projects @@ -198,6 +204,7 @@ end scope end + private :search_scope # Returns search results of given ids Index: lib/plugins/open_id_authentication/lib/open_id_authentication/association.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/plugins/open_id_authentication/lib/open_id_authentication/association.rb (revision 33d5ca2997952dc9616bf5df5a1a6a88eddd4b95) +++ lib/plugins/open_id_authentication/lib/open_id_authentication/association.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) @@ -1,6 +1,6 @@ module OpenIdAuthentication class Association < ActiveRecord::Base - self.table_name = :open_id_authentication_associations + self.table_name = :open_id_auth_associations def from_record OpenID::Association.new(handle, secret, issued, lifetime, assoc_type) Index: lib/redmine/acts/positioned.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/redmine/acts/positioned.rb (revision 33d5ca2997952dc9616bf5df5a1a6a88eddd4b95) +++ lib/redmine/acts/positioned.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed) @@ -85,11 +85,11 @@ end def insert_position - position_scope.where("position >= ? AND id <> ?", position, id).update_all("position = position + 1") + position_scope.where(self.class.arel_table[:position].gteq(position)).where('id <> ?', id).update_all(:position => (self.class.arel_table[:position] + 1).to_sql) end def remove_position - position_scope_was.where("position >= ? AND id <> ?", position_was, id).update_all("position = position - 1") + position_scope_was.where(self.class.arel_table[:position].gteq(position_was)).where('id <> ?', id).update_all(:position => (self.class.arel_table[:position] - 1).to_sql) end def position_scope_changed? @@ -99,7 +99,7 @@ def shift_positions offset = position_was <=> position min, max = [position, position_was].sort - r = position_scope.where("id <> ? AND position BETWEEN ? AND ?", id, min, max).update_all("position = position + #{offset}") + r = position_scope.where('id <> ?', id).where(self.class.arel_table[:position].between(min..max)).update_all(:position => (self.class.arel_table[:position] + offset).to_sql) if r != max - min reset_positions_in_list end Index: lib/redmine/field_format.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/redmine/field_format.rb (revision 4d10162d2a58c14765bf6abc8b5ed12ea4af73d2) +++ lib/redmine/field_format.rb (revision 08bc581cf543157c294f6194f9062d42fcb1652a) @@ -265,7 +265,7 @@ # Returns nil if the custom field can not be used for sorting. def order_statement(custom_field) # COALESCE is here to make sure that blank and NULL values are sorted equally - "COALESCE(#{join_alias custom_field}.value, '')" + "COALESCE(#{join_alias custom_field}.#{value_column}, '')" end # Returns a GROUP BY clause that can used to group by custom value @@ -283,7 +283,7 @@ " AND #{alias_name}.customized_id = #{custom_field.class.customized_class.table_name}.id" + " AND #{alias_name}.custom_field_id = #{custom_field.id}" + " AND (#{custom_field.visibility_by_project_condition})" + - " AND #{alias_name}.value <> ''" + + " AND #{alias_name}.#{value_column} <> ''" + " AND #{alias_name}.id = (SELECT max(#{alias_name}_2.id) FROM #{CustomValue.table_name} #{alias_name}_2" + " WHERE #{alias_name}_2.customized_type = #{alias_name}.customized_type" + " AND #{alias_name}_2.customized_id = #{alias_name}.customized_id" + @@ -293,6 +293,10 @@ def join_alias(custom_field) "cf_#{custom_field.id}" end + + def value_column + ActiveRecord::Base.connection.quote_column_name('value') + end protected :join_alias end @@ -402,7 +406,7 @@ # Make the database cast values into numeric # Postgresql will raise an error if a value can not be casted! # CustomValue validations should ensure that it doesn't occur - "CAST(CASE #{join_alias custom_field}.value WHEN '' THEN '0' ELSE #{join_alias custom_field}.value END AS decimal(30,3))" + "CAST(CASE #{join_alias custom_field}.#{value_column} WHEN '' THEN '0' ELSE #{join_alias custom_field}.#{value_column} END AS decimal(18,3))" end # Returns totals for the given scope @@ -410,7 +414,7 @@ scope.joins(:custom_values). where(:custom_values => {:custom_field_id => custom_field.id}). where.not(:custom_values => {:value => ''}). - sum("CAST(#{CustomValue.table_name}.value AS decimal(30,3))") + sum("CAST(#{CustomValue.table_name}.#{value_column} AS decimal(18,3))") end def cast_total_value(custom_field, value) @@ -690,7 +694,7 @@ end def group_statement(custom_field) - "COALESCE(#{join_alias custom_field}.value, '')" + "COALESCE(#{join_alias custom_field}.#{value_column}, '')" end def join_for_order_statement(custom_field) @@ -701,13 +705,13 @@ " AND #{alias_name}.customized_id = #{custom_field.class.customized_class.table_name}.id" + " AND #{alias_name}.custom_field_id = #{custom_field.id}" + " AND (#{custom_field.visibility_by_project_condition})" + - " AND #{alias_name}.value <> ''" + + " AND #{alias_name}.#{value_column} <> ''" + " AND #{alias_name}.id = (SELECT max(#{alias_name}_2.id) FROM #{CustomValue.table_name} #{alias_name}_2" + " WHERE #{alias_name}_2.customized_type = #{alias_name}.customized_type" + " AND #{alias_name}_2.customized_id = #{alias_name}.customized_id" + " AND #{alias_name}_2.custom_field_id = #{alias_name}.custom_field_id)" + " LEFT OUTER JOIN #{target_class.table_name} #{value_join_alias custom_field}" + - " ON CAST(CASE #{alias_name}.value WHEN '' THEN '0' ELSE #{alias_name}.value END AS decimal(30,0)) = #{value_join_alias custom_field}.id" + " ON CAST(CASE #{alias_name}.#{value_column} WHEN '' THEN '0' ELSE #{alias_name}.#{value_column} END AS decimal(18,0)) = #{value_join_alias custom_field}.id" end def value_join_alias(custom_field) Index: lib/tasks/migrate_from_mantis.rake IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/tasks/migrate_from_mantis.rake (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ lib/tasks/migrate_from_mantis.rake (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a) @@ -52,7 +52,7 @@ TRACKER_BUG = Tracker.find_by_position(1) TRACKER_FEATURE = Tracker.find_by_position(2) - roles = Role.where(:builtin => 0).order('position ASC').all + roles = Role.where(:builtin => 0).order(:position).all manager_role = roles[0] developer_role = roles[1] DEFAULT_ROLE = roles.last Index: lib/tasks/migrate_from_trac.rake IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/tasks/migrate_from_trac.rake (revision 1199798be728002c93d6241bf33b919fdfeb7918) +++ lib/tasks/migrate_from_trac.rake (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a) @@ -60,7 +60,7 @@ 'patch' =>TRACKER_FEATURE } - roles = Role.where(:builtin => 0).order('position ASC').all + roles = Role.where(:builtin => 0).order(:position).all manager_role = roles[0] developer_role = roles[1] DEFAULT_ROLE = roles.last