fixes #2198
This commit is contained in:
@@ -8,7 +8,7 @@ class AliasAndImplicationImporter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def process!
|
def process!
|
||||||
tokens = tokenize(text)
|
tokens = AliasAndImplicationImporter.tokenize(text)
|
||||||
parse(tokens)
|
parse(tokens)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -16,9 +16,8 @@ class AliasAndImplicationImporter
|
|||||||
@rename_aliased_pages == "1"
|
@rename_aliased_pages == "1"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def self.tokenize(text)
|
||||||
|
text = text.dup
|
||||||
def tokenize(text)
|
|
||||||
text.gsub!(/^\s+/, "")
|
text.gsub!(/^\s+/, "")
|
||||||
text.gsub!(/\s+$/, "")
|
text.gsub!(/\s+$/, "")
|
||||||
text.gsub!(/ {2,}/, " ")
|
text.gsub!(/ {2,}/, " ")
|
||||||
@@ -41,6 +40,8 @@ private
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def parse(tokens)
|
def parse(tokens)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
tokens.map do |token|
|
tokens.map do |token|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class BulkUpdateRequest < ActiveRecord::Base
|
|||||||
validates_presence_of :script
|
validates_presence_of :script
|
||||||
validates_presence_of :title
|
validates_presence_of :title
|
||||||
validates_inclusion_of :status, :in => %w(pending approved rejected)
|
validates_inclusion_of :status, :in => %w(pending approved rejected)
|
||||||
|
validate :script_formatted_correctly
|
||||||
attr_accessible :user_id, :forum_topic_id, :script, :title, :reason
|
attr_accessible :user_id, :forum_topic_id, :script, :title, :reason
|
||||||
attr_accessible :status, :as => [:admin]
|
attr_accessible :status, :as => [:admin]
|
||||||
before_validation :initialize_attributes, :on => :create
|
before_validation :initialize_attributes, :on => :create
|
||||||
@@ -35,4 +36,12 @@ class BulkUpdateRequest < ActiveRecord::Base
|
|||||||
self.user_id = CurrentUser.user.id unless self.user_id
|
self.user_id = CurrentUser.user.id unless self.user_id
|
||||||
self.status = "pending"
|
self.status = "pending"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def script_formatted_correctly
|
||||||
|
AliasAndImplicationImporter.tokenize(script)
|
||||||
|
return true
|
||||||
|
rescue StandardError => e
|
||||||
|
errors.add(:base, e.message)
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user