diff --git a/lib/guardian/ensure_magic.rb b/lib/guardian/ensure_magic.rb index 9ccfbd1168c..cb8b5c0ed77 100644 --- a/lib/guardian/ensure_magic.rb +++ b/lib/guardian/ensure_magic.rb @@ -1,6 +1,6 @@ # Support for ensure_{blah}! methods. module EnsureMagic - + def method_missing(method, *args, &block) if method.to_s =~ /^ensure_(.*)\!$/ can_method = :"#{Regexp.last_match[1]}?" @@ -18,5 +18,5 @@ module EnsureMagic def ensure_can_see!(obj) raise Discourse::InvalidAccess.new("Can't see #{obj}") unless can_see?(obj) end - -end \ No newline at end of file + +end diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rb index e11b3797a89..b6d0a0dd588 100644 --- a/lib/guardian/post_guardian.rb +++ b/lib/guardian/post_guardian.rb @@ -61,9 +61,9 @@ module PostGuardain # Creating Method def can_create_post?(parent) !SpamRule::AutoBlock.block?(@user) && ( - !parent || - !parent.category || - Category.post_create_allowed(self).where(:id => parent.category.id).count == 1 + !parent || + !parent.category || + Category.post_create_allowed(self).where(:id => parent.category.id).count == 1 ) end diff --git a/lib/tasks/typepad.thor b/lib/tasks/typepad.thor index 71d3fa79f93..016c2b084d4 100644 --- a/lib/tasks/typepad.thor +++ b/lib/tasks/typepad.thor @@ -1,13 +1,12 @@ require 'open-uri' class Typepad < Thor + desc "import", "Imports posts from a Disqus XML export" method_option :file, aliases: '-f', required: true, desc: "The typepad file to import" - method_option :dry_run, required: false, desc: "Just output what will be imported rather than doing it" method_option :post_as, aliases: '-p', required: true, desc: "The Discourse username to post as" method_option :google_api, aliases: '-g', required: false, desc: "The google plus API key to use to fetch usernames" - def import require './config/environment' @@ -142,7 +141,7 @@ class Typepad < Thor end def parse_comment(section) - return parse_meta_data(section) + parse_meta_data(section) end def process_entry(entry) @@ -242,5 +241,3 @@ class Typepad < Thor end end - - diff --git a/lib/tasks/vanilla.thor b/lib/tasks/vanilla.thor new file mode 100644 index 00000000000..577e69e6a6f --- /dev/null +++ b/lib/tasks/vanilla.thor @@ -0,0 +1,322 @@ +require "csv" + +class Vanilla < Thor + + desc "import", "Imports posts from a Vanilla export" + method_option :file, aliases: '-f', required: true, desc: "The vanilla file to import" + + def import + + unless File.exist?(options[:file]) + puts "File '#{options[:file]}' not found" + exit 1 + end + + load_rails + + file = read_file(options[:file]) + parse_file(file) + + disable_rate_limiter + + create_users + create_user_memberships + + create_categories + create_topics + create_posts + update_topic_statuses + + create_private_topics + create_private_posts + ensure + enable_rate_limiter + end + + no_commands do + + def load_rails + puts "loading rails..." + require "./config/environment" + end + + def disable_rate_limiter + puts "disabling rate limiter..." + RateLimiter.disable + end + + def read_file(file) + puts "reading file..." + string = File.read(file).gsub("\\N", "").gsub(/\\$\n/m, "\\n").gsub("\\,", ",").gsub(/(?