diff --git a/boards/smf/forums.php b/boards/smf/forums.php index bb3e9e8..65f29ef 100644 --- a/boards/smf/forums.php +++ b/boards/smf/forums.php @@ -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']); } @@ -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. diff --git a/boards/smf2/forums.php b/boards/smf2/forums.php index a4d918f..7ef6110 100644 --- a/boards/smf2/forums.php +++ b/boards/smf2/forums.php @@ -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']); } @@ -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. diff --git a/boards/vbulletin3/forums.php b/boards/vbulletin3/forums.php index a19f52e..298ab69 100644 --- a/boards/vbulletin3/forums.php +++ b/boards/vbulletin3/forums.php @@ -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 diff --git a/boards/vbulletin4/forums.php b/boards/vbulletin4/forums.php index 797d108..9871dc6 100644 --- a/boards/vbulletin4/forums.php +++ b/boards/vbulletin4/forums.php @@ -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 diff --git a/boards/vbulletin5/forums.php b/boards/vbulletin5/forums.php index b246f90..d1ce8dd 100644 --- a/boards/vbulletin5/forums.php +++ b/boards/vbulletin5/forums.php @@ -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 diff --git a/resources/modules/forums.php b/resources/modules/forums.php index de8ba01..517ae68 100644 --- a/resources/modules/forums.php +++ b/resources/modules/forums.php @@ -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, @@ -58,6 +59,7 @@ abstract class Converter_Module_Forums extends Converter_Module 'lastposteruid', 'threads', 'posts', + 'pid', 'active', 'open', 'allowhtml',