Skip to content

Commit

Permalink
+ [Kunena#3] phpBB3 support: migrateattachments, uploaded avatars and…
Browse files Browse the repository at this point in the history
… gallery
  • Loading branch information
mahagr committed Jul 7, 2011
1 parent f6d56fa commit 4ebf2b7
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 20 deletions.
8 changes: 7 additions & 1 deletion administrator/components/com_kunenaimporter/CHANGELOG.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

KunenaImporter 1.6.5
KunenaImporter 1.6.5-DEV

6-July-2011 Matias
+ [#3] phpBB3 support: migrate uploaded avatars and gallery

6-July-2011 Matias
+ [#3] phpBB3 support: migrate attachments

5-July-2011 Matias
^ [#1] Convert component to PHP5
Expand Down
6 changes: 3 additions & 3 deletions administrator/components/com_kunenaimporter/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<option value='phpbb3'>phpBB3</option>
<!-- <option value='phpbb2'>phpBB2</option> -->
<!-- <option value='pnphpbb2'>PNphpBB2</option> -->
<option value='smf2'>SMF2</option>
<!-- <option value='smf2'>SMF2</option> -->
</param>
<param name='path' type='text' default='' label='Relative Path to Forum' description='' size='30' />
<!-- <param name='db_host' type='text' default='localhost' label='Database Host' description='' size='30' />
<!-- <param name='path' type='text' default='' label='Relative Path to Forum' description='' size='30' />
<param name='db_host' type='text' default='localhost' label='Database Host' description='' size='30' />
<param name='db_user' type='text' default='' label='Database User' description='' size='30' />
<param name='db_passwd' type='password' default='' label='Database Password' description='' size='30' />
<param name='db_name' type='text' default='' label='Forum Database Name' description='' size='30' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!DOCTYPE install>
<install type="component" version="1.5.19" method="upgrade">
<name>KunenaImporter</name>
<version>1.6.4</version>
<version>1.6.5-DEV</version>
<creationDate>@kunenaversiondate@</creationDate>
<build>@kunenaversionbuild@</build>
<author>Kunena Team</author>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ KNIMPORTER_TASK_USERS=Import Users
KNIMPORTER_TASK_VERSION=Import Version
KNIMPORTER_TASK_WHOISONLINE=Import Online Status
KNIMPORTER_TASK_MAPUSERS=Map users
KNIMPORTER_TASK_AVATARGALLERIES=Import Avatar Galleries
KNIMPORTER_DESCRIPTION_ANNOUNCEMENTS=Import Announcements
KNIMPORTER_DESCRIPTION_ATTACHMENTS=Import Attachments
KNIMPORTER_DESCRIPTION_CATEGORIES=Import Categories
Expand All @@ -42,4 +43,5 @@ KNIMPORTER_DESCRIPTION_USERS=Import Users
KNIMPORTER_DESCRIPTION_VERSION=Import Version
KNIMPORTER_DESCRIPTION_WHOISONLINE=Import Online Status
KNIMPORTER_DESCRIPTION_MAPUSERS=Map users to Joomla
KNIMPORTER_DESCRIPTION_AVATARGALLERIES=Import Avatar Galleries
IMPORT OPTIONS=Import Options
105 changes: 97 additions & 8 deletions administrator/components/com_kunenaimporter/models/export_phpbb3.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,44 @@ public function __construct() {
$component = JComponentHelper::getComponent ( 'com_kunenaimporter' );
$params = new JParameter ( $component->params );

// Use RokBridge
// Use RokBridge if it has been installed
$rokbridge = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_rokbridge' . DS . 'helper.php';
if (is_file ( $rokbridge )) {
require_once ($rokbridge);
$this->rokbridge = new RokBridgeHelper ();
if (isset ( $this->rokbridge->phpbb_db ))
$this->ext_database = $this->rokbridge->phpbb_db;
$this->basepath = JPATH_ROOT."/{$this->rokbridge->phpbb_path}";
$this->relpath = $this->rokbridge->phpbb_path;
}

parent::__construct ();
}

protected function getConfig() {
if (empty($this->config)) {
// Check if database settings are correct
$query = "SELECT config_name, config_value AS value FROM #__config";
$this->ext_database->setQuery ( $query );
$this->config = $this->ext_database->loadObjectList ('config_name');
}
return $this->config;
}

public function checkConfig() {
// Check Kunena compatibility
parent::checkConfig ();
if (JError::isError ( $this->ext_database ))
return;

if ($this->rokbridge)
// Check RokBridge
if ($this->rokbridge) {
$this->addMessage ( '<div>RokBridge: <b style="color:green">detected</b></div>' );
$query = "SELECT config_value FROM #__config WHERE config_name='version'";
$this->ext_database->setQuery ( $query );
$this->version = $this->ext_database->loadResult ();
if (! $this->version) {
}

// Check if database settings are correct
$config = $this->getConfig();
if (empty($config['version'])) {
$this->error = $this->ext_database->getErrorMsg ();
if (! $this->error)
$this->error = 'Configuration information missing: phpBB version not found';
Expand All @@ -61,6 +76,8 @@ public function checkConfig() {
return false;
}

// Check version number
$this->version = $config['version']->value;
if ($this->version [0] == '.')
$this->version = '2' . $this->version;
$version = explode ( '.', $this->version, 3 );
Expand All @@ -73,11 +90,13 @@ public function checkConfig() {
}
$this->addMessage ( '<div>phpBB version: <b style="color:green">' . $this->version . '</b></div>' );

// Check authentication method
$query = "SELECT config_value FROM #__config WHERE config_name='auth_method'";
$this->ext_database->setQuery ( $query );
$this->auth_method = $this->ext_database->loadResult () or die ( "<br />Invalid query:<br />$query<br />" . $this->ext_database->errorMsg () );
$this->addMessage ( '<div>phpBB authentication method: <b style="color:green">' . $this->auth_method . '</b></div>' );

// Find out which field is used as username
$fields = $this->ext_database->getTableFields('#__users');
$this->login_field = isset($fields['#__users']['login_name']);
}
Expand All @@ -93,9 +112,11 @@ public function buildImportOps() {
$importOps ['categories'] = array ('count' => 'countCategories', 'export' => 'exportCategories' );
$importOps ['config'] = array ('count' => 'countConfig', 'export' => 'exportConfig' );
$importOps ['messages'] = array ('count' => 'countMessages', 'export' => 'exportMessages' );
$importOps ['attachments'] = array ('count' => 'countAttachments', 'export' => 'exportAttachments' );
$importOps ['sessions'] = array ('count' => 'countSessions', 'export' => 'exportSessions' );
$importOps ['subscriptions'] = array ('count' => 'countSubscriptions', 'export' => 'exportSubscriptions' );
$importOps ['userprofile'] = array ('count' => 'countUserProfile', 'export' => 'exportUserProfile' );
$importOps ['avatargalleries'] = array ('count' => 'countAvatarGalleries', 'export' => 'exportAvatarGalleries' );
$this->importOps = $importOps;
}

Expand Down Expand Up @@ -345,6 +366,30 @@ public function &exportMessages($start = 0, $limit = 0) {
return $result;
}

public function countAttachments() {
$query = "SELECT COUNT(*) FROM `#__attachments`";
return $this->getCount ( $query );
}
public function &exportAttachments($start = 0, $limit = 0) {
$query = "SELECT
attach_id AS id,
post_msg_id AS mesid,
poster_id AS userid,
NULL AS hash,
filesize AS size,
'phpbb3' AS folder,
IF(LENGTH(mimetype)>0,mimetype,extension) AS filetype,
real_filename AS filename,
physical_filename AS location
FROM `#__attachments`
ORDER BY attach_id";
$result = $this->getExportData ( $query, $start, $limit, 'id' );
foreach ( $result as &$row ) {
$row->location = "{$this->basepath}/files/{$row->location}";
}
return $result;
}

public function countSessions() {
$query = "SELECT COUNT(*) FROM `#__users` AS u WHERE user_lastvisit>0";
return $this->getCount ( $query );
Expand Down Expand Up @@ -396,7 +441,7 @@ public function &exportUserProfile($start = 0, $limit = 0) {
NULL AS banned,
0 AS ordering,
u.user_posts AS posts,
NULL AS avatar,
user_avatar AS avatar,
0 AS karma,
0 AS karma_time,
1 AS group_id,
Expand Down Expand Up @@ -425,14 +470,38 @@ public function &exportUserProfile($start = 0, $limit = 0) {
u.user_website AS websiteurl,
0 AS rank,
1 AS hideEmail,
1 AS showOnline
1 AS showOnline,
user_avatar_type AS avatartype
FROM `#__users` AS u
WHERE u.user_id > 0 AND u.user_type != 2
ORDER BY u.user_id";
$result = $this->getExportData ( $query, $start, $limit, 'userid' );

$path = $this->config['avatar_path']->value;
$salt = $this->config['avatar_salt']->value;
foreach ( $result as &$row ) {
// Convert bbcode in signature
if ($row->avatar) {
switch ($row->avatartype) {
case 1:
// Uploaded
$filename = (int) $row->avatar;
$ext = substr(strrchr($row->avatar, '.'), 1);
$row->avatar = "users/{$row->avatar}";
$row->avatarpath = "{$this->basepath}/{$path}/{$salt}_{$filename}.{$ext}";
break;
case 2:
// URL not supported
$row->avatar = '';
break;
case 3:
// Gallery
$row->avatar = "gallery/{$row->avatar}";
break;
default:
$row->avatar = '';
}
}
$row->signature = $this->prep ( $row->signature );
$row->location = $this->prep ( $row->location );
}
Expand Down Expand Up @@ -472,6 +541,26 @@ public function &exportUsers($start = 0, $limit = 0) {
return $result;
}

protected function &getAvatarGalleries() {
static $galleries = false;
if ($galleries === false) {
$path = "{$this->basepath}/{$this->config['avatar_gallery_path']->value}";
$galleries = array();
$folders = JFolder::folders($path);
foreach ($folders as $folder) {
$galleries[$folder] = "{$path}/{$folder}";
}
}
return $galleries;
}
public function countAvatarGalleries() {
return count($this->getAvatarGalleries());
}
public function &exportAvatarGalleries($start = 0, $limit = 0) {
$galleries = $this->getAvatarGalleries();
return array_slice($galleries, $start, $limit);
}

public function mapJoomlaUser($joomlauser) {

if (!$this->rokbridge) return false;
Expand Down
87 changes: 83 additions & 4 deletions administrator/components/com_kunenaimporter/models/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct() {

public function getImportOptions() {
// version
$options = array ('users','mapusers','config', 'userprofile', 'categories', 'messages', 'attachments', 'favorites', 'subscriptions', 'moderation', 'ranks', 'smilies', 'announcements', 'sessions', 'whoisonline' );
$options = array ('users','mapusers','config', 'userprofile', 'categories', 'messages', 'attachments', 'favorites', 'subscriptions', 'moderation', 'ranks', 'smilies', 'announcements', 'sessions', 'whoisonline', 'avatargalleries' );
return $options;
}

Expand Down Expand Up @@ -72,7 +72,7 @@ public function getUsername($name) {
return strtr ( $name, "<>\"'%;()&", '_________' );
}

protected function findPotentialUsers($extuser, $all = false) {
public function findPotentialUsers($extuser, $all = false) {
// Check if user exists in Joomla
$query = "SELECT u.*
FROM `#__users` AS u
Expand Down Expand Up @@ -180,7 +180,7 @@ protected function UpdateCatStats() {
}

public function truncateData($option) {
if ($option == 'config')
if ($option == 'config' || $option == 'avatargalleries')
return;
if ($option == 'mapusers')
return;
Expand All @@ -190,9 +190,10 @@ public function truncateData($option) {
$this->truncateData ( $option . '_text' );
$this->db = JFactory::getDBO ();
$table = JTable::getInstance ( $option, 'KunenaImporterTable' );
if (!$table) die ("<br />{$option}: Table doesn't exist!");
$query = "TRUNCATE TABLE " . $this->db->nameQuote ( $table->getTableName () );
$this->db->setQuery ( $query );
$result = $this->db->query () or die ( "<br />Invalid query:<br />$query<br />" . $this->db->errorMsg () );
$result = $this->db->query () or die ( "<br />{$option}: Invalid query:<br />$query<br />" . $this->db->errorMsg () );
}

/*
Expand Down Expand Up @@ -229,10 +230,19 @@ public function importData($option, &$data) {
case 'messages' :
$this->importMessages ( $data );
break;
case 'attachments':
$this->importAttachments ( $data );
break;
case 'subscriptions' :
case 'favorites' :
$this->importUnique ( $option, $data );
break;
case 'userprofile':
$this->importUserProfile ( $data );
break;
case 'avatargalleries':
$this->importAvatarGalleries ( $data );
break;
case 'mapusers':
break;
case 'users':
Expand Down Expand Up @@ -267,6 +277,75 @@ protected function importUnique($option, &$data) {
$this->commitEnd ();
}

protected function importAttachments(&$data) {
$table = JTable::getInstance ( 'attachments', 'KunenaImporterTable' );
if (! $table)
die ( $option );

$extids = array();
foreach ( $data as $item ) {
if (!empty($item->userid)) $extids[$item->userid] = $item->userid;
}
$extuser = JTable::getInstance ( 'ExtUser', 'KunenaImporterTable' );
$idmap = $extuser->loadIdMap($extids);

$this->commitStart ();
foreach ( $data as $item ) {
if (isset($idmap[$item->userid])) {
$item->userid = $idmap[$item->userid]->id ? $idmap[$item->userid]->id : -$idmap[$item->userid]->extid;
}
$item->folder = 'media/kunena/attachments/'.$item->folder;
if (file_exists($item->location)) {
$path = JPATH_ROOT."/{$item->folder}";

// Create upload folder and index.html
if (!JFolder::exists($path) && JFolder::create($path)) {
JFile::write("{$path}/index.html",'<html><body></body></html>');
}
$item->hash = md5_file ( $item->location );
JFile::copy($item->location, "{$path}/{$item->filename}");
}
if ($table->save ( $item ) === false)
die ( "ERROR: " . $table->getError () );
}
$this->commitEnd ();
}

protected function importAvatarGalleries(&$data) {
foreach ( $data as $item=>$path ) {
// Copy gallery
JFolder::copy($path, JPATH_ROOT."/media/kunena/avatars/gallery/{$item}", '', true);
// Create index.html
JFile::write(JPATH_ROOT."/media/kunena/avatars/gallery/{$item}/index.html",'<html><body></body></html>');
}
}

protected function importUserProfile(&$data) {
$table = JTable::getInstance ( 'UserProfile', 'KunenaImporterTable' );
if (! $table)
die ( $option );

$extids = array();
foreach ( $data as $item ) {
if (!empty($item->userid)) $extids[$item->userid] = $item->userid;
}
$extuser = JTable::getInstance ( 'ExtUser', 'KunenaImporterTable' );
$idmap = $extuser->loadIdMap($extids);

$this->commitStart ();
foreach ( $data as $item ) {
if (isset($idmap[$item->userid])) {
$item->userid = $idmap[$item->userid]->id ? $idmap[$item->userid]->id : -$idmap[$item->userid]->extid;
}
if (!empty($item->avatarpath) && file_exists($item->avatarpath)) {
JFile::copy($item->avatarpath, JPATH_ROOT."/media/kunena/avatars/users/{$item->avatar}");
}
if ($table->save ( $item ) === false)
die ( "ERROR: " . $table->getError () );
}
$this->commitEnd ();
}

protected function importDefault($option, &$data) {
$table = JTable::getInstance ( $option, 'KunenaImporterTable' );
if (! $table)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function bind($array, $ignore = '') {
return true;
}

public public function save($data) {
public function save($data) {
$this->remove ();
$this->bind ( $data );
$this->create ();
Expand Down
4 changes: 2 additions & 2 deletions build/build.number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Tue Jul 05 18:23:21 EEST 2011
build.number=163
#Thu Jul 07 21:02:39 EEST 2011
build.number=194

0 comments on commit 4ebf2b7

Please sign in to comment.