Beispiel #1
0
    def handle(self, *args, **options):
        # Requires at least one forum_id
        if not args:
            raise CommandError('Usage: ./manage.py migrate_forum %s' %
                               self.args)

        for forum_id in args:
            try:
                tiki_forum = TikiForum.objects.get(pk=int(forum_id))
            except TikiForum.DoesNotExist:
                raise CommandError('Forum "%s" does not exist' % forum_id)

            forum = create_forum(tiki_forum)

            if options['verbosity'] > 0:
                print ('Starting migration for forum "%s" (%s)' %
                       (tiki_forum.name, forum_id))

            if options['verbosity'] > 0:
                print 'Created forum "%s" (%s)...' % (forum.name, forum.id)

            # ... then create the threads
            thread_offset = 0
            threads = fetch_threads(tiki_forum, self.max_threads,
                                    thread_offset)
            thread_i = 0
            while threads:
                try:
                    tiki_thread = threads[thread_i]
                except IndexError:
                    # we're done with this list, next!
                    thread_offset = thread_offset + self.max_threads
                    threads = fetch_threads(tiki_forum, self.max_threads,
                                            thread_offset)
                    thread_i = 0
                    continue

                if options['verbosity'] > 1:
                    print 'Processing thread %s...' % tiki_thread.threadId
                thread = create_thread(forum, tiki_thread)

                # keep track of the last_post
                last_post = thread.last_post

                # ... then create its posts
                post_offset = 0
                posts = fetch_posts(tiki_thread, self.max_posts, post_offset)
                post_i = 0
                while posts:
                    try:
                        tiki_post = posts[post_i]
                    except IndexError:
                        post_offset = post_offset + self.max_posts
                        posts = fetch_posts(tiki_thread, self.max_posts,
                                            post_offset)
                        post_i = 0
                        continue

                    if options['verbosity'] > 2:
                        print ('Processing post %s for thread %s...' %
                           (tiki_post.threadId, tiki_post.parentId))
                    post = create_post(thread, tiki_post)
                    post_i = post_i + 1

                    # if this post is newer than the last_post, update it
                    if post.created > last_post.created:
                        last_post = post

                thread.last_post = last_post
                thread.save()

                thread_i = thread_i + 1

            if options['verbosity'] > 0:
                print ('Successfully migrated posts in forum "%s" (%s)' %
                       (tiki_forum.name, forum_id))
Beispiel #2
0
    def handle(self, *args, **options):
        pin_this_thread()

        # Requires at least one forum_id
        if args:
            raise CommandError("Usage: ./manage.py migrate_questions")

        try:
            tiki_forum = TikiForum.objects.get(pk=self.forum_id)
        except TikiForum.DoesNotExist:
            raise CommandError('Forum "%s" does not exist' % self.forum_id)

        if options["verbosity"] > 0:
            print ('Starting migration for forum "%s" (%s)' % (tiki_forum.name, self.forum_id))

        # Create the questions
        thread_offset = 0
        threads = fetch_threads(tiki_forum, self.max_threads, thread_offset)
        thread_counter = self.max_threads
        thread_i = 0
        while threads and thread_counter <= self.max_total_threads:
            try:
                tiki_thread = threads[thread_i]
            except IndexError:
                # we're done with this list, next!
                thread_offset = thread_offset + self.max_threads
                threads = fetch_threads(tiki_forum, self.max_threads, thread_offset)
                thread_counter += self.max_threads
                thread_i = 0
                continue

            if options["verbosity"] > 1:
                print "Processing thread %s..." % tiki_thread.threadId

            # Create question..
            question = create_question(tiki_thread)
            create_question_metadata(question)

            # ... then create its answers
            post_offset = 0
            posts = fetch_posts(tiki_thread, self.max_posts, post_offset)
            post_i = 0
            while posts:
                try:
                    tiki_post = posts[post_i]
                except IndexError:
                    post_offset = post_offset + self.max_posts
                    posts = fetch_posts(tiki_thread, self.max_posts, post_offset)
                    post_i = 0
                    continue

                if options["verbosity"] > 2:
                    print ("Processing post %s for thread %s..." % (tiki_post.threadId, tiki_post.parentId))

                # Create answer
                create_answer(question, tiki_post, tiki_thread)
                post_i = post_i + 1

            # Now that all answers have been migrated, update the question's
            # updated date
            update_question_updated_date(question)
            post_reply_in_old_thread(tiki_thread, question)
            thread_i = thread_i + 1

        if options["verbosity"] > 0:
            print ('Successfully migrated posts in forum "%s" (%s)' % (tiki_forum.name, self.forum_id))

        if options["verbosity"] > 0 and thread_counter >= self.max_total_threads:
            print ("Reached maximum number of threads to migrate " + "(%s) and stopped." % self.max_total_threads)