forked from vanilla/porter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.skeleton.php
172 lines (154 loc) · 7.15 KB
/
class.skeleton.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
/**
* [Platform] exporter tool.
*
* @copyright Vanilla Forums Inc. 2010-2014
* @license GNU GPL2
* @package VanillaPorter
* @see functions.commandline.php for command line usage.
*/
// Add to the $Supported array so it appears in the dropdown menu. Uncomment next line.
//$Supported['slugname'] = array('name'=> 'Proper Platform Name', 'prefix'=>'x_');
class SlugName extends ExportController {
/**
* You can use this to require certain tables and columns be present.
*
* This can be useful for verifying data integrity. Don't specify more columns
* than your porter actually requires to avoid forwards-compatibility issues.
*
* @var array Required tables => columns
*/
protected $SourceTables = array(
'forums' => array(), // This just requires the 'forum' table without caring about columns.
'posts' => array(),
'topics' => array(),
'users' => array('ID', 'user_login', 'user_pass', 'user_email'), // Require specific cols on 'users'
);
/**
* Main export process.
*
* @param ExportModel $Ex
* @see $_Structures in ExportModel for allowed destination tables & columns.
*/
public function ForumExport($Ex) {
// Get the characterset for the comments.
// Usually the comments table is the best target for this.
$CharacterSet = $Ex->GetCharacterSet('CommentsTableNameGoesHere');
if ($CharacterSet)
$Ex->CharacterSet = $CharacterSet;
// Reiterate the platform name here to be included in the porter file header.
$Ex->BeginExport('', 'Proper Platform Name');
// It's usually a good idea to do the porting in the approximate order laid out here.
// User.
// Map as much as possible using the $x_Map array for clarity.
// Key is always the source column name.
// Value is either the destination column or an array of meta data, usually Column & Filter.
// If it's a meta array, 'Column' is the destination column name and 'Filter' is a method name to run it thru.
// Here, 'HTMLDecoder' is a method in ExportModel. Check there for available filters.
// Assume no filter is needed and only use one if you encounter issues.
$User_Map = array(
'Author_ID' => 'UserID',
'Username' => array('Column' => 'Name', 'Filter' => array($Ex, 'HTMLDecoder')),
);
// This is the query that the x_Map array above will be mapped against.
// Therefore, our select statement must cover all the "source" columns.
// It's frequently necessary to add joins, where clauses, and more to get the data we want.
// The :_ before the table name is the placeholder for the prefix designated. It gets swapped on the fly.
$Ex->ExportTable('User', "
select u.*
from :_User u
", $User_Map);
// Role.
// The Vanilla roles table will be wiped by any import. If your current platform doesn't have roles,
// you can hard code new ones into the select statement. See Vanilla's defaults for a good example.
$Role_Map = array(
'Group_ID' => 'RoleID',
'Name' => 'Name', // We let these arrays end with a comma to prevent typos later as we add.
);
$Ex->ExportTable('Role', "
select *
from :_tblGroup", $Role_Map);
// User Role.
// Really simple matchup.
// Note that setting Admin=1 on the User table trumps all roles & permissions with "owner" privileges.
// Whatever account you select during the import will get the Admin=1 flag to prevent permissions issues.
$UserRole_Map = array(
'Author_ID' => 'UserID',
'Group_ID' => 'RoleID',
);
$Ex->ExportTable('UserRole', "
select u.*
from :_tblAuthor u", $UserRole_Map);
// Permission.
// Feel free to add a permission export if this is a major platform or it will see reuse.
// For small or custom jobs, it's usually not worth it. Just fix them afterward.
// UserMeta.
// This is an example of pulling Signatures into Vanilla's UserMeta table.
// This is often a good place for any extraneous data on the User table too.
// The Profile Extender addon uses the namespace "Profile.[FieldName]"
// You can add the appropriately-named fields after the migration and profiles will auto-populate with the migrated data.
$Ex->ExportTable('UserMeta', "
select
Author_ID as UserID,
'Plugin.Signatures.Sig' as `Name`,
Signature as `Value`
from :_tblAuthor
where Signature <> ''");
// Category.
// Be careful to not import hundreds of categories. Try translating huge schemas to Tags instead.
// Numeric category slugs aren't allowed in Vanilla, so be careful to sidestep those.
// Don't worry about rebuilding the TreeLeft & TreeRight properties. Vanilla can fix this afterward
// if you just get the Sort and ParentIDs correct.
$Category_Map = array(
'Forum_ID' => 'CategoryID',
'Forum_name' => 'Name',
);
$Ex->ExportTable('Category', "
select *
from :_tblCategory c
", $Category_Map);
// Discussion.
// A frequent issue is for the OPs content to be on the comment/post table, so you may need to join it.
$Discussion_Map = array(
'Topic_ID' => 'DiscussionID',
'Forum_ID' => 'CategoryID',
'Author_ID' => 'InsertUserID',
'Subject' => array('Column' => 'Name', 'Filter' => array($Ex, 'HTMLDecoder')),
);
// It's easier to convert between Unix time and MySQL datestamps during the db query.
$Ex->ExportTable('Discussion', "
select *,
FROM_UNIXTIME(Message_date) as Message_date
from :_tblTopic t
join :_tblThread th
on t.Start_Thread_ID = th.Thread_ID", $Discussion_Map);
// Comment.
// This is where big migrations are going to get bogged down.
// Be sure you have indexes created for any columns you are joining on.
$Comment_Map = array(
'Thread_ID' => 'CommentID',
'Topic_ID' => 'DiscussionID',
'Author_ID' => 'InsertUserID',
'IP_addr' => 'InsertIPAddress',
'Message' => array('Column' => 'Body'),
'Format' => 'Format',
'Message_date' => array('Column' => 'DateInserted')
);
$Ex->ExportTable('Comment', "
select th.*
from :_tblThread th", $Comment_Map);
// UserDiscussion.
// This is the table for assigning bookmarks/subscribed threads.
// Media.
// Attachment data goes here. Vanilla attachments are files under the /uploads folder.
// This is usually the trickiest step because you need to translate file paths.
// If you need to export blobs from the database, see the vBulletin porter.
// Conversations.
// Private messages often involve the most data manipulation.
// If you need a large number of complex SQL statements, consider making it a separate method
// to keep the main process easy to understand. Pass $Ex as a parameter if you do.
$Ex->EndExport();
}
}
// Closing PHP tag required.
?>