/**
* Drupal exporter tool
*
* @copyright Saturn Laboratories 2010
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPL2
* @package VanillaPorter
*/
class Drupal extends ExportController {
/** @var array Required tables => columns */
protected $SourceTables = array(
'users' => array('uid', 'name', 'pass', 'mail', 'timezone', 'language', 'created', 'access'),
'role' => array('rid', 'name'),
'users_roles' => array('uid', 'rid'),
'node' => array('nid', 'vid', 'type', 'title', 'uid', 'status', 'created', 'changed'),
'node_revisions' => array('nid', 'vid', 'uid', 'title', 'body', 'teaser', 'log', 'timestamp', 'format'),
'term_data' => array('tid', 'name', 'description', 'weight'),
'term_node' => array('nid', 'tid', 'vid')
);
/**
* Forum-specific export format.
* @param ExportModel $Ex
*/
protected function ForumExport($Ex) {
// Begin
$Ex->BeginExport('', 'Drupal 6.*', array('HashMethod' => 'Drupal'));
// Users
$User_Map = array(
'uid'=>'UserID',
'name'=>'Name',
'pass'=>'Password',
'mail'=>'Email',
'timezone'=>'HourOffset'
);
$Ex->ExportTable('User', "SELECT uid, name, pass, mail, timezone,
FROM_UNIXTIME(nullif(created, 0)) AS DateFirstVisit,
FROM_UNIXTIME(nullif(access, 0)) AS DateLastActive,
FROM_UNIXTIME(nullif(created, 0)) AS DateInserted
FROM :_users", $User_Map); // ":_" will be replace by database prefix
// Categories
$Category_Map = array(
'tid'=>'CategoryID',
'parent'=>'ParentCategoryID',
'name'=>'Name',
'description'=>'Description',
'Depth'=>'Depth'
);
$Ex->ExportTable('Category', "SELECT t.tid,
IF(h.parent = 0, -1, h.parent) AS parent,
t.name,
t.description,
IF(h.parent = 0, 1, 2) AS Depth
FROM :_term_data t
JOIN :_vocabulary v ON t.vid = v.vid
JOIN :_term_hierarchy h ON t.tid = h.tid
WHERE v.module = 'forum'", $Category_Map);
// Discussions
$Discussion_Map = array(
'nid'=>'DiscussionID',
'tid'=>'CategoryID',
'uid'=>'InsertUserID',
'title'=>'Name',
'body' => 'Body',
'Format'=>'Format',
'CountComments' => 'CountComments',
'CountViews'=>'CountViews'
);
$Ex->ExportTable('Discussion', "SELECT n.nid, t.tid, n.uid, n.title, r.body,
(SELECT count(c.cid) FROM :_comments AS c WHERE c.nid = n.nid) + 1 AS CountComments,
(SELECT count(c.cid) FROM :_comments AS c WHERE c.nid = n.nid) + 1 AS CountViews,
'Html' AS Format,
0 AS Closed,
0 AS Announce,
FROM_UNIXTIME(n.created) AS DateInserted
FROM :_node AS n
JOIN :_node_revisions AS r ON n.nid = r.nid AND n.vid = r.vid
JOIN :_term_node AS t ON n.nid = t.nid
WHERE n.type = 'forum'",
$Discussion_Map);
// Comments
$Comment_Map = array(
'cid' => 'CommentID',
'nid' => 'DiscussionID',
'comment' => 'Body',
'Format' => 'Format',
'uid' => 'InsertUserID'
);
$Ex->ExportTable('Comment', "SELECT c.cid, c.nid, c.comment,
'Html' as Format,
c.uid,
FROM_UNIXTIME(c.timestamp) as DateInserted,
FROM_UNIXTIME(c.timestamp) as DateUpdated
FROM :_comments c
JOIN :_node AS n ON c.nid = n.nid AND n.type = 'forum'",
$Comment_Map);
// End
$Ex->EndExport();
}
}