Codoforum related discussions
Import from phpbb3

I have created an import file to import my old forum from the phpbb3 system. That database is on the same server.
I created this file and saved it at /sys/CODOF/Importer/Drivers/

file named phpbb3.php:
corrected code:

<?php

/*
 * @CODOLICENSE
 */

namespace CODOF\Importer\Drivers;

/**
 * 
 * SMF uses concept of boards . 
 * They have boards -> categories -> topics -> posts
 * 
 * But codoforum has categories -> topics -> posts 
 * 
 * We have seen from the tables that all topics and posts of SMF are linked 
 * with their boards . 
 * 
 * So, we will treat boards of SMF as categories of codoforum . We will not
 * concern ourselves with categories of SMF . 
 * 
 */

class phpbb3 {

    public $max_rows = 100;

    /**
     * Mention whether your posts table contain topic message as a post or not ?
     * 
     * If it is set to true , make sure the query in get_posts() below returns
     * messages of all topics too
     * 
     * Note: Importer runs faster when posts table has the message of topics
     *       but sadly not all forum systems are the same :(
     * @var type 
     */    
    public $post_has_topic = true;


    private $db;    
    public function __construct($db) {

        $this->db = $db;
    }

    /**
     * Table prefix 
     * @var type 
     */    
    public function set_prefix($prefix) {

        define('DBPRE', $prefix);
    }


    /**
     * 
     * Selects 
     * category id          -> cat_id
     * category name        -> cat_name
     * category description -> cat_description
     * category order       -> cat_order
     * category parent id   -> cat_pid 
     * @return type
     */
    public function get_cats() {

        $qry = "SELECT b.forum_id AS cat_id, b.forum_name AS cat_name, b.forum_desc AS cat_description,
                    b.left_id AS cat_order, b.parent_id AS cat_pid
                    FROM  ".DBPRE."forums AS b WHERE b.forum_type=1";

        $res = $this->db->query($qry);
        return $res->fetchAll();
    }

    /**
     * 
     * Selects
     * topic id           -> topic_id
     * topic title        -> title
     * category id        -> cat_id
     * topic created time -> topic_created
     * topic updated time -> topic_updated
     * last post id       -> last_post_id    [optional]
     * last post uid      -> last_post_uid   [optional]
     * last post name     -> last_post_name  [optional]
     * last post time     -> last_post_time  [optional] 
     * user id who creaed -> uid
     * post message       -> message [Must be selected when $post_has_topic=false Otherwise OPTIONAL]
     * post id            -> post_id [Must be selected when $post_has_topic=true  Otherwise OPTIONAL]
     * @param type $start
     * @return type
     */
    public function get_topics($start) {


        $qry = "SELECT t.topic_id AS topic_id, t.topic_title AS title,t.forum_id AS cat_id,t.topic_time AS topic_created,
                t.topic_last_post_time AS topic_updated, t.topic_poster AS uid, t.topic_first_post_id AS post_id,
                p.post_text AS message
                 FROM ".DBPRE."topics AS t 
                 INNER JOIN ".DBPRE."posts AS p ON p.topic_id=t.topic_first_post_id
                 LIMIT $this->max_rows OFFSET $start";

        $res = $this->db->query($qry);
        $result = $res->fetchAll(\PDO::FETCH_ASSOC);

        return $result;
    }

    /**
     * 
     * Selects
     * category id        -> cat_id
     * topic id           -> topic_id
     * post id            -> post_id
     * user id            -> uid
     * post message       -> message
     * post created time  -> post_created
     * post modified time -> post_modified
     * @param type $start
     * @return type
     */
    public function get_posts($start) {

        $qry = "SELECT t.forum_id AS cat_id, p.topic_id AS topic_id, p.poster_id AS uid,
                p.post_id AS post_id,p.post_text AS message, p.post_time AS post_created,
                p.post_time AS post_modified
                FROM ".DBPRE."posts AS p
                INNER JOIN ".DBPRE."topics as t ON t.topic_id=p.topic_id
                LIMIT $this->max_rows OFFSET $start";

        $res = $this->db->query($qry);
        $result = $res->fetchAll(\PDO::FETCH_ASSOC);

        return $result;

    }

    /**
     * Selects
     * user id              -> uid
     * username             -> username
     * nickname             -> name
     * password             -> pass
     * email                -> mail
     * forum signature      -> signature
     * user created time    -> created
     * user last login time -> last_access
     * user status          -> status
     * user avatar url      -> avatar
     * user role id         -> rid [OPTIONAL]
     * @param type $start
     * @return type
     */
    public function get_users($start) {

        $qry = "SELECT u.user_id AS id, u.username AS username, u.username AS name, u.user_password AS pass,
                 u.user_email AS mail, u.user_sig AS signature, u.user_regdate AS created,
                 u.user_lastvisit AS last_access, 
                 CASE WHEN u.user_rank='yes' THEN 0 ELSE 1 END AS user_status,               
                 u.user_avatar AS avatar
                FROM ".DBPRE."users AS u
                LIMIT $this->max_rows OFFSET $start";

        $res = $this->db->query($qry);
        $result = $res->fetchAll(\PDO::FETCH_ASSOC);
        //var_dump($result);
        return $result;
    }


    /**
     * Get the userid by email
     * This is used pre-import to check if admin account email address
     * given is correct or not
     * 
     * @param type $mail
     */
    public function get_user_by_mail($mail) {

        $qry = "SELECT user_id AS uid FROM ".DBPRE."users WHERE user_email=? ";

        $obj = $this->db->prepare($qry);

        $obj->execute(array($mail));
        $res = $obj->fetch();

        if (!empty($res)) {

            return $res['uid'];
        }

        return false;
    }

}

When I run it on my server at System/Importer I can select phpbb3. My error message is:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydomain.phpbb3_USERS' doesn't exist' in ...

I edited all fields to correspond the fields for phpbb3 and table phpbb3_USERS does exist.

By the way, my old demo categories from the installation of Codoforum are gone now so that went well.

What am I missing here?

I have created an import file to import my old forum from the phpbb3 system. That database is on the same server. I created this file and saved it at /sys/CODOF/Importer/Drivers/ file named phpbb3.php: _corrected code:_ ```` &amp;lt;?php /* * @CODOLICENSE */ namespace CODOF\Importer\Drivers; /** * * SMF uses concept of boards . * They have boards -&amp;gt; categories -&amp;gt; topics -&amp;gt; posts * * But codoforum has categories -&amp;gt; topics -&amp;gt; posts * * We have seen from the tables that all topics and posts of SMF are linked * with their boards . * * So, we will treat boards of SMF as categories of codoforum . We will not * concern ourselves with categories of SMF . * */ class phpbb3 { public $max_rows = 100; /** * Mention whether your posts table contain topic message as a post or not ? * * If it is set to true , make sure the query in get_posts() below returns * messages of all topics too * * Note: Importer runs faster when posts table has the message of topics * but sadly not all forum systems are the same :( * @var type */ public $post_has_topic = true; private $db; public function __construct($db) { $this-&amp;gt;db = $db; } /** * Table prefix * @var type */ public function set_prefix($prefix) { define(&#039;DBPRE&#039;, $prefix); } /** * * Selects * category id -&amp;gt; cat_id * category name -&amp;gt; cat_name * category description -&amp;gt; cat_description * category order -&amp;gt; cat_order * category parent id -&amp;gt; cat_pid * @return type */ public function get_cats() { $qry = &quot;SELECT b.forum_id AS cat_id, b.forum_name AS cat_name, b.forum_desc AS cat_description, b.left_id AS cat_order, b.parent_id AS cat_pid FROM &quot;.DBPRE.&quot;forums AS b WHERE b.forum_type=1&quot;; $res = $this-&amp;gt;db-&amp;gt;query($qry); return $res-&amp;gt;fetchAll(); } /** * * Selects * topic id -&amp;gt; topic_id * topic title -&amp;gt; title * category id -&amp;gt; cat_id * topic created time -&amp;gt; topic_created * topic updated time -&amp;gt; topic_updated * last post id -&amp;gt; last_post_id [optional] * last post uid -&amp;gt; last_post_uid [optional] * last post name -&amp;gt; last_post_name [optional] * last post time -&amp;gt; last_post_time [optional] * user id who creaed -&amp;gt; uid * post message -&amp;gt; message [Must be selected when $post_has_topic=false Otherwise OPTIONAL] * post id -&amp;gt; post_id [Must be selected when $post_has_topic=true Otherwise OPTIONAL] * @param type $start * @return type */ public function get_topics($start) { $qry = &quot;SELECT t.topic_id AS topic_id, t.topic_title AS title,t.forum_id AS cat_id,t.topic_time AS topic_created, t.topic_last_post_time AS topic_updated, t.topic_poster AS uid, t.topic_first_post_id AS post_id, p.post_text AS message FROM &quot;.DBPRE.&quot;topics AS t INNER JOIN &quot;.DBPRE.&quot;posts AS p ON p.topic_id=t.topic_first_post_id LIMIT $this-&amp;gt;max_rows OFFSET $start&quot;; $res = $this-&amp;gt;db-&amp;gt;query($qry); $result = $res-&amp;gt;fetchAll(\PDO::FETCH_ASSOC); return $result; } /** * * Selects * category id -&amp;gt; cat_id * topic id -&amp;gt; topic_id * post id -&amp;gt; post_id * user id -&amp;gt; uid * post message -&amp;gt; message * post created time -&amp;gt; post_created * post modified time -&amp;gt; post_modified * @param type $start * @return type */ public function get_posts($start) { $qry = &quot;SELECT t.forum_id AS cat_id, p.topic_id AS topic_id, p.poster_id AS uid, p.post_id AS post_id,p.post_text AS message, p.post_time AS post_created, p.post_time AS post_modified FROM &quot;.DBPRE.&quot;posts AS p INNER JOIN &quot;.DBPRE.&quot;topics as t ON t.topic_id=p.topic_id LIMIT $this-&amp;gt;max_rows OFFSET $start&quot;; $res = $this-&amp;gt;db-&amp;gt;query($qry); $result = $res-&amp;gt;fetchAll(\PDO::FETCH_ASSOC); return $result; } /** * Selects * user id -&amp;gt; uid * username -&amp;gt; username * nickname -&amp;gt; name * password -&amp;gt; pass * email -&amp;gt; mail * forum signature -&amp;gt; signature * user created time -&amp;gt; created * user last login time -&amp;gt; last_access * user status -&amp;gt; status * user avatar url -&amp;gt; avatar * user role id -&amp;gt; rid [OPTIONAL] * @param type $start * @return type */ public function get_users($start) { $qry = &quot;SELECT u.user_id AS id, u.username AS username, u.username AS name, u.user_password AS pass, u.user_email AS mail, u.user_sig AS signature, u.user_regdate AS created, u.user_lastvisit AS last_access, CASE WHEN u.user_rank=&#039;yes&#039; THEN 0 ELSE 1 END AS user_status, u.user_avatar AS avatar FROM &quot;.DBPRE.&quot;users AS u LIMIT $this-&amp;gt;max_rows OFFSET $start&quot;; $res = $this-&amp;gt;db-&amp;gt;query($qry); $result = $res-&amp;gt;fetchAll(\PDO::FETCH_ASSOC); //var_dump($result); return $result; } /** * Get the userid by email * This is used pre-import to check if admin account email address * given is correct or not * * @param type $mail */ public function get_user_by_mail($mail) { $qry = &quot;SELECT user_id AS uid FROM &quot;.DBPRE.&quot;users WHERE user_email=? &quot;; $obj = $this-&amp;gt;db-&amp;gt;prepare($qry); $obj-&amp;gt;execute(array($mail)); $res = $obj-&amp;gt;fetch(); if (!empty($res)) { return $res[&#039;uid&#039;]; } return false; } } ```` When I run it on my server at System/Importer I can select phpbb3. My error message is: Fatal error: Uncaught exception &#039;PDOException&#039; with message &#039;SQLSTATE[42S02]: Base table or view not found: 1146 Table &#039;mydomain.phpbb3_USERS&#039; doesn&#039;t exist&#039; in ... I edited all fields to correspond the fields for phpbb3 and table phpbb3_USERS does exist. By the way, my old demo categories from the installation of Codoforum are gone now so that went well. What am I missing here?
edited Jan 5 '15 at 5:41 pm

Another option would be to import manually.

export users table from phpbb3:

SELECT  `user_id` ,  `user_type` ,  `user_regdate` ,  `username` ,  `username_clean` ,  `user_password` ,  `user_email` ,  `user_lastvisit` ,  `user_posts` 
FROM  `phpbb3_users`

then import into codo_users table:

INSERT INTO `codo_users` (`id`, `user_status`, `created`, `username`, `name`, `pass`, `mail`, `last_access`, `no_posts`) VALUES
(4, 0, 1265115566, 'Test User', 'testuser', '$H$9wR4xUbBtx1hDDLBrwQ5UeNns73nJE/', 'email@address.com', 1265128706, 1),

I'd have to do this for Users, Posts and Categories.

Another option would be to import manually. export users table from phpbb3: ```` SELECT `user_id` , `user_type` , `user_regdate` , `username` , `username_clean` , `user_password` , `user_email` , `user_lastvisit` , `user_posts` FROM `phpbb3_users` ```` then import into codo_users table: ```` INSERT INTO `codo_users` (`id`, `user_status`, `created`, `username`, `name`, `pass`, `mail`, `last_access`, `no_posts`) VALUES (4, 0, 1265115566, &#039;Test User&#039;, &#039;testuser&#039;, &#039;$H$9wR4xUbBtx1hDDLBrwQ5UeNns73nJE/&#039;, &#039;email@address.com&#039;, 1265128706, 1), ```` I&#039;d have to do this for Users, Posts and Categories.

Hi,

phpBB does not use capitalized names for either tables or the fields inside.

Remember that mySQL databases are case-sensitive in most UNIX systems and that may be the reason for the importer complaining that the table is not found.

Hi, phpBB does not use capitalized names for either tables or the fields inside. Remember that mySQL databases are case-sensitive in most UNIX systems and that may be the reason for the importer complaining that the table is not found.
edited Jan 5 '15 at 9:30 am

Hi @adesh, Thank you for your reply.
I have successfully imported all posts from my old forum now. I updated the code above in case anyone else needs it.
I'm beginning to love Codoforum!

Hi @adesh, Thank you for your reply. I have successfully imported all posts from my old forum now. I updated the code above in case anyone else needs it. I&#039;m beginning to love Codoforum!

Hello,
I have read your post with interest!

I will try your import code.

What about the BBCODE and attached files?

Hello, I have read your post with interest! I will try your import code. What about the BBCODE and attached files?
edited Jun 12 '15 at 8:58 am

hey!

Thank you @KopjeKoffie , I saved a lot of time with your code.

Now I try to correct all the footprints of PhpBB : smileys, bbcode and attached files...

Any idea to start with?

hey! Thank you @KopjeKoffie , I saved a lot of time with your code. Now I try to correct all the footprints of PhpBB : smileys, bbcode and attached files... Any idea to start with?
732
5
2
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft