Skip to content

Commit

Permalink
Fix #238 Error on importing sub-forum before its parent's been merged…
Browse files Browse the repository at this point in the history
…. 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
  • Loading branch information
yuliu authored Aug 5, 2020
1 parent 55fbf78 commit d453ec2
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
29 changes: 28 additions & 1 deletion boards/smf/forums.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ function convert_data($data)

if($data['ID_PARENT'])
{
$insert_data['pid'] = $this->get_import->fid_f($data['ID_PARENT']);
// Parent forum is a board.
$insert_data['import_pid'] = $data['ID_PARENT'];

// Assign the already merged parent board's ID, otherwise 0.
$pid = $this->get_import->fid_f($data['ID_PARENT']);
$insert_data['pid'] = empty($pid) ? 0 : $pid;
}
else
{
// Parent forum is a category. All categories should have been already merged.
$insert_data['import_pid'] = $data['ID_CAT']; // TODO: may needn't this, and this could be confusing.
$insert_data['pid'] = $this->get_import->fid_c($data['ID_CAT']);
}

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

/**
* Update imported forums that don't have a parent forum assigned.
*/
function finish()
{
global $db;

// 'f' type forum. Column `pid`'s value is 0 if this forum is merged before its parent being merged.
$query = $db->simple_select("forums", "fid,import_pid", "type = 'f' AND import_fid != 0 AND pid = 0");
while($forum = $db->fetch_array($query))
{
$pid = $this->get_import->fid($forum['import_pid']);
if(!empty($pid)) // Do another check, failure will leave dirty work to parent class's cleanup() function.
{
$db->update_query("forums", array('pid' => $pid), "fid='{$forum['fid']}'", 1);
}
}
$db->free_result($query);
}

/**
* Correctly associate any forums with their correct parent ids. This is automagically run after importing
* forums.
Expand Down
29 changes: 28 additions & 1 deletion boards/smf2/forums.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ function convert_data($data)

if($data['id_parent'])
{
$insert_data['pid'] = $this->get_import->fid_f($data['id_parent']);
// Parent forum is a board.
$insert_data['import_pid'] = $data['id_parent'];

// Assign the already merged parent board's ID, otherwise 0.
$pid = $this->get_import->fid_f($data['id_parent']);
$insert_data['pid'] = empty($pid) ? 0 : $pid;
}
else
{
// Parent forum is a category. All categories should have been already merged.
$insert_data['import_pid'] = $data['id_cat']; // TODO: may needn't this, and this could be confusing.
$insert_data['pid'] = $this->get_import->fid_c($data['id_cat']);
}

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

/**
* Update imported forums that don't have a parent forum assigned.
*/
function finish()
{
global $db;

// 'f' type forum. Column `pid`'s value is 0 if this forum is merged before its parent being merged.
$query = $db->simple_select("forums", "fid,import_pid", "type = 'f' AND import_fid != 0 AND pid = 0");
while($forum = $db->fetch_array($query))
{
$pid = $this->get_import->fid($forum['import_pid']);
if(!empty($pid)) // Do another check, failure will leave dirty work to parent class's cleanup() function.
{
$db->update_query("forums", array('pid' => $pid), "fid='{$forum['fid']}'", 1);
}
}
$db->free_result($query);
}

/**
* Correctly associate any forums with their correct parent ids. This is automagically run after importing
* forums.
Expand Down
1 change: 0 additions & 1 deletion boards/vbulletin3/forums.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ function convert_data($data)
if($data['parentid'] == '-1')
{
$insert_data['type'] = 'c';
$insert_data['import_fid'] = $data['forumid'];
}
// We have a forum
else
Expand Down
1 change: 0 additions & 1 deletion boards/vbulletin4/forums.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ function convert_data($data)
if($data['parentid'] == '-1')
{
$insert_data['type'] = 'c';
$insert_data['import_fid'] = $data['forumid'];
}
// We have a forum
else
Expand Down
1 change: 0 additions & 1 deletion boards/vbulletin5/forums.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ function convert_data($data)
if($data['parentid'] == '-1')
{
$insert_data['type'] = 'c';
$insert_data['import_fid'] = $data['forumid'];
}
// We have a forum
else
Expand Down
2 changes: 2 additions & 0 deletions resources/modules/forums.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ abstract class Converter_Module_Forums extends Converter_Module
'threads' => 0,
'posts' => 0,
'type' => 'f',
'pid' => 0,
'active' => 1,
'open' => 1,
'allowhtml' => 0,
Expand Down Expand Up @@ -58,6 +59,7 @@ abstract class Converter_Module_Forums extends Converter_Module
'lastposteruid',
'threads',
'posts',
'pid',
'active',
'open',
'allowhtml',
Expand Down

0 comments on commit d453ec2

Please sign in to comment.