Project

General

Profile

Feature #38423 ยป 38423.patch

Go MAEDA, 2023-04-10 17:30

View differences:

app/models/query.rb
"!p" => :label_no_issues_in_project,
"*o" => :label_any_open_issues,
"!o" => :label_no_open_issues,
"/" => :label_matches_regexp
}
class_attribute :operators_by_filter_type
......
:list_subprojects => [ "*", "!*", "=", "!" ],
:date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "nd", "t", "ld", "nw", "w", "lw", "l2w", "nm", "m", "lm", "y", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
:date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "!*", "*" ],
:string => [ "~", "=", "!~", "!", "^", "$", "!*", "*" ],
:text => [ "~", "!~", "^", "$", "!*", "*" ],
:string => [ "~", "=", "/", "!~", "!", "^", "$", "!*", "*" ],
:text => [ "~", "/", "!~", "^", "$", "!*", "*" ],
:search => [ "~", "!~" ],
:integer => [ "=", ">=", "<=", "><", "!*", "*" ],
:float => [ "=", ">=", "<=", "><", "!*", "*" ],
:relation => ["=", "!", "=p", "=!p", "!p", "*o", "!o", "!*", "*"],
:tree => ["=", "~", "!*", "*"]
}
unless Redmine::Database.supports_regexp?
operators_by_filter_type[:string].delete('/')
operators_by_filter_type[:text].delete('/')
end
class_attribute :available_columns
self.available_columns = []
......
sql = sql_contains("#{db_table}.#{db_field}", value.first, :starts_with => true)
when "$"
sql = sql_contains("#{db_table}.#{db_field}", value.first, :ends_with => true)
when "/"
operator = Redmine::Database.regexp_operator
unless operator.nil?
sql = queried_class.send(:sanitize_sql_for_conditions, ["#{db_table}.#{db_field} #{operator} ?", value])
end
else
raise QueryError, "Unknown query operator #{operator}"
end
config/locales/en.yml
label_not_contains: doesn't contain
label_starts_with: starts with
label_ends_with: ends with
label_matches_regexp: matches regexp
label_any_issues_in_project: any issues in project
label_any_issues_not_in_project: any issues not in project
label_no_issues_in_project: no issues in project
lib/redmine/database.rb
/mysql/i.match?(ActiveRecord::Base.connection.adapter_name)
end
# Returns the MysQL version or nil if another DBMS is used
def mysql_version
mysql? ? ActiveRecord::Base.connection.select_value('SELECT VERSION()').to_s : nil
end
# Returns a SQL statement for case/accent (if possible) insensitive match
def like(left, right, options={})
neg = (options[:match] == false ? 'NOT ' : '')
......
def reset
@postgresql_unaccent = nil
end
# Returns true if the database supports regular expressions
def supports_regexp?
regexp_operator.present?
end
# Returns the regexp operator for the current database
# MySQL 8.0.4+ and PostgreSQL are supported
def regexp_operator
@regexp_operator ||=
if mysql? && Gem::Version.new(mysql_version) >= Gem::Version.new('8.0.4')
'REGEXP'
elsif postgresql?
'~*'
else
nil
end
end
end
end
end
test/unit/query_test.rb
assert_not_include issue, result
end
def test_operator_regexp
skip unless Redmine::Database.supports_regexp?
regexp_str = '(Recipes{0,1}|ingred.ents)'
query = IssueQuery.new(:name => '_')
query.add_filter('subject', '/', [regexp_str])
result = find_issues_with_query(query)
assert_equal [1, 2, 3], result.map(&:id).sort
result.each {|issue| assert issue.subject =~ /#{regexp_str}/i}
end
def test_range_for_this_week_with_week_starting_on_monday
I18n.locale = :fr
assert_equal '1', I18n.t(:general_first_day_of_week)
    (1-1/1)