Feature #24013 » current_trunk_Firebird_and_RedDatabase_support.patch
| app/models/user.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
# 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(:admin => true, :id => id).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', :prop_key => 'assigned_to_id', :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
|
||
| app/models/issue.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
if p.priority_derived?
|
||
|
# priority = highest priority of open children
|
||
|
# priority is left unchanged if all children are closed and there's no default priority defined
|
||
|
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}.#{'position'.quote_column_name}")
|
||
|
p.priority = IssuePriority.find_by_position(priority_position)
|
||
|
elsif default_priority = IssuePriority.default
|
||
|
p.priority = default_priority
|
||
| app/models/query.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
json = {}
|
||
|
available_filters.each do |field, filter|
|
||
|
options = {:type => filter[:type], :name => filter[:name]}
|
||
|
next if filter.is_a?(Hash)
|
||
|
options[:remote] = true if filter.remote
|
||
|
|
||
|
if has_filter?(field) || !filter.remote
|
||
| ... | ... | |
|
end
|
||
|
|
||
|
def sql_for_custom_field(field, operator, value, custom_field_id)
|
||
|
db_table = CustomValue.table_name
|
||
|
db_field = 'value'
|
||
|
db_table = CustomValue.table_name.quote_table_name
|
||
|
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
|
||
| ... | ... | |
|
filter = available_filters[field]
|
||
|
target_class = filter[:through].format.target_class
|
||
|
|
||
|
value_col = 'value'.quote_column_name
|
||
|
|
||
|
"#{queried_table_name}.id #{not_in} IN (" +
|
||
|
"SELECT customized_id FROM #{CustomValue.table_name}" +
|
||
|
" WHERE customized_type='#{queried_class}' AND custom_field_id=#{custom_field_id}" +
|
||
|
" AND CAST(CASE value WHEN '' THEN '0' ELSE value END AS decimal(30,0)) IN (" +
|
||
|
" AND CAST(CASE #{value_col} WHEN '' THEN '0' ELSE #{value_col} END AS decimal(30,0)) IN (" +
|
||
|
" SELECT customized_id FROM #{CustomValue.table_name}" +
|
||
|
" WHERE customized_type='#{target_class}' AND custom_field_id=#{chained_custom_field_id}" +
|
||
|
" AND #{sql_for_field(field, operator, value, CustomValue.table_name, 'value')}))"
|
||
|
" AND #{sql_for_field(field, operator, value, CustomValue.table_name, value_col)}))"
|
||
|
|
||
|
end
|
||
|
|
||
| ... | ... | |
|
filter = available_filters[field]
|
||
|
target_table_name = filter[:field].format.target_class.table_name
|
||
|
|
||
|
value_col = 'value'.quote_column_name
|
||
|
|
||
|
"#{queried_table_name}.id #{not_in} IN (" +
|
||
|
"SELECT customized_id FROM #{CustomValue.table_name}" +
|
||
|
" WHERE customized_type='#{queried_class}' AND custom_field_id=#{custom_field_id}" +
|
||
|
" AND CAST(CASE value WHEN '' THEN '0' ELSE value END AS decimal(30,0)) IN (" +
|
||
|
" AND CAST(CASE #{value_col} WHEN '' THEN '0' ELSE #{value_col} END AS decimal(30,0)) IN (" +
|
||
|
" SELECT id FROM #{target_table_name} WHERE #{sql_for_field(field, operator, value, filter[:field].format.target_class.table_name, attribute)}))"
|
||
|
end
|
||
|
|
||
| app/models/member.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
# Sort by first role and principal
|
||
|
scope :sorted, lambda {
|
||
|
includes(:member_roles, :roles, :principal).
|
||
|
reorder("#{Role.table_name}.position").
|
||
|
reorder("#{Role.table_name}.#{'position'.quote_column_name}").
|
||
|
order(Principal.fields_for_order_statement)
|
||
|
}
|
||
|
scope :sorted_by_project, lambda {
|
||
| app/models/project.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
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.table_name}.#{'position'.quote_column_name}")},
|
||
|
:class_name => 'IssueCustomField',
|
||
|
:join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
|
||
|
:association_foreign_key => 'custom_field_id'
|
||
| app/helpers/my_helper.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
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
|
||
|
|
||
|
return entries, days
|
||
| app/models/enumeration.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
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_query.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
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 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
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
|
||
|
|
||
|
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}])
|
||
|
|
||
|
# Then we update issues that don't have a journal which means the
|
||
|
# current status was set on creation
|
||
| lib/redmine/field_format.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
# 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'.quote_column_name}, '')"
|
||
|
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'.quote_column_name} <> ''" +
|
||
|
" 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" +
|
||
| ... | ... | |
|
# 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))"
|
||
|
value_col = 'value'.quote_column_name
|
||
|
"CAST(CASE #{join_alias custom_field}.#{value_col} WHEN '' THEN '0' ELSE #{join_alias custom_field}.#{value_col} END AS decimal(30,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'.quote_column_name} AS decimal(30,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'.quote_column_name}, '')"
|
||
|
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(30,0)) = #{value_join_alias custom_field}.id"
|
||
|
end
|
||
|
|
||
|
def value_join_alias(custom_field)
|
||
|
join_alias(custom_field) + "_" + custom_field.field_format
|
||
|
end
|
||
|
protected :value_join_alias
|
||
|
|
||
|
def value_column
|
||
|
'value'.quote_column_name
|
||
|
end
|
||
|
protected :value_column
|
||
|
end
|
||
|
|
||
|
class EnumerationFormat < RecordList
|
||
| app/models/time_entry_query.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
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),
|
||
|
]
|
||
| lib/redmine/acts/positioned.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
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 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
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
|
||
| app/controllers/projects_controller.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
def destroy
|
||
|
@project_to_destroy = @project
|
||
|
if api_request? || params[:confirm]
|
||
|
@project_to_destroy.destroy
|
||
|
@project_to_destroy.delete
|
||
|
respond_to do |format|
|
||
|
format.html { redirect_to admin_projects_path }
|
||
|
format.api { render_api_ok }
|
||
| app/controllers/versions_controller.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
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?}
|
||
| ... | ... | |
|
@issues = @version.fixed_issues.visible.
|
||
|
includes(:status, :tracker, :priority).
|
||
|
preload(:project).
|
||
|
reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id").
|
||
|
reorder("#{Tracker.table_name}.#{'position'.quote_column_name}, #{Issue.table_name}.id").
|
||
|
to_a
|
||
|
}
|
||
|
format.api
|
||
| app/models/custom_field_enumeration.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
|
||
|
def self.fields_for_order_statement(table=nil)
|
||
|
table ||= table_name
|
||
|
columns = ['position']
|
||
|
columns = ['position'.quote_column_name]
|
||
|
columns.uniq.map {|field| "#{table}.#{field}"}
|
||
|
end
|
||
|
|
||
| app/controllers/application_controller.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
def logout_user
|
||
|
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 => User.current.id, :action => 'autologin').delete_all
|
||
|
Token.where(:user_id => User.current.id, :action => 'session', :value => session[:tk]).delete_all
|
||
|
self.logged_user = nil
|
||
|
end
|
||
|
end
|
||
| lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
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
|
||
| lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
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,
|
||
|
:inverse_of => :customized,
|
||
|
:dependent => :delete_all,
|
||
| db/migrate/20130201184705_add_unique_index_on_tokens_value.rb (revision 7efc8b6462a0dd33ff88b788712d76fec02b0a4c) | ||
|---|---|---|
|
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'
|
||