Merge pull request #5952 from Supermathie/remap_enhance

DbHelper.remap/find: add option to anchor at left/right of the column value
This commit is contained in:
Michael Brown 2018-06-11 15:15:17 -04:00 committed by GitHub
commit 8d92c73aad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,10 +8,10 @@ class DbHelper
AND (data_type LIKE 'char%' OR data_type LIKE 'text%')
ORDER BY table_name, column_name"
def self.remap(from, to)
def self.remap(from, to, anchor_left = false, anchor_right = false)
connection = ActiveRecord::Base.connection.raw_connection
remappable_columns = connection.async_exec(REMAP_SQL).to_a
args = [from, to, "%#{from}%"]
args = [from, to, "#{anchor_left ? '' : "%"}#{from}#{anchor_right ? '' : "%"}"]
remappable_columns.each do |rc|
table_name = rc["table_name"]
@ -22,10 +22,10 @@ class DbHelper
SiteSetting.refresh!
end
def self.find(needle)
def self.find(needle, anchor_left = false, anchor_right = false)
connection = ActiveRecord::Base.connection.raw_connection
text_columns = connection.async_exec(REMAP_SQL).to_a
args = ["%#{needle}%"]
args = ["#{anchor_left ? '' : "%"}#{needle}#{anchor_right ? '' : "%"}"]
found = {}
text_columns.each do |rc|