mirror of
https://github.com/hanzoai/forum.git
synced 2026-09-30 21:51:19 +00:00
DEV: Update to lastest rubocop-discourse
This commit is contained in:
committed by
Loïc Guitaut
parent
c4c3e8d40e
commit
db1c19d472
@@ -1853,7 +1853,7 @@ class BulkImport::Base
|
||||
end
|
||||
|
||||
def normalize_text(text)
|
||||
return nil unless text.present?
|
||||
return nil if text.blank?
|
||||
@html_entities.decode(normalize_charset(text.presence || "").scrub)
|
||||
end
|
||||
|
||||
|
||||
@@ -910,7 +910,7 @@ class BulkImport::DiscourseMerger < BulkImport::Base
|
||||
end
|
||||
|
||||
def process_post_action(post_action)
|
||||
return nil unless post_action["post_id"].present?
|
||||
return nil if post_action["post_id"].blank?
|
||||
post_action["related_post_id"] = post_id_from_imported_id(post_action["related_post_id"])
|
||||
post_action["deferred_by_id"] = user_id_from_imported_id(post_action["deferred_by_id"])
|
||||
post_action["agreed_by_id"] = user_id_from_imported_id(post_action["agreed_by_id"])
|
||||
@@ -969,7 +969,7 @@ class BulkImport::DiscourseMerger < BulkImport::Base
|
||||
end
|
||||
|
||||
def process_group_archived_message(gam)
|
||||
return nil unless gam["topic_id"].present? && gam["group_id"].present?
|
||||
return nil if gam["topic_id"].blank? || gam["group_id"].blank?
|
||||
gam
|
||||
end
|
||||
|
||||
@@ -990,14 +990,12 @@ class BulkImport::DiscourseMerger < BulkImport::Base
|
||||
user_avatar["gravatar_upload_id"] = upload_id_from_imported_id(
|
||||
user_avatar["gravatar_upload_id"],
|
||||
) if user_avatar["gravatar_upload_id"]
|
||||
unless user_avatar["custom_upload_id"].present? || user_avatar["gravatar_upload_id"].present?
|
||||
return nil
|
||||
end
|
||||
return nil if user_avatar["custom_upload_id"].blank? && user_avatar["gravatar_upload_id"].blank?
|
||||
user_avatar
|
||||
end
|
||||
|
||||
def process_user_history(user_history)
|
||||
return nil unless user_history["group_id"].present?
|
||||
return nil if user_history["group_id"].blank?
|
||||
user_history["acting_user_id"] = user_id_from_imported_id(
|
||||
user_history["acting_user_id"],
|
||||
) if user_history["acting_user_id"]
|
||||
@@ -1011,7 +1009,7 @@ class BulkImport::DiscourseMerger < BulkImport::Base
|
||||
user_warning["created_by_id"] = user_id_from_imported_id(
|
||||
user_warning["created_by_id"],
|
||||
) if user_warning["created_by_id"]
|
||||
return nil unless user_warning["created_by_id"].present?
|
||||
return nil if user_warning["created_by_id"].blank?
|
||||
user_warning
|
||||
end
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ class BulkImport::Generic < BulkImport::Base
|
||||
when "append"
|
||||
raise "Cannot append to #{name} setting" if setting[:type] != "list"
|
||||
items = (SiteSetting.get(name) || "").split("|")
|
||||
items << row["value"] unless items.include?(row["value"])
|
||||
items << row["value"] if items.exclude?(row["value"])
|
||||
SiteSetting.set_and_log(name, items.join("|"))
|
||||
end
|
||||
end
|
||||
@@ -2287,7 +2287,7 @@ class BulkImport::Generic < BulkImport::Base
|
||||
|
||||
rows.each do |row|
|
||||
normalization = row["normalization"]
|
||||
normalizations << normalization unless normalizations.include?(normalization)
|
||||
normalizations << normalization if normalizations.exclude?(normalization)
|
||||
end
|
||||
|
||||
SiteSetting.permalink_normalizations = normalizations.join("|")
|
||||
|
||||
@@ -114,7 +114,7 @@ module BulkImport
|
||||
producer_thread =
|
||||
Thread.new do
|
||||
query("SELECT * FROM uploads ORDER BY id", @source_db).tap do |result_set|
|
||||
result_set.each { |row| queue << row unless output_existing_ids.include?(row["id"]) }
|
||||
result_set.each { |row| queue << row if output_existing_ids.exclude?(row["id"]) }
|
||||
result_set.close
|
||||
end
|
||||
end
|
||||
@@ -612,7 +612,7 @@ module BulkImport
|
||||
begin
|
||||
if optimized_images.present?
|
||||
optimized_images.map! do |optimized_image|
|
||||
next unless optimized_image.present?
|
||||
next if optimized_image.blank?
|
||||
optimized_image_path =
|
||||
add_multisite_prefix(store.get_path_for_optimized_image(optimized_image))
|
||||
|
||||
|
||||
@@ -227,7 +227,7 @@ class BulkImport::Vanilla < BulkImport::Base
|
||||
).first
|
||||
next if r.nil?
|
||||
photo = r["photo"]
|
||||
next unless photo.present?
|
||||
next if photo.blank?
|
||||
|
||||
# Possible encoded values:
|
||||
# 1. cf://uploads/userpics/820/Y0AFUQYYM6QN.jpg
|
||||
@@ -305,7 +305,7 @@ class BulkImport::Vanilla < BulkImport::Base
|
||||
next if r.nil?
|
||||
path = r["Path"]
|
||||
name = r["Name"]
|
||||
next unless path.present?
|
||||
next if path.blank?
|
||||
|
||||
path.gsub!("s3://content/", "")
|
||||
path.gsub!("s3://uploads/", "")
|
||||
|
||||
@@ -640,9 +640,9 @@ class BulkImport::VBulletin < BulkImport::Base
|
||||
next if item == (".") || item == ("..") || item == (".DS_Store")
|
||||
next unless item =~ /avatar(\d+)_(\d).gif/
|
||||
scan = item.scan(/avatar(\d+)_(\d).gif/)
|
||||
next unless scan[0][0].present?
|
||||
next if scan[0][0].blank?
|
||||
u = UserCustomField.find_by(name: "import_id", value: scan[0][0]).try(:user)
|
||||
next unless u.present?
|
||||
next if u.blank?
|
||||
# raise "User not found for id #{user_id}" if user.blank?
|
||||
|
||||
photo_real_filename = File.join(AVATAR_DIR, item)
|
||||
@@ -686,10 +686,10 @@ class BulkImport::VBulletin < BulkImport::Base
|
||||
print_status current_count, total_count
|
||||
user_id = sig[0]
|
||||
user_sig = sig[1]
|
||||
next unless user_id.present? && user_sig.present?
|
||||
next if user_id.blank? || user_sig.blank?
|
||||
|
||||
u = UserCustomField.find_by(name: "import_id", value: user_id).try(:user)
|
||||
next unless u.present?
|
||||
next if u.blank?
|
||||
|
||||
# can not hold dupes
|
||||
UserCustomField.where(
|
||||
|
||||
@@ -29,7 +29,7 @@ File
|
||||
.each_line do |line|
|
||||
parsed = JSON.parse(line)
|
||||
if parsed && parsed["address"]
|
||||
diff << parsed unless origs.include? parsed["address"]
|
||||
diff << parsed if origs.exclude? parsed["address"]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -318,7 +318,7 @@ class ImportScripts::Answerbase < ImportScripts::Base
|
||||
end
|
||||
|
||||
def add_normalization(normalizations, normalization)
|
||||
normalizations << normalization unless normalizations.include?(normalization)
|
||||
normalizations << normalization if normalizations.exclude?(normalization)
|
||||
end
|
||||
|
||||
def permalink_exists?(url)
|
||||
|
||||
@@ -155,7 +155,7 @@ class ImportScripts::MyAskBot < ImportScripts::Base
|
||||
cat = nil
|
||||
if tags
|
||||
CATEGORIES.each do |cname|
|
||||
next unless tags.include?(cname.downcase)
|
||||
next if tags.exclude?(cname.downcase)
|
||||
cat = cname
|
||||
break
|
||||
end
|
||||
|
||||
@@ -994,7 +994,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
|
||||
next
|
||||
end
|
||||
html = html_for_upload(upload, filename)
|
||||
unless new_raw.include? html
|
||||
if new_raw.exclude? html
|
||||
new_raw << "\n"
|
||||
new_raw << html
|
||||
end
|
||||
|
||||
@@ -73,7 +73,7 @@ class ImportScripts::Disqus < ImportScripts::Base
|
||||
if post.present? && post.topic.posts_count <= 1
|
||||
(t[:posts] || []).each do |p|
|
||||
post_user = find_existing_user(p[:author_email] || "", p[:author_username])
|
||||
next unless post_user.present?
|
||||
next if post_user.blank?
|
||||
|
||||
attrs = {
|
||||
user_id: post_user.id,
|
||||
|
||||
@@ -383,7 +383,7 @@ class ImportScripts::Drupal < ImportScripts::Base
|
||||
end
|
||||
|
||||
upload_html = html_for_upload(upload, filename)
|
||||
new_raw = "#{new_raw}\n\n#{upload_html}" unless new_raw.include?(upload_html)
|
||||
new_raw = "#{new_raw}\n\n#{upload_html}" if new_raw.exclude?(upload_html)
|
||||
|
||||
if new_raw != post.raw
|
||||
PostRevisor.new(post).revise!(
|
||||
|
||||
@@ -188,7 +188,7 @@ class ImportScripts::Jive < ImportScripts::Base
|
||||
rows = []
|
||||
|
||||
csv_parse("communities") do |row|
|
||||
next unless CATEGORY_IDS.include?(row.communityid.to_i)
|
||||
next if CATEGORY_IDS.exclude?(row.communityid.to_i)
|
||||
rows << { id: row.communityid, name: "#{row.name} (#{row.communityid})" }
|
||||
end
|
||||
|
||||
@@ -261,7 +261,7 @@ class ImportScripts::Jive < ImportScripts::Base
|
||||
thread_map = {}
|
||||
|
||||
csv_parse("messages") do |thread|
|
||||
next unless CATEGORY_IDS.include?(thread.containerid.to_i)
|
||||
next if CATEGORY_IDS.exclude?(thread.containerid.to_i)
|
||||
|
||||
if !thread.parentmessageid
|
||||
# topic
|
||||
@@ -329,7 +329,7 @@ class ImportScripts::Jive < ImportScripts::Base
|
||||
csv_parse("messages") do |thread|
|
||||
# post
|
||||
|
||||
next unless CATEGORY_IDS.include?(thread.containerid.to_i)
|
||||
next if CATEGORY_IDS.exclude?(thread.containerid.to_i)
|
||||
|
||||
if thread.parentmessageid
|
||||
#IMAGE UPLOADER
|
||||
|
||||
@@ -75,7 +75,7 @@ class ImportScripts::Kunena < ImportScripts::Base
|
||||
results =
|
||||
@client.query("SELECT id, username, email, registerDate FROM jos_users;", cache_rows: false)
|
||||
results.each do |u|
|
||||
next unless u["id"].to_i > (0) && u["username"].present? && u["email"].present?
|
||||
next if u["id"].to_i <= (0) || u["username"].blank? || u["email"].blank?
|
||||
username = u["username"].gsub(" ", "_").gsub(/[^A-Za-z0-9_]/, "")[0, User.username_length.end]
|
||||
if username.length < User.username_length.first
|
||||
username = username * User.username_length.first
|
||||
|
||||
@@ -94,7 +94,7 @@ class ImportScripts::Kunena < ImportScripts::Base
|
||||
cache_rows: false,
|
||||
)
|
||||
results.each do |u|
|
||||
next unless u["id"].to_i > (0) && u["username"].present? && u["email"].present?
|
||||
next if u["id"].to_i <= (0) || u["username"].blank? || u["email"].blank?
|
||||
username = u["username"].gsub(" ", "_").gsub(/[^A-Za-z0-9_]/, "")[0, User.username_length.end]
|
||||
if username.length < User.username_length.first
|
||||
username = username * User.username_length.first
|
||||
|
||||
@@ -218,7 +218,7 @@ module ImportScripts::Mbox
|
||||
end
|
||||
|
||||
def read_mail_from_string(raw_message)
|
||||
unless raw_message.blank?
|
||||
if raw_message.present?
|
||||
Email::Receiver.new(raw_message, convert_plaintext: true, skip_trimming: false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -224,7 +224,7 @@ class ImportScripts::MylittleforumSQL < ImportScripts::Base
|
||||
raw = clean_up(discussion["Body"])
|
||||
|
||||
youtube = nil
|
||||
unless discussion["youtube"].blank?
|
||||
if discussion["youtube"].present?
|
||||
youtube = clean_youtube(discussion["youtube"])
|
||||
raw += "\n#{youtube}\n"
|
||||
print_warning(raw)
|
||||
@@ -286,7 +286,7 @@ class ImportScripts::MylittleforumSQL < ImportScripts::Base
|
||||
next if comment["Body"].blank?
|
||||
raw = clean_up(comment["Body"])
|
||||
youtube = nil
|
||||
unless comment["youtube"].blank?
|
||||
if comment["youtube"].present?
|
||||
youtube = clean_youtube(comment["youtube"])
|
||||
raw += "\n#{youtube}\n"
|
||||
end
|
||||
|
||||
@@ -136,7 +136,7 @@ module ImportScripts::PhpBB3
|
||||
# This appears to be a reply. Let's try to find the Discourse topic_id for this message.
|
||||
parent_msg_id = get_import_id(row[:root_msg_id])
|
||||
parent = @lookup.topic_lookup_from_imported_post_id(parent_msg_id)
|
||||
parent[:topic_id] unless parent.blank?
|
||||
parent[:topic_id] if parent.present?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ module ImportScripts::PhpBB3
|
||||
normalization = "/#{prefix.gsub("/", '\/')}\\#{normalization}"
|
||||
end
|
||||
|
||||
normalizations << normalization unless normalizations.include?(normalization)
|
||||
normalizations << normalization if normalizations.exclude?(normalization)
|
||||
end
|
||||
|
||||
def permalink_exists(url)
|
||||
|
||||
@@ -38,7 +38,7 @@ class ImportScripts::Sfn < ImportScripts::Base
|
||||
@external_users = {}
|
||||
|
||||
CSV.foreach("/Users/zogstrip/Desktop/sfn.csv", col_sep: ";") do |row|
|
||||
next unless @personify_id_to_contact_key.include?(row[0])
|
||||
next if @personify_id_to_contact_key.exclude?(row[0])
|
||||
|
||||
id = @personify_id_to_contact_key[row[0]]
|
||||
full_name = [row[1].strip, row[2].strip, row[3].strip].join(" ").strip
|
||||
|
||||
@@ -278,7 +278,7 @@ class ImportScripts::Smf2 < ImportScripts::Base
|
||||
attachment[:file_hash],
|
||||
attachment[:filename],
|
||||
)
|
||||
raise "Attachment for post #{post[:id]} failed: #{attachment[:filename]}" unless path.present?
|
||||
raise "Attachment for post #{post[:id]} failed: #{attachment[:filename]}" if path.blank?
|
||||
upload = create_upload(post[:user_id], path, attachment[:filename])
|
||||
unless upload.persisted?
|
||||
raise "Attachment for post #{post[:id]} failed: #{upload.errors.full_messages.join(", ")}"
|
||||
@@ -378,7 +378,7 @@ class ImportScripts::Smf2 < ImportScripts::Base
|
||||
pattern, emitter = *p
|
||||
body.gsub!(pattern) do |s|
|
||||
next s if (num = $~[:num].to_i - 1) < 0
|
||||
next s unless (upload = attachments[num]).present?
|
||||
next s if (upload = attachments[num]).blank?
|
||||
use_count[num] += 1
|
||||
instance_exec(upload, &emitter)
|
||||
end
|
||||
|
||||
@@ -888,7 +888,7 @@ class ImportScripts::Telligent < ImportScripts::Base
|
||||
end
|
||||
|
||||
def add_normalization(normalizations, normalization)
|
||||
normalizations << normalization unless normalizations.include?(normalization)
|
||||
normalizations << normalization if normalizations.exclude?(normalization)
|
||||
end
|
||||
|
||||
def batches
|
||||
|
||||
@@ -166,7 +166,7 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
|
||||
).first
|
||||
next if r.nil?
|
||||
photo = r["photo"]
|
||||
next unless photo.present?
|
||||
next if photo.blank?
|
||||
|
||||
# Possible encoded values:
|
||||
# 1. cf://uploads/userpics/820/Y0AFUQYYM6QN.jpg
|
||||
@@ -642,7 +642,7 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
|
||||
next if r.nil?
|
||||
path = r["Path"]
|
||||
name = r["Name"]
|
||||
next unless path.present?
|
||||
next if path.blank?
|
||||
|
||||
path.gsub!("s3://content/", "")
|
||||
path.gsub!("s3://uploads/", "")
|
||||
|
||||
@@ -107,7 +107,7 @@ class ImportScripts::Yammer < ImportScripts::Base
|
||||
csv_parse("Messages") do |row|
|
||||
next unless row[:thread_id] == row[:id]
|
||||
next if row[:in_private_conversation] == "true"
|
||||
next unless row[:deleted_at].blank?
|
||||
next if row[:deleted_at].present?
|
||||
# next if row[:message_type] == 'system'
|
||||
title = ""
|
||||
url = ""
|
||||
@@ -119,7 +119,7 @@ class ImportScripts::Yammer < ImportScripts::Base
|
||||
url = Regexp.last_match(2)
|
||||
title = Regexp.last_match(3) if Regexp.last_match(3)
|
||||
description = Regexp.last_match(4)
|
||||
raw += "\n***\n#{description}\n#{url}\n" unless raw.include?(url)
|
||||
raw += "\n***\n#{description}\n#{url}\n" if raw.exclude?(url)
|
||||
end
|
||||
row[:attachments].match(/uploadedfile:(\d*)$/) do
|
||||
file_id = Regexp.last_match(1).to_i
|
||||
@@ -148,7 +148,7 @@ class ImportScripts::Yammer < ImportScripts::Base
|
||||
csv_parse("Messages") do |row|
|
||||
next unless row[:thread_id] == row[:id]
|
||||
next unless row[:in_private_conversation] == "true"
|
||||
next unless row[:deleted_at].blank?
|
||||
next if row[:deleted_at].present?
|
||||
# next if row[:message_type] == 'system'
|
||||
title = ""
|
||||
url = ""
|
||||
@@ -160,7 +160,7 @@ class ImportScripts::Yammer < ImportScripts::Base
|
||||
url = Regexp.last_match(2)
|
||||
title = Regexp.last_match(3) if Regexp.last_match(3)
|
||||
description = Regexp.last_match(4)
|
||||
raw += "\n***\n#{description}\n#{url}\n" unless raw.include?(url)
|
||||
raw += "\n***\n#{description}\n#{url}\n" if raw.exclude?(url)
|
||||
end
|
||||
row[:attachments].match(/uploadedfile:(\d*)$/) do
|
||||
file_id = Regexp.last_match(1).to_i
|
||||
@@ -189,7 +189,7 @@ class ImportScripts::Yammer < ImportScripts::Base
|
||||
# get posts from messages
|
||||
csv_parse("Messages") do |row|
|
||||
next if row[:thread_id] == row[:id]
|
||||
next unless row[:deleted_at].blank?
|
||||
next if row[:deleted_at].present?
|
||||
next if row[:in_private_conversation] == "true"
|
||||
@db.insert_post(
|
||||
id: row[:id],
|
||||
@@ -204,7 +204,7 @@ class ImportScripts::Yammer < ImportScripts::Base
|
||||
# get pm posts from messages
|
||||
csv_parse("Messages") do |row|
|
||||
next if row[:thread_id] == row[:id]
|
||||
next unless row[:deleted_at].blank?
|
||||
next if row[:deleted_at].present?
|
||||
next unless row[:in_private_conversation] == "false"
|
||||
@db.insert_pm_post(
|
||||
id: row[:id],
|
||||
|
||||
@@ -79,7 +79,7 @@ class ImportScripts::Zoho < ImportScripts::Base
|
||||
@all_posts << row.dup
|
||||
@categories[row.forum_name] = [] if @categories[row.forum_name].nil?
|
||||
|
||||
unless @categories[row.forum_name].include?(row.category_name)
|
||||
if @categories[row.forum_name].exclude?(row.category_name)
|
||||
@categories[row.forum_name] << row.category_name
|
||||
end
|
||||
end
|
||||
|
||||
@@ -38,7 +38,7 @@ end
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
||||
|
||||
unless %w[profile development].include? Rails.env
|
||||
if %w[profile development].exclude? Rails.env
|
||||
puts "Bad idea to run a script that inserts random posts in any non development environment"
|
||||
exit
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user