Beispiel #1
0
    def _dump_(self, sqlfile):
        # Get parent id
        if self.parent:
            parent_id = self.parent.newid
        else:
            parent_id = 0

        # Get forum_parents field
        entry = "i:{};a:2:{{i:0;s:{}:\"{}\";i:1;i:{};}}"
        entries = []
        parent = self.parent
        while parent:
            title = parent.title
            entries.append(
                entry.format(parent.newid, len(parent.title), title,
                             parent.forum_type))
            parent = parent.parent

        parents = "a:{}:{{{}}}".format(len(entries),
                                       "".join(reversed(entries)))

        parser = htmltobbcode.Parser(self.root)
        parser.feed(self.description)
        description = parser.get_post()

        num_posts = sum(1 for post in self.get_posts())
        num_topics = sum(1 for post in self.get_topics())

        if num_posts == 0:
            last_post = NoPost()
        else:
            last_post = max(self.get_posts(), key=lambda post: post.time)

        sqlfile.insert(
            "forums", {
                "forum_id": self.newid,
                "parent_id": parent_id,
                "left_id": self.left_id,
                "right_id": self.right_id,
                "forum_parents": parents,
                "forum_name": self.title,
                "forum_desc": description.text,
                "forum_desc_bitfield": description.bitfield,
                "forum_desc_uid": description.uid,
                "forum_type": self.forum_type,
                "forum_image": self.icon,
                "forum_status": self.status,
                "forum_posts": num_posts,
                "forum_topics": num_topics,
                "forum_topics_real": num_topics,
                "forum_last_post_id": last_post.post_id,
                "forum_last_poster_id": last_post.poster.newid,
                "forum_last_post_subject": last_post.title,
                "forum_last_post_time": last_post.time,
                "forum_last_poster_name": last_post.poster.name,
                "forum_last_poster_colour": last_post.poster.colour
            })

        for acl in default_forum_acl(self.newid):
            sqlfile.insert("acl_groups", acl)
Beispiel #2
0
    def _dump_(self, sqlfile):
        self.logger.debug("Exportation du message %d (sujet %d)", self.post_id,
                          self.topic.topic_id)
        parser = htmltobbcode.Parser(self.root)
        parser.feed(self.text)
        post = parser.get_post()

        sqlfile.insert(
            "posts", {
                "post_id": self.post_id,
                "topic_id": self.topic.topic_id,
                "forum_id": self.forum.newid,
                "poster_id": self.poster.newid,
                "post_time": self.time,
                "poster_ip": "::1",
                "post_subject": self.title,
                "post_text": post.text,
                "bbcode_bitfield": post.bitfield,
                "bbcode_uid": post.uid
            })
Beispiel #3
0
    def _dump_(self, sqlfile):
        try:
            group_id = self.groups[0].newid
        except:
            group_id = 2

        if 5 in [group.newid for group in self.groups]:
            # The user is an administrator
            self.colour = "AA0000"

        post_times = [
            post.time for post in self.root.get_posts() if post.poster == self
        ]
        num_posts = sum(1 for _ in post_times)
        if num_posts > 0:
            lastpost_time = max(post_times)
        else:
            lastpost_time = 0

        user = {
            "user_id": self.newid,
            "group_id": group_id,
            "user_regdate": self.date,
            "username": self.name,
            "username_clean": self.name.lower(),
            "user_password": md5(random_string()),
            "user_pass_convert": "1",
            "user_email": self.mail,
            "user_email_hash": email_hash(self.mail),
            "user_lastvisit": self.lastvisit,
            "user_lastpost_time": lastpost_time,
            "user_posts": num_posts,
            "user_lang": self.config["default_lang"],
            "user_style": "1",
            #"user_rank" (TODO)
            "user_colour": self.colour
            #"user_avatar" (TODO)
            #"user_sig" (TODO)
            #"user_from" (TODO)
            #"user_website" (TODO) (...)
        }

        # Check if the user is the administrator
        if self.name == self.config["admin_name"]:
            user.update({
                "user_type": 3,
                "user_password": md5(self.config["admin_password"]),
                "user_rank": 1,
                "user_new_privmsg": 1,
                "user_unread_privmsg": 1,
                "user_last_privmsg": self.root.dump_time
            })

        if self.name == "Anonymous":
            user.update({
                "user_type": 2,
                "group_id": 1,
                "user_allow_massemail": "0"
            })

        # Add user to database
        sqlfile.insert("users", user)

        # Add user to registered group
        if self.name == "Anonymous":
            sqlfile.insert("user_group", {
                "group_id": "1",
                "user_id": "1",
                "user_pending": "0"
            })
        else:
            sqlfile.insert("user_group", {
                "group_id": 2,
                "user_id": self.newid,
                "user_pending": 0
            })

        for group in self.groups:
            group_leader = 1 if group.leader_name == self.name else 0
            sqlfile.insert(
                "user_group", {
                    "group_id": group.newid,
                    "user_id": self.newid,
                    "user_pending": 0,
                    "group_leader": group_leader
                })

        # Check if the user is the administrator
        if self.name == self.config["admin_name"]:
            # Add user to global moderators group
            sqlfile.insert("user_group", {
                "group_id": 4,
                "user_id": self.newid,
                "user_pending": 0
            })

            # Send a private message confirming the import was successful
            parser = htmltobbcode.Parser(self.root)
            parser.feed(PM_POST)
            post = parser.get_post()

            sqlfile.insert(
                "privmsgs", {
                    'msg_id': 1,
                    'author_id': self.newid,
                    'message_time': self.root.dump_time,
                    'message_subject': PM_SUBJECT,
                    'message_text': post.text,
                    'bbcode_bitfield': post.bitfield,
                    'bbcode_uid': post.uid,
                    'to_address': "u_{}".format(self.newid),
                    'bcc_address': ""
                })

            # Add the message in the inbox
            sqlfile.insert(
                "privmsgs_to", {
                    'msg_id': 1,
                    'user_id': self.newid,
                    'author_id': self.newid,
                    'folder_id': -1
                })
            # Add the message in the outbox
            sqlfile.insert(
                "privmsgs_to", {
                    'msg_id': 1,
                    'user_id': self.newid,
                    'author_id': self.newid,
                    'folder_id': 0
                })
Beispiel #4
0
    def _dump_(self, sqlfile):
        try:
            group_id = self.groups[0].newid
        except:
            group_id = 2

        if 5 in [group.newid for group in self.groups]:
            # The user is an administrator
            self.colour = "AA0000"

        post_times = [
            post.time for post in self.root.get_posts() if post.poster == self
        ]
        num_posts = sum(1 for _ in post_times)
        if num_posts > 0:
            lastpost_time = max(post_times)
        else:
            lastpost_time = 0

        self.get_additionnal_data()

        user = {
            "user_id": self.newid,
            "group_id": group_id,
            "user_regdate": self.date,
            "username": self.name,
            "username_clean": self.name.lower(),
            "user_password": md5(random_string()),
            "user_pass_convert": "1",
            "user_email": self.mail,
            "user_email_hash": email_hash(self.mail),
            "user_lastvisit": self.lastvisit,
            "user_lastpost_time": lastpost_time,
            "user_posts": num_posts,
            "user_lang": self.config["default_lang"],
            "user_style": "1",
            #"user_rank" (built later)
            "user_colour": self.colour,
            #"user_avatar" (TODO)
            "user_avatar": self.avatar,
            "user_sig": self.signature,
            "user_attachsig": self.attachsig,
            #"user_from" (TODO)
            "user_sex": self.sexe,
            "user_date_of_birth": self.age,
            # les nouveaux médias ne sont pas dans les profils d'origine de phpbb2
            "user_facebook": self.facebook,
            "user_twitter": self.twitter,
            "user_skype": self.skype,
            "user_website": self.site_web,

            #Specific to my own forum/site
            "user_modele_bat": self.modele_bat,
            "user_nom_bat": self.nom_bat,
            "user_port_bat": self.port_bat,
            "user_mmsi_bat": self.mmsi_bat
        }

        # Check if the user is the administrator
        if self.name == self.config["admin_name"]:
            self.logger.debug(
                'Ajout des droits administrateur et du mot de passe configuré pour "%s"',
                self.name)

            user.update({
                "user_type": 3,
                "user_password": md5(self.config["admin_password"]),
                "user_rank": 1,
                "user_new_privmsg": 1,
                "user_unread_privmsg": 1,
                "user_last_privmsg": self.root.dump_time
            })

        if self.name == "Anonymous":
            user.update({
                "user_type": 2,
                "group_id": 1,
                "user_allow_massemail": "0"
            })

        # Add user to database
        sqlfile.insert("users", user)

        # Add user to registered group
        if self.name == "Anonymous":
            sqlfile.insert("user_group", {
                "group_id": "1",
                "user_id": "1",
                "user_pending": "0"
            })
        else:
            sqlfile.insert("user_group", {
                "group_id": 2,
                "user_id": self.newid,
                "user_pending": 0
            })

        for group in self.groups:
            group_leader = 1 if group.leader_name == self.name else 0
            sqlfile.insert(
                "user_group", {
                    "group_id": group.newid,
                    "user_id": self.newid,
                    "user_pending": 0,
                    "group_leader": group_leader
                })

        # Check if the user is the administrator
        if self.name == self.config["admin_name"]:
            # Add user to global moderators group
            sqlfile.insert("user_group", {
                "group_id": 4,
                "user_id": self.newid,
                "user_pending": 0
            })

            # Send a private message confirming the import was successful
            parser = htmltobbcode.Parser(self.root)
            parser.feed(PM_POST)
            post = parser.get_post()

            sqlfile.insert(
                "privmsgs", {
                    'msg_id': 1,
                    'author_id': self.newid,
                    'message_time': self.root.dump_time,
                    'message_subject': PM_SUBJECT,
                    'message_text': post.text,
                    'bbcode_bitfield': post.bitfield,
                    'bbcode_uid': post.uid,
                    'to_address': "u_{}".format(self.newid),
                    'bcc_address': ""
                })

            # Add the message in the inbox
            sqlfile.insert(
                "privmsgs_to", {
                    'msg_id': 1,
                    'user_id': self.newid,
                    'author_id': self.newid,
                    'folder_id': -1
                })
            # Add the message in the outbox
            sqlfile.insert(
                "privmsgs_to", {
                    'msg_id': 1,
                    'user_id': self.newid,
                    'author_id': self.newid,
                    'folder_id': 0
                })