/** * Import the sample content * * @return $this */ public function convert() { $this->data = json_decode(file_get_contents(JPATH_COMPONENT_ADMINISTRATOR . '/data/demo.json'), true); parent::convert(); if (KRequest::type() == 'AJAX') { echo json_encode(array('splittable' => false)); } return $this; }
/** * Import the sample content * * @return $this */ public function convert() { $tables = array(array('name' => 'attachments', 'options' => array('name' => 'ccb_attachments'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('tbl.id', 'tbl.post_id AS post', 'tbl.real_name AS name', 'post.post_user AS joomla_user_id', 'tbl.ccb_name AS file'))->join('left', 'ccb_posts AS post', 'tbl.post_id = post.id')), array('name' => 'forums', 'options' => array('name' => 'ccb_category'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('(id + (SELECT MAX(id) FROM #__ccb_forums)) AS id', 'cat_name AS title', "'/' AS path"))), array('name' => 'forums', 'options' => array('name' => 'ccb_forums'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('id', 'forum_name AS title', 'forum_desc AS description', 'topic_count AS topics', 'post_count AS posts', 'last_post_id', 'published AS enabled', 'locked', "CONCAT('/', (cat_id + (SELECT MAX(id) FROM #__ccb_forums)), '/') AS path"))), array('name' => 'posts', 'options' => array('name' => 'ccb_posts'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('*', 'topic_id AS ninjaboard_topic_id', 'post_subject AS subject', 'post_text AS text', 'post_user AS created_by', 'FROM_UNIXTIME(post_time) AS created_on', 'ip AS user_ip', 'modified_by', 'FROM_UNIXTIME(modified_time) AS mofidied_on', 'modified_reason AS edit_reason'))), array('name' => 'topics', 'options' => array('name' => 'ccb_topics'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('*', 'reply_count AS replies', 'topic_type AS topic_type_id', 'start_post_id AS first_post_id'))), array('name' => 'people', 'options' => array('name' => 'ccb_users'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('user_id AS id', 'signature', 'post_count AS posts', 'avatar')))); //This returns false if the import is big enough to be done in steps. //So we need to stop the importing in this step, in order for it to initiate if ($this->importData($tables, 'ccboard') === false) { return $this; } //Convert html 2 bbcode where needed if (isset($this->data['posts'])) { foreach ($this->data['posts'] as $id => $post) { if (!isset($this->data['posts'][$id]['text'])) { continue; } $this->data['posts'][$id]['text'] = html2bbcode($post['text']); } } //Move over file attachments if (isset($this->data['attachments'])) { foreach ($this->data['attachments'] as $id => $attachment) { $from = JPATH_ROOT . '/components/com_ccboard/assets/uploads/' . $attachment['file']; $file = JPATH_ROOT . '/media/com_ninjaboard/attachments/' . $attachment['file']; //Don't do anything if avatar don't exist if (!JFile::exists($from)) { continue; } JFile::copy($from, $file); } } //Move over avatars if (isset($this->data['people'])) { foreach ($this->data['people'] as $id => $person) { if (!$person['avatar']) { continue; } $from = JPATH_ROOT . '/components/com_ccboard/assets/avatar/' . $person['avatar']; $file = basename($from); $avatar = '/media/com_ninjaboard/images/avatars/' . $person['id'] . '/' . $file; //Don't do anything if avatar don't exist if (!JFile::exists($from)) { continue; } JFile::copy($from, JPATH_ROOT . $avatar); $this->data['people'][$id]['avatar'] = $avatar; } } //Clear cache folder so that avatars and attachments cache are cleared //@TODO this should only run once $cache = JPATH_ROOT . '/cache/com_ninjaboard/'; if (JFolder::exists($cache)) { JFolder::delete($cache); } parent::convert(); return $this; }
/** * Import the sample content * * @return $this */ public function convert() { $tables = array(array('name' => 'attachments', 'options' => array('name' => 'ninjaboard_attachments_backups', 'identity_column' => 'id'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('id', 'id_user AS joomla_user_id', 'id_post AS post', 'file_name AS name', 'file_name AS file'))), array('name' => 'forums', 'options' => array('name' => 'ninjaboard_categories_backups', 'identity_column' => 'id'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('(id + (SELECT MAX(id) FROM #__ninjaboard_forums_backups)) AS id', '(SELECT SUM(posts) FROM #__ninjaboard_forums_backups) AS posts', '(SELECT SUM(topics) FROM #__ninjaboard_forums_backups) AS topics', '(SELECT MAX(id_last_post) FROM #__ninjaboard_forums_backups) AS last_post_id', 'name AS title', 'published AS enabled', 'ordering', "'/' AS path"))), array('name' => 'forums', 'options' => array('name' => 'ninjaboard_forums_backups', 'identity_column' => 'id'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('id', 'description', 'locked', 'ordering', 'topics', 'posts', 'id_last_post AS last_post_id', 'name AS title', 'state AS enabled', "CONCAT('/', (id_cat + (SELECT MAX(id) FROM #__ninjaboard_forums_backups)), '/') AS path"))), array('name' => 'usergroups', 'options' => array('name' => 'ninjaboard_groups_backups', 'identity_column' => 'id'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('id', 'name AS title'))), $this->buildAclQueryColumn('FORUM', 3, 4), $this->buildAclQueryColumn('TOPIC', 3, 2, '>'), $this->buildAclQueryColumn('POST', 3, 2, '>'), $this->buildAclQueryColumn('ATTACHMENT', 3, 2, '>'), $this->buildAclQueryColumn('TOPIC', 1, 3, '<'), $this->buildAclQueryColumn('POST', 1, 3, '<'), $this->buildAclQueryColumn('ATTACHMENT', 1, 3, '<'), $this->buildAclQueryColumn('FORUM', 1, 4, '<'), array('name' => 'posts', 'options' => array('name' => 'ninjaboard_posts_backups', 'identity_column' => 'id'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('*', 'date_post AS created_on', 'date_last_edit AS modified_on', 'id_edit_by AS modified_by', 'ip_poster AS user_ip', 'id_topic AS ninjaboard_topic_id', 'id_user AS created_by', 'IFNULL(guest.guest_name, tbl.guest_name) AS guest_name'))->join('left', 'ninjaboard_posts_guests_backups AS guest', 'guest.id_post = tbl.id')), array('name' => 'topics', 'options' => array('name' => 'ninjaboard_topics_backups', 'identity_column' => 'id'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('*', 'id_forum AS forum_id', 'views AS hits', 'type AS topic_type_id', 'id_first_post AS first_post_id', 'id_last_post AS last_post_id'))), array('name' => 'people', 'options' => array('name' => 'ninjaboard_users_backups', 'identity_column' => 'id'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('*', 'avatar_file AS avatar')))); //This returns false if the import is big enough to be done in steps. //So we need to stop the importing in this step, in order for it to initiate if ($this->importData($tables, 'ninjaboard_legacy') === false) { return $this; } //Move over file attachments if (isset($this->data['attachments'])) { foreach ($this->data['attachments'] as $id => $attachment) { $from = JPATH_ROOT . '/components/com_ninjaboard/attachments/' . $attachment['file']; $file = JPATH_ROOT . '/media/com_ninjaboard/attachments/' . $attachment['file']; //Don't do anything if avatar don't exist if (!JFile::exists($from)) { continue; } JFile::copy($from, $file); } } //Move over avatars if (isset($this->data['people'])) { $path = 'media/ninjaboard/avatars'; $query = KFactory::tmp('lib.koowa.database.query')->select('avatar_settings')->from('ninjaboard_configs_backups')->order('default_config'); $avatar_settings = KFactory::get('lib.koowa.database.adapter.mysqli')->select($query, KDatabase::FETCH_FIELD); if ($avatar_settings) { foreach (explode("\n", $avatar_settings) as $avatar_setting) { $parts = explode('=', $avatar_setting); if ($parts[0] == 'avatar_path') { $path = $parts[1]; } } } foreach ($this->data['people'] as $id => $person) { $from = JPATH_ROOT . '/' . $path . '/' . $person['avatar']; $file = basename($from); $avatar = '/media/com_ninjaboard/images/avatars/' . $person['id'] . '/' . $file; //Don't do anything if avatar don't exist if (!JFile::exists($from)) { continue; } JFile::copy($from, JPATH_ROOT . $avatar); $this->data['people'][$id]['avatar'] = $avatar; } } //Clear cache folder so that avatars and attachments cache are cleared //@TODO this should only run once $cache = JPATH_ROOT . '/cache/com_ninjaboard/'; if (JFolder::exists($cache)) { JFolder::delete($cache); } parent::convert(); return $this; }
/** * Import the sample content * * @return $this */ public function convert() { $tables = array(array('name' => 'forums', 'options' => array('name' => 'agora_categories'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('(id + (SELECT MAX(id) FROM #__agora_forums)) AS id', 'cat_name AS title', 'disp_position AS ordering', 'enable AS enabled', "'/' AS path"))), array('name' => 'forums', 'options' => array('name' => 'agora_forums'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('id', 'enable AS enabled', 'forum_name AS title', 'forum_desc AS description', 'num_topics AS topics', 'num_posts AS posts', 'last_post_id', 'disp_position AS ordering', "CONCAT('/', (cat_id + (SELECT MAX(id) FROM #__agora_forums)), '/') AS path", 'parent_forum_id AS parent_id'))), array('name' => 'posts', 'options' => array('name' => 'agora_posts'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('tbl.*', 'topic.subject AS subject', 'user.jos_id AS created_by', 'poster_ip AS user_ip', 'poster_email AS guest_email', 'message AS text', 'FROM_UNIXTIME(tbl.posted) AS created_on', 'FROM_UNIXTIME(edited) AS mofidied_on', 'edited_by AS modified_by', 'topic_id AS ninjaboard_topic_id'))->join('left', 'agora_topics AS topic', 'topic.id = tbl.topic_id')->join('left', 'agora_users AS user', 'user.id = tbl.poster_id')), array('name' => 'topics', 'options' => array('name' => 'agora_topics'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('tbl.*', 'num_views AS hits', 'num_replies AS replies', 'closed AS locked', 'post.id AS first_post_id'))->join('left', 'agora_posts AS post', 'topic_id = tbl.id')->group('tbl.id')), array('name' => 'people', 'options' => array('name' => 'agora_users'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('jos_id AS id', 'id AS agora_user_id', 'signature', 'num_posts AS posts'))), array('name' => 'watches', 'options' => array('name' => 'agora_subscriptions'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('CONCAT(user_id, topic_id, forum_id, category_id) AS id', 'jos_id AS created_by', 'NOW() AS created_on', '1 AS subscription_type', '(category_id + (SELECT MAX(id) FROM #__agora_forums)) AS subscription_type_id'))->join('left', 'agora_users', 'user_id = id')->where('category_id', '>', 0)), array('name' => 'watches', 'options' => array('name' => 'agora_subscriptions'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('CONCAT(user_id, topic_id, forum_id, category_id) AS id', 'jos_id AS created_by', 'NOW() AS created_on', '1 AS subscription_type', 'forum_id AS subscription_type_id'))->join('left', 'agora_users', 'user_id = id')->where('forum_id', '>', 0)), array('name' => 'watches', 'options' => array('name' => 'agora_subscriptions'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('CONCAT(user_id, topic_id, forum_id, category_id) AS id', 'jos_id AS created_by', 'NOW() AS created_on', '3 AS subscription_type', 'topic_id AS subscription_type_id'))->join('left', 'agora_users', 'user_id = id')->where('topic_id', '>', 0))); //This returns false if the import is big enough to be done in steps. //So we need to stop the importing in this step, in order for it to initiate if ($this->importData($tables, 'agora') === false) { return $this; } //Move over avatars if (isset($this->data['people'])) { //Get the avatar path $query = KFactory::tmp('lib.koowa.database.query')->select('conf_value')->from('agora_config')->where('conf_name', '=', 'o_avatars_dir'); $path = KFactory::get('lib.koowa.database.adapter.mysqli')->select($query, KDatabase::FETCH_FIELD); foreach ($this->data['people'] as $id => $person) { $from = JPATH_ROOT . '/' . $path . '/' . $person['agora_user_id'] . '.'; //Agora have 3 avatar types we need to check, gif, jpg and png if (JFile::exists($from . 'gif')) { $from .= 'gif'; } elseif (JFile::exists($from . 'jpg')) { $from .= 'jpg'; } elseif (JFile::exists($from . 'png')) { $from .= 'png'; } else { continue; } $file = basename($from); $avatar = '/media/com_ninjaboard/images/avatars/' . $person['id'] . '/' . $file; //Don't do anything if avatar don't exist if (!JFile::exists($from)) { continue; } JFile::copy($from, JPATH_ROOT . $avatar); $this->data['people'][$id]['avatar'] = $avatar; } } //Clear cache folder so that avatars and attachments cache are cleared //@TODO this should only run once $cache = JPATH_ROOT . '/cache/com_ninjaboard/'; if (JFolder::exists($cache)) { JFolder::delete($cache); } parent::convert(); if (isset($this->data['forums'])) { $this->updateForumPaths(); } return $this; }
/** * Import the sample content * * @return $this */ public function convert() { //Connect the lib.koowa.database to the phpBB3 database $this->setDatabaseConnection(); $tables = array(array('name' => 'attachments', 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('attach_id AS id', 'post_msg_id AS post', 'real_filename AS name', 'poster_id AS joomla_user_id', 'physical_filename AS file', 'extension'))->where('post_msg_id', '!=', 0)), array('name' => 'forums', 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('*', 'forum_id AS id', 'forum_name AS title', 'forum_desc AS description', 'forum_status AS locked', 'forum_topics AS topics', 'forum_posts AS posts', 'forum_last_post_id AS last_post_id'))), array('name' => 'topic_symlinks', 'options' => array('name' => 'topics'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('topic_id AS id', 'topic_moved_id AS ninjaboard_topic_id', 'forum_id AS ninjaboard_forum_id'))->where('topic_moved_id', '>', 0)), array('name' => 'topics', 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('*', 'topic_id AS id', 'topic_title AS title', 'icon_id AS status', 'topic_last_post_id AS last_post_id', 'topic_first_post_id AS first_post_id', 'topic_replies AS replies', 'topic_views AS hits'))->where('topic_moved_id', '=', 0)), array('name' => 'posts', 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('*', 'post_id AS id', 'topic_id AS ninjaboard_topic_id', 'icon_id AS status', 'poster_id AS created_by', 'FROM_UNIXTIME(post_time) AS created_on', 'poster_ip AS user_ip', 'FROM_UNIXTIME(post_edit_time) AS mofidied_on', 'post_edit_reason AS edit_reason', 'post_subject AS subject', 'post_text AS text')))); //This returns false if the import is big enough to be done in steps. //So we need to stop the importing in this step, in order for it to initiate if ($this->importData($tables, 'phpbb') === false) { return $this; } //Move over file attachments if (isset($this->data['attachments'])) { //Get the attachments path $query = KFactory::tmp('lib.koowa.database.query')->select('config_value')->from('config')->where('config_name', '=', 'upload_path'); $path = KFactory::get('lib.koowa.database.adapter.mysqli')->select($query, KDatabase::FETCH_FIELD); foreach ($this->data['attachments'] as $id => $attachment) { $from = JPATH_ROOT . '/' . $this->getPath() . '/' . $path . '/' . $attachment['file']; $file = JPATH_ROOT . '/media/com_ninjaboard/attachments/' . $attachment['file'] . '.' . $attachment['extension']; //Don't do anything if attachment don't exist if (!JFile::exists($from)) { continue; } JFile::copy($from, $file); $this->data['attachments'][$id]['file'] = basename($file); } } //Reconnect the lib.koowa.database to the Joomla! database $this->resetDatabaseConnection(); //Clear cache folder so that avatars and attachments cache are cleared //@TODO this should only run once $cache = JPATH_ROOT . '/cache/com_ninjaboard/'; if (JFolder::exists($cache)) { JFolder::delete($cache); } parent::convert(); if (isset($this->data['forums'])) { $this->updateForumPaths(); } return $this; }
/** * Import the sample content * * @return $this */ public function convert() { $tables = array(array('name' => 'topics', 'options' => array('name' => 'yahoo_messages', 'identity_column' => 'ninjaboard_topic_id'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('tbl.post_id AS ninjaboard_topic_id', 'tbl.post_id AS first_post_id', '(SELECT last_post.post_id FROM #__yahoo_messages AS last_post WHERE last_post.topic_id = tbl.topic_id ORDER BY post_id DESC LIMIT 1) AS last_post_id', '(SELECT COUNT(*) FROM #__yahoo_messages AS count_replies WHERE count_replies.topic_id = tbl.topic_id) AS replies', '(SELECT forum.ninjaboard_forum_id FROM #__ninjaboard_forums AS forum LIMIT 1) AS forum_id'))->where('tbl.post_subject = tbl.topic_id')), array('name' => 'posts', 'options' => array('name' => 'yahoo_messages', 'identity_column' => 'ninjaboard_post_id'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('post_id AS ninjaboard_post_id', 'post_subject AS subject', 'post_text AS text', 'post_time AS created_on', 'post_username AS guest_name', '(SELECT topic.post_id FROM #__yahoo_messages AS topic WHERE topic.post_subject = tbl.topic_id LIMIT 1) AS ninjaboard_topic_id')))); //This returns false if the import is big enough to be done in steps. //So we need to stop the importing in this step, in order for it to initiate if ($this->importData($tables, 'yahoo') === false) { return $this; } //Convert the html to bbcode before it's inserted to ninjaboard tables if (isset($this->data['posts'])) { foreach ($this->data['posts'] as $id => $post) { $this->data['posts'][$id]['text'] = html2bbcode($post['text']); } } //Clear cache folder so that avatars and attachments cache are cleared //@TODO this should only run once $cache = JPATH_ROOT . '/cache/com_ninjaboard/'; if (JFolder::exists($cache)) { JFolder::delete($cache); } parent::convert(); return $this; }
/** * Import the sample content * * @return $this */ public function convert() { //Connect the lib.koowa.database to the SMF database $this->setDatabaseConnection(); //Get the category offset needed to avoid ID collisions when we merge smf_categories and smf_boards into ninjaboard_forums $database = KFactory::get('lib.koowa.database'); $query = KFactory::tmp('lib.koowa.database.query')->select('ID_CAT AS id')->from('categories')->order('ID_CAT', 'desc'); $forum_padding = $database->select($query, KDatabase::FETCH_FIELD); $query = KFactory::tmp('lib.koowa.database.query')->select('ID_MEMBER AS id')->from('members')->order('ID_MEMBER', 'desc'); $member_padding = $database->select($query, KDatabase::FETCH_FIELD); $tables = array(array('name' => 'attachments', 'options' => array('name' => 'attachments'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('ID_ATTACH AS id', 'ID_MSG AS post', 'file_hash AS hash', 'filename AS name', 'ID_MEMBER AS joomla_user_id'))->where('attachmentType', '=', 0)), array('name' => 'forums', 'options' => array('name' => 'categories'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('ID_CAT AS id', 'catOrder AS ordering', 'name AS title', "'/' AS path"))), array('name' => 'forums', 'options' => array('name' => 'boards'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('(ID_BOARD + ' . $forum_padding . ') AS id', 'boardOrder AS ordering', 'name AS title', 'IF(ID_PARENT > 0, (ID_PARENT + ' . $forum_padding . '), ID_CAT) AS parent_id', 'description', 'childLevel AS level', 'numTopics AS topics', 'numPosts AS posts', 'ID_LAST_MSG AS last_post_id', "'/' AS path"))), array('name' => 'topics', 'options' => array('name' => 'topics'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('ID_TOPIC AS id', 'isSticky AS sticky', '(ID_BOARD + ' . $forum_padding . ') AS forum_id', 'ID_FIRST_MSG AS first_post_id', 'ID_LAST_MSG AS last_post_id', 'ID_POLL AS poll', 'numReplies AS replies', 'numViews AS hits', 'locked'))), array('name' => 'posts', 'options' => array('name' => 'messages'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('ID_MSG AS id', 'ID_TOPIC AS ninjaboard_topic_id', "FROM_UNIXTIME(posterTime) AS created_on", 'ID_MEMBER AS created_by', 'subject', 'posterName AS guest_name', 'posterEmail AS guest_email', 'posterIP AS user_ip', 'FROM_UNIXTIME(modifiedTime) AS modified_on', 'modifiedName', 'body AS text', 'icon'))), array('name' => 'messages', 'options' => array('name' => 'personal_messages'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('ID_PM AS id', 'ID_MEMBER_FROM AS created_by', "FROM_UNIXTIME(msgtime) AS created_on", 'subject', 'body AS text', 'deletedBySender AS deleted'))), array('name' => 'message_recipients', 'options' => array('name' => 'pm_recipients'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('ID_PM AS id', 'ID_PM AS ninjaboard_message_id', 'ID_MEMBER AS user_id', 'bcc AS is_bcc', 'is_read', 'deleted AS is_deleted'))), array('name' => 'people', 'options' => array('name' => 'members'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('(ID_MEMBER + ' . $member_padding . ' + ' . $member_padding . ') AS id', 'posts', 'signature', 'ID_MEMBER AS temporary_id', "LOWER('ALIAS') AS which_name", 'memberName AS alias')))); //To prevent errors only add this part if the table exists $query = "SHOW TABLES LIKE '#__pretty_topic_urls';"; $sef = KFactory::get('lib.koowa.database')->select($query); if ($sef) { $tables[] = array('name' => 'topic_slugs', 'options' => array('name' => 'pretty_topic_urls'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('ID_TOPIC AS id', 'ID_TOPIC AS ninjaboard_topic_id', 'pretty_url AS ninjaboard_topic_slug'))); } //This returns false if the import is big enough to be done in steps. //So we need to stop the importing in this step, in order for it to initiate if ($this->importData($tables, 'smf_converter') === false) { return $this; } //Turn <br /> into real linebreaks if (isset($this->data['posts'])) { $utc = new DateTimeZone('UTC'); $timezone = new DateTimeZone(date('e')); foreach ($this->data['posts'] as $id => $post) { //Since Ninjaboard stores all dates as GMT, imported datetime values needs to be adjusted $created_on = new DateTime($this->data['posts'][$id]['created_on'], $timezone); $created_on->setTimezone($utc); $this->data['posts'][$id]['created_on'] = $created_on->format('Y-m-d H:i:s'); $modified_on = new DateTime($this->data['posts'][$id]['modified_on'], $timezone); $modified_on->setTimezone($utc); $this->data['posts'][$id]['modified_on'] = $modified_on->format('Y-m-d H:i:s'); $this->data['posts'][$id]['text'] = str_replace(array(' ', '<br />', '&#'), array(' ', "\n", '&#'), $post['text']); } } //Private messages also needs to adjust datetime offsets if (isset($this->data['messages'])) { $utc = new DateTimeZone('UTC'); $timezone = new DateTimeZone(date('e')); foreach ($this->data['messages'] as $id => $message) { //Since Ninjaboard stores all dates as GMT, imported datetime values needs to be adjusted $created_on = new DateTime($this->data['messages'][$id]['created_on'], $timezone); $created_on->setTimezone($utc); $this->data['messages'][$id]['created_on'] = $created_on->format('Y-m-d H:i:s'); $this->data['messages'][$id]['text'] = str_replace(array(' ', '<br />', '&#'), array(' ', "\n", '&#'), $message['text']); } } //Undo the slashes and html special chars that SMF does on all input foreach ($this->data as $name => $table) { foreach ($table as $id => $row) { foreach ($row as $key => $value) { if (!is_string($value)) { continue; } $this->data[$name][$id][$key] = stripslashes(htmlspecialchars_decode($value, ENT_QUOTES)); } } } //Convert html 2 bbcode where needed if (isset($this->data['forums'])) { foreach ($this->data['forums'] as $id => $forum) { if (!isset($this->data['forums'][$id]['description'])) { continue; } $this->data['forums'][$id]['description'] = html2bbcode($forum['description']); } } if (isset($this->data['messages'])) { foreach ($this->data['messages'] as $id => $message) { if (!isset($this->data['messages'][$id]['text'])) { continue; } $this->data['messages'][$id]['text'] = html2bbcode($message['text']); } } //Fix line breaks in signatures if (isset($this->data['people'])) { foreach ($this->data['people'] as $id => $person) { if (!isset($this->data['people'][$id]['signature'])) { continue; } $this->data['people'][$id]['signature'] = str_replace(array('<br />', '&#'), array("\n", '&#'), $person['signature']); } } //Move over file attachments if (isset($this->data['attachments'])) { //Get the attachments path $query = KFactory::tmp('lib.koowa.database.query')->select('value')->from('settings')->where('variable', '=', 'attachmentUploadDir'); $path = KFactory::get('lib.koowa.database')->select($query, KDatabase::FETCH_FIELD); foreach ($this->data['attachments'] as $id => $attachment) { //SMF have two ways of storing attachments if ($attachment['hash']) { $file = $id . '_' . $attachment['hash']; } else { $file = $attachment['name']; /** * The following code is from getLegacyAttachmentFilename defined in SMF/Sources/Sub.php */ // Remove special accented characters - ie. sí. $clean_name = strtr($file, 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'); $clean_name = strtr($clean_name, array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u')); // Sorry, no spaces, dots, or anything else but letters allowed. $clean_name = preg_replace(array('/\\s/', '/[^\\w_\\.\\-]/'), array('_', ''), $clean_name); $enc_name = $id . '_' . strtr($clean_name, '.', '_') . md5($clean_name); $clean_name = preg_replace('~\\.[\\.]+~', '.', $clean_name); $file = JFile::exists($path . '/' . $enc_name) ? $enc_name : $clean_name; } $from = $path . '/' . $file; $file = JPATH_ROOT . '/media/com_ninjaboard/attachments/' . $file; //Don't do anything if attachment don't exist if (!JFile::exists($from)) { continue; } JFile::copy($from, $file); $this->data['attachments'][$id]['file'] = basename($file); } } //Reconnect the lib.koowa.database to the Joomla! database $this->resetDatabaseConnection(); //Clear cache folder so that avatars and attachments cache are cleared //@TODO this should only run once $cache = JPATH_ROOT . '/cache/com_ninjaboard/'; if (JFolder::exists($cache)) { JFolder::delete($cache); } parent::convert(); if (isset($this->data['forums'])) { $this->updateForumPaths(); } return $this; }
/** * Import the sample content * * @return $this */ public function convert() { $tables = array(array('name' => 'attachments', 'options' => array('name' => 'kunena_attachments'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('id', 'mesid AS post', 'filename AS name', 'userid AS joomla_user_id', 'folder', 'hash', 'NULL AS file'))), array('name' => 'forums', 'options' => array('name' => 'kunena_categories'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('tbl.*', "'/' AS path", 'name AS title', 'parent AS parent_id', 'published AS enabled', 'numTopics AS topics', 'numPosts AS posts', 'id_last_msg AS last_post_id'))), array('name' => 'topic_symlinks', 'options' => array('name' => 'kunena_messages'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('id', 'id AS ninjaboard_topic_id', 'catid AS ninjaboard_forum_id'))->join('left', 'kunena_messages_text', 'mesid = id')->where('parent', '=', 0)->where('moved', '=', 1)), array('name' => 'topics', 'options' => array('name' => 'kunena_messages'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('tbl.*', 'catid AS forum_id', 'topic_emoticon AS status', 'id AS first_post_id', '(SELECT COUNT(*) FROM #__kunena_messages WHERE thread = tbl.id AND id != tbl.id) AS replies', '(SELECT MAX(id) FROM #__kunena_messages WHERE thread = tbl.id) AS last_post_id'))->where('parent', '=', 0)->where('moved', '=', 0)), array('name' => 'posts', 'options' => array('name' => 'kunena_messages'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('tbl.*', '!hold AS enabled', 'thread AS ninjaboard_topic_id', 'topic_emoticon AS status', 'id AS first_post_id', 'name AS guest_name', 'email AS guest_email', 'userid AS created_by', 'modified_by AS modified_by', 'FROM_UNIXTIME(time) AS created_on', 'ip AS user_ip', 'FROM_UNIXTIME(modified_time) AS mofidied_on', 'modified_reason AS edit_reason', 'IFNULL(message, \'\') AS text'))->join('left', 'kunena_messages_text', 'mesid = id')->where('moved', '=', 0)), array('name' => 'people', 'options' => array('name' => 'kunena_users'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('*', 'userid AS id'))), array('name' => 'watches', 'options' => array('name' => 'kunena_subscriptions_categories', 'identity_column' => 'id'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('CONCAT(catid, userid) AS id', 'userid AS created_by', 'NOW() AS created_on', '1 AS subscription_type', 'catid AS subscription_type_id'))->where('catid', '>', 0)), array('name' => 'watches', 'options' => array('name' => 'kunena_subscriptions', 'identity_column' => 'id'), 'query' => KFactory::tmp('lib.koowa.database.query')->select(array('(CONCAT(thread, userid) + (SELECT MAX(ninjaboard_subscription_id) FROM #__ninjaboard_subscriptions)) AS id', 'userid AS created_by', 'NOW() AS created_on', '3 AS subscription_type', 'thread AS subscription_type_id'))->where('thread', '>', 0))); //This returns false if the import is big enough to be done in steps. //So we need to stop the importing in this step, in order for it to initiate if ($this->importData($tables, 'kunena') === false) { return $this; } //Move over file attachments if (isset($this->data['attachments'])) { foreach ($this->data['attachments'] as $id => $attachment) { $from = JPATH_ROOT . '/' . $attachment['folder'] . '/' . $attachment['name']; $file = JPATH_ROOT . '/media/com_ninjaboard/attachments/' . $attachment['hash'] . '.' . JFile::getExt($attachment['name']); //Don't do anything if avatar don't exist if (!JFile::exists($from)) { continue; } JFile::copy($from, $file); $this->data['attachments'][$id]['file'] = basename($file); } } //Kunena stores the new location in the text body if (isset($this->data['topic_symlinks'])) { foreach ($this->data['topic_symlinks'] as $id => $topic_symlink) { if (!$topic_symlink['ninjaboard_topic_id']) { continue; } $symlink = explode('=', $topic_symlink['ninjaboard_topic_id']); //Something is wrong, there is no id if (!isset($symlink[1])) { continue; } $this->data['topic_symlinks'][$id]['ninjaboard_topic_id'] = $symlink[1]; } } //Move over avatars if (isset($this->data['people'])) { foreach ($this->data['people'] as $id => $person) { if (!$person['avatar']) { continue; } $from = JPATH_ROOT . '/media/kunena/avatars/' . $person['avatar']; $file = basename($from); $avatar = '/media/com_ninjaboard/images/avatars/' . $person['id'] . '/' . $file; //Don't do anything if avatar don't exist if (!JFile::exists($from)) { continue; } JFile::copy($from, JPATH_ROOT . $avatar); $this->data['people'][$id]['avatar'] = $avatar; } } //Clear cache folder so that avatars and attachments cache are cleared //@TODO this should only run once $cache = JPATH_ROOT . '/cache/com_ninjaboard/'; if (JFolder::exists($cache)) { JFolder::delete($cache); } parent::convert(); if (isset($this->data['forums'])) { $this->updateForumPaths(); } return $this; }