Skip to content

Commit d453ec2

Browse files
authored
Fix #238 Error on importing sub-forum before its parent's been merged. And code improvement. (#239)
* Fix mybb/merge-system:#238 SMF2 module's error on processing sub-forum before its parent's been merged. * Fix mybb/merge-system:#238 SMF module's error on importing sub-forum before its parent's been merged. Improve code format for SMF2's forum module. * Add a TODO mark to lines relating to mybb/merge-system:#238. * Improve code quality: remove some redundant code in `import_forums` module of vbulletin3/vbulletin4/vbulletin5. * Code improvement. * Revert "Add a TODO mark to lines relating to mybb/merge-system:#238." This reverts commit eb09a98. * Add default value (integer) for field `pid` in forums base module
1 parent 55fbf78 commit d453ec2

File tree

6 files changed

+58
-5
lines changed

6 files changed

+58
-5
lines changed

boards/smf/forums.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,17 @@ function convert_data($data)
4343

4444
if($data['ID_PARENT'])
4545
{
46-
$insert_data['pid'] = $this->get_import->fid_f($data['ID_PARENT']);
46+
// Parent forum is a board.
47+
$insert_data['import_pid'] = $data['ID_PARENT'];
48+
49+
// Assign the already merged parent board's ID, otherwise 0.
50+
$pid = $this->get_import->fid_f($data['ID_PARENT']);
51+
$insert_data['pid'] = empty($pid) ? 0 : $pid;
4752
}
4853
else
4954
{
55+
// Parent forum is a category. All categories should have been already merged.
56+
$insert_data['import_pid'] = $data['ID_CAT']; // TODO: may needn't this, and this could be confusing.
5057
$insert_data['pid'] = $this->get_import->fid_c($data['ID_CAT']);
5158
}
5259

@@ -71,6 +78,26 @@ function fetch_total()
7178
return $import_session['total_forums'];
7279
}
7380

81+
/**
82+
* Update imported forums that don't have a parent forum assigned.
83+
*/
84+
function finish()
85+
{
86+
global $db;
87+
88+
// 'f' type forum. Column `pid`'s value is 0 if this forum is merged before its parent being merged.
89+
$query = $db->simple_select("forums", "fid,import_pid", "type = 'f' AND import_fid != 0 AND pid = 0");
90+
while($forum = $db->fetch_array($query))
91+
{
92+
$pid = $this->get_import->fid($forum['import_pid']);
93+
if(!empty($pid)) // Do another check, failure will leave dirty work to parent class's cleanup() function.
94+
{
95+
$db->update_query("forums", array('pid' => $pid), "fid='{$forum['fid']}'", 1);
96+
}
97+
}
98+
$db->free_result($query);
99+
}
100+
74101
/**
75102
* Correctly associate any forums with their correct parent ids. This is automagically run after importing
76103
* forums.

boards/smf2/forums.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,17 @@ function convert_data($data)
4343

4444
if($data['id_parent'])
4545
{
46-
$insert_data['pid'] = $this->get_import->fid_f($data['id_parent']);
46+
// Parent forum is a board.
47+
$insert_data['import_pid'] = $data['id_parent'];
48+
49+
// Assign the already merged parent board's ID, otherwise 0.
50+
$pid = $this->get_import->fid_f($data['id_parent']);
51+
$insert_data['pid'] = empty($pid) ? 0 : $pid;
4752
}
4853
else
4954
{
55+
// Parent forum is a category. All categories should have been already merged.
56+
$insert_data['import_pid'] = $data['id_cat']; // TODO: may needn't this, and this could be confusing.
5057
$insert_data['pid'] = $this->get_import->fid_c($data['id_cat']);
5158
}
5259

@@ -71,6 +78,26 @@ function fetch_total()
7178
return $import_session['total_forums'];
7279
}
7380

81+
/**
82+
* Update imported forums that don't have a parent forum assigned.
83+
*/
84+
function finish()
85+
{
86+
global $db;
87+
88+
// 'f' type forum. Column `pid`'s value is 0 if this forum is merged before its parent being merged.
89+
$query = $db->simple_select("forums", "fid,import_pid", "type = 'f' AND import_fid != 0 AND pid = 0");
90+
while($forum = $db->fetch_array($query))
91+
{
92+
$pid = $this->get_import->fid($forum['import_pid']);
93+
if(!empty($pid)) // Do another check, failure will leave dirty work to parent class's cleanup() function.
94+
{
95+
$db->update_query("forums", array('pid' => $pid), "fid='{$forum['fid']}'", 1);
96+
}
97+
}
98+
$db->free_result($query);
99+
}
100+
74101
/**
75102
* Correctly associate any forums with their correct parent ids. This is automagically run after importing
76103
* forums.

boards/vbulletin3/forums.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ function convert_data($data)
5959
if($data['parentid'] == '-1')
6060
{
6161
$insert_data['type'] = 'c';
62-
$insert_data['import_fid'] = $data['forumid'];
6362
}
6463
// We have a forum
6564
else

boards/vbulletin4/forums.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ function convert_data($data)
5959
if($data['parentid'] == '-1')
6060
{
6161
$insert_data['type'] = 'c';
62-
$insert_data['import_fid'] = $data['forumid'];
6362
}
6463
// We have a forum
6564
else

boards/vbulletin5/forums.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ function convert_data($data)
5959
if($data['parentid'] == '-1')
6060
{
6161
$insert_data['type'] = 'c';
62-
$insert_data['import_fid'] = $data['forumid'];
6362
}
6463
// We have a forum
6564
else

resources/modules/forums.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ abstract class Converter_Module_Forums extends Converter_Module
2525
'threads' => 0,
2626
'posts' => 0,
2727
'type' => 'f',
28+
'pid' => 0,
2829
'active' => 1,
2930
'open' => 1,
3031
'allowhtml' => 0,
@@ -58,6 +59,7 @@ abstract class Converter_Module_Forums extends Converter_Module
5859
'lastposteruid',
5960
'threads',
6061
'posts',
62+
'pid',
6163
'active',
6264
'open',
6365
'allowhtml',

0 commit comments

Comments
 (0)