fix folders with leading spaces as well as trailing ones
closes #CNVS-27257 Change-Id: I21f88c87400cda576f233c57b88026995bf391b5 Reviewed-on: https://gerrit.instructure.com/72224 Tested-by: Jenkins Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Product-Review: James Williams <jamesw@instructure.com> QA-Review: James Williams <jamesw@instructure.com>
This commit is contained in:
parent
0334f92761
commit
ab75744a6f
|
@ -147,7 +147,7 @@ class Folder < ActiveRecord::Base
|
|||
# TODO i18n
|
||||
t :default_folder_name, 'New Folder'
|
||||
self.name = 'New Folder' if self.name.blank?
|
||||
self.name = self.name.rstrip.gsub(/\//, "_")
|
||||
self.name = self.name.strip.gsub(/\//, "_")
|
||||
folder = self
|
||||
@update_sub_folders = false
|
||||
self.parent_folder_id = nil if !self.parent_folder || self.parent_folder.context != self.context || self.parent_folder_id == self.id
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class FixFolderNames < ActiveRecord::Migration
|
||||
class FixFolderNamesAgain < ActiveRecord::Migration
|
||||
tag :postdeploy
|
||||
def up
|
||||
DataFixup::FixFolderNames.send_later_if_production_enqueue_args(:run,
|
|
@ -1,9 +1,14 @@
|
|||
module DataFixup
|
||||
module FixFolderNames
|
||||
def self.run
|
||||
wildcards = []
|
||||
[" ", "\t", "\r", "\n"].each do |ws|
|
||||
wildcards += ["#{ws}%", "%#{ws}"]
|
||||
end
|
||||
|
||||
Folder.find_ids_in_ranges(:batch_size => 10000) do |min_id, max_id|
|
||||
Folder.active.where(:id => min_id..max_id).where("name LIKE ?", "% ").each do |f|
|
||||
f.name = f.name.rstrip
|
||||
Folder.active.where(:id => min_id..max_id).where((["(name LIKE ?)"] * wildcards.count).join(" OR "), *wildcards).each do |f|
|
||||
f.name = f.name.strip
|
||||
f.save
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue