From 38b443f94ae7011a076657201c9ee18b8511a433 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 9 Jun 2016 21:32:16 +0200 Subject: [PATCH] Export boards, threads and posts (Xobor) --- .../system/exporter/XoborExporter.class.php | 128 +++++++++++++++++- 1 file changed, 124 insertions(+), 4 deletions(-) diff --git a/files/lib/system/exporter/XoborExporter.class.php b/files/lib/system/exporter/XoborExporter.class.php index 135ed28..6251a20 100644 --- a/files/lib/system/exporter/XoborExporter.class.php +++ b/files/lib/system/exporter/XoborExporter.class.php @@ -32,6 +32,9 @@ class XoborExporter extends AbstractExporter { */ protected $methods = array( 'com.woltlab.wcf.user' => 'Users', + 'com.woltlab.wbb.board' => 'Boards', + 'com.woltlab.wbb.thread' => 'Threads', + 'com.woltlab.wbb.post' => 'Posts', ); /** @@ -50,6 +53,8 @@ class XoborExporter extends AbstractExporter { return array( 'com.woltlab.wcf.user' => array( ), + 'com.woltlab.wbb.board' => array( + ), ); } @@ -68,10 +73,6 @@ class XoborExporter extends AbstractExporter { * @see \wcf\system\exporter\IExporter::validateFileAccess() */ public function validateFileAccess() { - if (in_array('com.woltlab.wcf.user.avatar', $this->selectedData) || in_array('com.woltlab.wbb.attachment', $this->selectedData) || in_array('com.woltlab.wcf.conversation.attachment', $this->selectedData)) { - return false; - } - return true; } @@ -86,6 +87,13 @@ class XoborExporter extends AbstractExporter { $queue[] = 'com.woltlab.wcf.user'; } + // board + if (in_array('com.woltlab.wbb.board', $this->selectedData)) { + $queue[] = 'com.woltlab.wbb.board'; + $queue[] = 'com.woltlab.wbb.thread'; + $queue[] = 'com.woltlab.wbb.post'; + } + return $queue; } @@ -122,6 +130,118 @@ class XoborExporter extends AbstractExporter { } } + /** + * Counts boards. + */ + public function countBoards() { + $sql = "SELECT COUNT(*) AS count + FROM forum_foren"; + $statement = $this->database->prepareStatement($sql); + $statement->execute(); + $row = $statement->fetchArray(); + return ($row['count'] ? 1 : 0); + } + + /** + * Exports boards. + */ + public function exportBoards($offset, $limit) { + $sql = "SELECT * + FROM forum_foren + ORDER BY zuid, sort, id"; + $statement = $this->database->prepareStatement($sql); + $statement->execute(); + while ($row = $statement->fetchArray()) { + $this->boardCache[$row['zuid']][] = $row; + } + + $this->exportBoardsRecursively(); + } + + /** + * Exports the boards recursively. + */ + protected function exportBoardsRecursively($parentID = 0) { + if (!isset($this->boardCache[$parentID])) return; + + foreach ($this->boardCache[$parentID] as $board) { + ImportHandler::getInstance()->getImporter('com.woltlab.wbb.board')->import($board['id'], array( + 'parentID' => ($board['zuid'] ?: null), + 'position' => $board['sort'], + 'boardType' => ($board['iscat'] ? Board::TYPE_CATEGORY : Board::TYPE_BOARD), + 'title' => $board['title'], + 'description' => $board['text'] + )); + + $this->exportBoardsRecursively($board['id']); + } + } + + /** + * Counts threads. + */ + public function countThreads() { + return $this->__getMaxID("forum_threads", 'id'); + } + + /** + * Exports threads. + */ + public function exportThreads($offset, $limit) { + $sql = "SELECT * + FROM forum_threads + WHERE id BETWEEN ? AND ? + ORDER BY id"; + $statement = $this->database->prepareStatement($sql); + $statement->execute(array($offset + 1, $offset + $limit)); + while ($row = $statement->fetchArray()) { + $data = array( + 'boardID' => $row['forum'], + 'topic' => $row['title'], + 'time' => $row['created'], + 'userID' => $row['userid'], + 'username' => $row['name'], + 'views' => $row['hits'], + 'isSticky' => $row['header'] ? 1 : 0 + ); + + ImportHandler::getInstance()->getImporter('com.woltlab.wbb.thread')->import($row['id'], $data, array()); + } + } + + /** + * Counts posts. + */ + public function countPosts() { + return $this->__getMaxID("forum_posts", 'id'); + } + + /** + * Exports posts. + */ + public function exportPosts($offset, $limit) { + $sql = "SELECT * + FROM forum_posts + WHERE id BETWEEN ? AND ? + ORDER BY id"; + $statement = $this->database->prepareStatement($sql); + $statement->execute(array($offset + 1, $offset + $limit)); + while ($row = $statement->fetchArray()) { + ImportHandler::getInstance()->getImporter('com.woltlab.wbb.post')->import($row['id'], array( + 'threadID' => $row['thread'], + 'userID' => $row['userid'], + 'username' => $row['username'], + 'subject' => $row['title'], + 'message' => $row['text'], + 'time' => strtotime($row['writetime']), + 'editorID' => null, + 'enableHtml' => 1, + 'isClosed' => 1, + 'ipAddress' => UserUtil::convertIPv4To6($row['signature']) + )); + } + } + private static function fixMessage($string) { return $string; } -- 2.20.1