Project

General

Profile

Feature #24013 » firebird_support_v2.patch

Andrey Lobanov (RedSoft), 2016-10-09 16:27

View differences:

app/controllers/application_controller.rb (revision 85e9849b69476e2f72984c77384ac73084968d99)
if User.current.logged?
cookies.delete(autologin_cookie_name)
Token.where(["user_id = ? AND action = ?", User.current.id, 'autologin']).delete_all
Token.where(["user_id = ? AND action = ? AND value = ?", User.current.id, 'session', session[:tk]]).delete_all
Token.where(["user_id = ? AND action = ?", User.current.id, 'session']).where(:value => session[:tk]).delete_all
self.logged_user = nil
end
end
app/controllers/versions_controller.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824)
@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)).
order("#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
order("#{Project.table_name}.lft, #{Tracker.table_name}.#{'position'.quote_column_name}, #{Issue.table_name}.id")
@issues_by_version = issues.group_by(&:fixed_version)
end
@versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
}
format.api {
@versions = @project.shared_versions.to_a
......
respond_to do |format|
format.html {
@issues = @version.fixed_issues.visible.
includes(:status, :tracker, :priority).
preload(:project).
reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id").
reorder(Issue.arel_table[:id].asc).
to_a
}
format.api
end
app/helpers/my_helper.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824)
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.table_name}.#{'position'.quote_column_name} DESC, #{Issue.table_name}.updated_on DESC")
end
def issuesreportedbyme_items
......
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.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.#{'position'.quote_column_name} ASC, #{Issue.table_name}.id ASC").
to_a
end
end
app/models/custom_field.rb (revision afb29457dc1ff6f03bbc6ad2650f6abb29285286)
# to move in project_custom_field
def self.for_all
where(:is_for_all => true).order('position').to_a
where(:is_for_all => true).order(:position).to_a
end
def type_name
app/models/enumeration.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824)
class Enumeration < ActiveRecord::Base
include Redmine::SubclassFactory
default_scope lambda {order(:position)}
default_scope lambda { order(:position) }
belongs_to :project
......
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
"#{'position'.quote_column_name} = coalesce((
select #{'position'.quote_column_name}
from (select id, #{'position'.quote_column_name} from enumerations) as parent
where parent_id = parent.id), 1)"
)
end
app/models/issue.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824)
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).maximum("#{IssuePriority.table_name.quote_table_name}.#{'position'.quote_column_name}")
p.priority = IssuePriority.find_by_position(priority_position)
else
p.priority = IssuePriority.default
app/models/issue_query.rb (revision 5f15e39173a0e68d75077ec0dd6c384115079d52)
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.table_name}.#{'position'.quote_column_name}", :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.table_name}.#{'position'.quote_column_name}", :groupable => true),
QueryColumn.new(:priority, :sortable => "#{IssuePriority.table_name}.#{'position'.quote_column_name}", :default_order => 'desc', :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),
app/models/issue_status.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824)
# 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"
" AND d.property = 'attr' AND d.prop_key = 'status_id' AND d.#{'value'.quote_column_name} = :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
app/models/project.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a)
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'
app/models/query.rb (revision 38bf2f2e39072da42354426272d4f58231e1d249)
def sql_for_custom_field(field, operator, value, custom_field_id)
db_table = CustomValue.table_name
db_field = 'value'
db_field = 'value'.quote_column_name
filter = @available_filters[field]
return nil unless filter
if filter[:field].format.target_class && filter[:field].format.target_class <= User
......
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
......
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
......
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
......
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
......
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
......
s = []
if from
if from.is_a?(Date)
if Redmine::Database.firebird?
from = date_for_user_time_zone(from.year, from.month, from.day).yesterday.end_of_day.to_date
else
from = date_for_user_time_zone(from.year, from.month, from.day).yesterday.end_of_day
from = date_for_user_time_zone(from.year, from.month, from.day).yesterday.end_of_day
end
else
from = from - 1 # second
end
......
end
if to
if to.is_a?(Date)
if Redmine::Database.firebird?
to = date_for_user_time_zone(to.year, to.month, to.day).end_of_day.to_date
else
to = date_for_user_time_zone(to.year, to.month, to.day).end_of_day
to = date_for_user_time_zone(to.year, to.month, to.day).end_of_day
end
end
if self.class.default_timezone == :utc
to = to.utc
app/models/repository.rb (revision 85e9849b69476e2f72984c77384ac73084968d99)
# 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(*) as commit_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(*) as commit_count").group("committer, user_id")
user_ids = changesets.map(&:user_id).compact.uniq
authors_names = User.where(:id => user_ids).inject({}) do |memo, user|
......
end
hash[mapped_name] ||= { :commits_count => 0, :changes_count => 0 }
if element.is_a?(Changeset)
hash[mapped_name][:commits_count] += element.count.to_i
hash[mapped_name][:commits_count] += element.commit_count.to_i
else
hash[mapped_name][:changes_count] += element.count.to_i
hash[mapped_name][:changes_count] += element.commit_count.to_i
end
hash
end
app/models/time_entry_query.rb (revision f1ecd5cccd87521ad1197bd7f26c321ca32cf673)
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.table_name}.#{'position'.quote_column_name}", :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.table_name}.#{'position'.quote_column_name}"),
QueryAssociationColumn.new(:issue, :status, :caption => :field_status, :sortable => "#{IssueStatus.table_name}.#{'position'.quote_column_name}"),
QueryColumn.new(:comments),
QueryColumn.new(:hours, :sortable => "#{TimeEntry.table_name}.hours", :totalable => true),
]
app/models/user.rb (revision 85e9849b69476e2f72984c77384ac73084968d99)
# 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',
......
where(["property = 'attr' AND prop_key = 'assigned_to_id' AND old_value = ?", id.to_s]).
update_all(['old_value = ?', substitute.id.to_s])
JournalDetail.
where(["property = 'attr' AND prop_key = 'assigned_to_id' AND value = ?", id.to_s]).
update_all(['value = ?', substitute.id.to_s])
where(["property = 'attr' AND prop_key = 'assigned_to_id'"]).
where(:value => id.to_s).
update_all(:value => substitute.id.to_s)
Message.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id])
News.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id])
# Remove private queries and keep public ones
db/migrate/007_create_journals.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed)
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
db/migrate/072_add_enumerations_position.rb (revision 3064ece372d53807b03ef057c7e8288c03230c94)
Enumeration.all.group_by(&:opt).each do |opt, enums|
enums.each_with_index do |enum, i|
# do not call model callbacks
Enumeration.where({:id => enum.id}).update_all("position = #{i+1}")
Enumeration.where({:id => enum.id}).update_all(:position => (i+1))
end
end
end
db/migrate/078_add_custom_fields_position.rb (revision 3064ece372d53807b03ef057c7e8288c03230c94)
CustomField.all.group_by(&:type).each do |t, fields|
fields.each_with_index do |field, i|
# do not call model callbacks
CustomField.where({:id => field.id}).update_all("position = #{i+1}")
CustomField.where({:id => field.id}).update_all(:position => (i+1))
end
end
end
db/migrate/107_add_open_id_authentication_tables.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed)
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
......
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
db/migrate/20130201184705_add_unique_index_on_tokens_value.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed)
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'
db/migrate/20130215111141_populate_issues_closed_on.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a)
" 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
db/migrate/20141029181824_remove_issue_statuses_is_default.rb (revision 3064ece372d53807b03ef057c7e8288c03230c94)
def down
add_column :issue_statuses, :is_default, :boolean, :null => false, :default => false
# Restores the first status as default
default_status_id = IssueStatus.order("position").pluck(:id).first
default_status_id = IssueStatus.order(:position).pluck(:id).first
IssueStatus.where(:id => default_status_id).update_all(:is_default => true)
end
end
lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a)
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
lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb (revision 02ee4bc8ea2af12e052d8ac1011554c84c4a8c76)
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).
where(search_tokens_condition(["#{CustomValue.table_name}.value"], tokens, options[:all_words])),
where(search_tokens_condition(["#{CustomValue.table_name}.#{'value'.quote_column_name}"], tokens, options[:all_words])),
options[:limit]
)
queries += 1
end
lib/plugins/open_id_authentication/lib/open_id_authentication/association.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed)
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)
lib/redmine/acts/positioned.rb (revision 5f15e39173a0e68d75077ec0dd6c384115079d52)
end
end
def position_column
'position'.quote_column_name
end
def insert_position
position_scope.where("position >= ? AND id <> ?", position, id).update_all("position = position + 1")
position_scope.where("#{position_column} >= ? AND id <> ?", position, id).update_all("#{position_column} = #{position_column} + 1")
end
def remove_position
position_scope_was.where("position >= ? AND id <> ?", position_was, id).update_all("position = position - 1")
position_scope_was.where("#{position_column} >= ? AND id <> ?", position_was, id).update_all("#{position_column} = #{position_column} - 1")
end
def position_scope_changed?
......
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 <> ? AND #{position_column} BETWEEN ? AND ?", id, min, max).update_all("#{position_column} = #{position_column} + #{offset}")
if r != max - min
reset_positions_in_list
end
lib/redmine/core_ext/string.rb (revision 6b2cdbedc5a68e135a73d671064fda452cb58824)
def is_binary_data?
( self.count( "^ -~", "^\r\n" ).fdiv(self.size) > 0.3 || self.index( "\x00" ) ) unless empty?
end
def quote_column_name
ActiveRecord::Base.connection.quote_column_name(self)
end
def quote_table_name
ActiveRecord::Base.connection.quote_table_name(self)
end
end
lib/redmine/database.rb (revision 02ee4bc8ea2af12e052d8ac1011554c84c4a8c76)
(ActiveRecord::Base.connection.adapter_name =~ /mysql/i).present?
end
# Returns +true+ if the database is Firebird or RedDatabase
def firebird?
(ActiveRecord::Base.connection.adapter_name =~ /fb/i).present?
end
# Returns a SQL statement for case/accent (if possible) insensitive match
def like(left, right, options={})
neg = (options[:match] == false ? 'NOT ' : '')
lib/redmine/field_format.rb (revision 5f15e39173a0e68d75077ec0dd6c384115079d52)
# 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
......
" 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" +
......
def join_alias(custom_field)
"cf_#{custom_field.id}"
end
def value_column
'value'.quote_column_name
end
protected :join_alias
end
......
# 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
......
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)
......
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)
......
" 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)
lib/tasks/migrate_from_mantis.rake (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a)
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
lib/tasks/migrate_from_trac.rake (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a)
'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
test/unit/query_test.rb (revision 5f15e39173a0e68d75077ec0dd6c384115079d52)
query = IssueQuery.new(:project => Project.find(1), :name => '_')
query.add_filter('fixed_version_id', '!*', [''])
query.add_filter('cf_1', '!*', [''])
value_col = 'value'.quote_column_name
assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NULL")
assert query.statement.include?("#{CustomValue.table_name}.value IS NULL OR #{CustomValue.table_name}.value = ''")
assert query.statement.include?("#{CustomValue.table_name}.#{value_col} IS NULL OR #{CustomValue.table_name}.#{value_col} = ''")
find_issues_with_query(query)
end
......
query = IssueQuery.new(:project => Project.find(1), :name => '_')
query.add_filter('fixed_version_id', '*', [''])
query.add_filter('cf_1', '*', [''])
value_col = 'value'.quote_column_name
assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NOT NULL")
assert query.statement.include?("#{CustomValue.table_name}.value IS NOT NULL AND #{CustomValue.table_name}.value <> ''")
assert query.statement.include?("#{CustomValue.table_name}.#{value_col} IS NOT NULL AND #{CustomValue.table_name}.#{value_col} <> ''")
find_issues_with_query(query)
end
test/unit/user_test.rb (revision b5fede3e23b04badd3d344f8684450a1e4efccac)
end
def test_own_account_deletable_should_be_false_for_a_single_admin
User.where(["admin = ? AND id <> ?", true, 1]).delete_all
User.where(["id <> ?", 1]).where(:admin => true).delete_all
with_settings :unsubscribe => '1' do
assert_equal false, User.find(1).own_account_deletable?
test/object_helpers.rb (revision afb29457dc1ff6f03bbc6ad2650f6abb29285286)
@generated_tracker_name.succ!
tracker = Tracker.new(attributes)
tracker.name = @generated_tracker_name.dup if tracker.name.blank?
tracker.default_status ||= IssueStatus.order('position').first || IssueStatus.generate!
tracker.default_status ||= IssueStatus.order(:position).first || IssueStatus.generate!
yield tracker if block_given?
tracker
end
(3-3/11)