From 4a1fdbaf47876788fa734838d29b0d3d9648e5cf Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Mon, 28 Mar 2022 15:41:25 +0200 Subject: [PATCH] Support for gallery import from IPB3 --- .../system/exporter/IPB3xExporter.class.php | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/files/lib/system/exporter/IPB3xExporter.class.php b/files/lib/system/exporter/IPB3xExporter.class.php index 58f74a5..ddf7d77 100644 --- a/files/lib/system/exporter/IPB3xExporter.class.php +++ b/files/lib/system/exporter/IPB3xExporter.class.php @@ -53,6 +53,9 @@ class IPB3xExporter extends AbstractExporter 'com.woltlab.wbb.poll' => 'Polls', 'com.woltlab.wbb.poll.option.vote' => 'PollOptionVotes', 'com.woltlab.wbb.like' => 'Likes', + 'com.woltlab.gallery.category' => 'GalleryCategories', + 'com.woltlab.gallery.album' => 'GalleryAlbums', + 'com.woltlab.gallery.image' => 'GalleryImages', ]; /** @@ -77,6 +80,10 @@ class IPB3xExporter extends AbstractExporter 'com.woltlab.wcf.conversation' => [ 'com.woltlab.wcf.conversation.attachment', ], + 'com.woltlab.gallery.image' => [ + 'com.woltlab.gallery.category', + 'com.woltlab.gallery.album', + ], ]; } @@ -102,6 +109,7 @@ class IPB3xExporter extends AbstractExporter \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) + || \in_array('com.woltlab.gallery.image', $this->selectedData) ) { if (empty($this->fileSystemPath) || !@\file_exists($this->fileSystemPath . 'conf_global.php')) { return false; @@ -173,6 +181,17 @@ class IPB3xExporter extends AbstractExporter } } + // gallery + if (\in_array('com.woltlab.gallery.image', $this->selectedData)) { + if (\in_array('com.woltlab.gallery.category', $this->selectedData)) { + $queue[] = 'com.woltlab.gallery.category'; + } + if (\in_array('com.woltlab.gallery.album', $this->selectedData)) { + $queue[] = 'com.woltlab.gallery.album'; + } + $queue[] = 'com.woltlab.gallery.image'; + } + return $queue; } @@ -1205,6 +1224,143 @@ class IPB3xExporter extends AbstractExporter } } + /** + * Counts gallery categories. + */ + public function countGalleryCategories() + { + $sql = "SELECT COUNT(*) AS count + FROM " . $this->databasePrefix . "gallery_categories"; + $statement = $this->database->prepareStatement($sql); + $statement->execute(); + $row = $statement->fetchArray(); + + return $row['count']; + } + + /** + * Exports gallery categories. + * + * @param integer $offset + * @param integer $limit + */ + public function exportGalleryCategories($offset, $limit) + { + $sql = "SELECT * + FROM " . $this->databasePrefix . "gallery_categories + ORDER BY category_id"; + $statement = $this->database->prepareStatement($sql, $limit, $offset); + $statement->execute(); + while ($row = $statement->fetchArray()) { + $data = [ + 'title' => $row['category_name'], + 'description' => $row['category_description'], + 'parentCategoryID' => $row['category_parent_id'], + ]; + + ImportHandler::getInstance() + ->getImporter('com.woltlab.gallery.category') + ->import($row['category_id'], $data); + } + } + + /** + * Counts gallery albums. + */ + public function countGalleryAlbums() + { + return $this->__getMaxID($this->databasePrefix . "gallery_albums", 'album_id'); + } + + /** + * Exports gallery albums. + * + * @param integer $offset + * @param integer $limit + */ + public function exportGalleryAlbums($offset, $limit) + { + $sql = "SELECT albums.*, members.name AS username + FROM " . $this->databasePrefix . "gallery_albums albums + LEFT JOIN " . $this->databasePrefix . "members members + ON members.member_id = albums.album_owner_id + WHERE albums.album_id BETWEEN ? AND ? + ORDER BY albums.album_id"; + $statement = $this->database->prepareStatement($sql); + $statement->execute([$offset + 1, $offset + $limit]); + while ($row = $statement->fetchArray()) { + $data = [ + 'userID' => $row['album_owner_id'], + 'username' => $row['username'] ?: '', + 'title' => $row['album_name'], + 'description' => StringUtil::stripHTML($row['album_description']), + 'lastUpdateTime' => $row['album_last_img_date'], + ]; + + ImportHandler::getInstance() + ->getImporter('com.woltlab.gallery.album') + ->import($row['album_id'], $data); + } + } + + /** + * Counts gallery images. + */ + public function countGalleryImages() + { + return $this->__getMaxID($this->databasePrefix . "gallery_images", 'image_id'); + } + + /** + * Exports gallery images. + * + * @param integer $offset + * @param integer $limit + */ + public function exportGalleryImages($offset, $limit) + { + $sql = "SELECT images.*, members.name AS username + FROM " . $this->databasePrefix . "gallery_images images + LEFT JOIN " . $this->databasePrefix . "members members + ON members.member_id = images.image_member_id + WHERE image_id BETWEEN ? AND ? + ORDER BY image_id"; + $statement = $this->database->prepareStatement($sql); + $statement->execute([$offset + 1, $offset + $limit]); + while ($row = $statement->fetchArray()) { + $fileLocation = $this->fileSystemPath . 'uploads/' . $row['image_directory'] . '/' . $row['image_masked_file_name']; + if (!\file_exists($fileLocation)) { + continue; + } + + $data = [ + 'userID' => $row['image_member_id'] ?: null, + 'username' => $row['username'] ?: '', + 'albumID' => $row['image_album_id'] ?: null, + 'title' => $row['image_caption'], + 'description' => self::fixMessage($row['image_description']), + 'filename' => $row['image_file_name'], + 'fileExtension' => \pathinfo($row['image_file_name'], \PATHINFO_EXTENSION), + 'views' => $row['image_views'], + 'uploadTime' => $row['image_date'], + 'creationTime' => $row['image_date'], + ]; + + $additionalData = [ + 'fileLocation' => $fileLocation, + ]; + $additionalData['categories'] = [$row['image_category_id']]; + + ImportHandler::getInstance() + ->getImporter('com.woltlab.gallery.image') + ->import( + $row['image_id'], + $data, + $additionalData + ); + } + } + /** * Returns the data of tags. * -- 2.20.1