From 17cf9d1e2e8bb80403a177a5bbb7f8ba350afc6d Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Tue, 19 Dec 2023 12:58:31 +0100 Subject: [PATCH] Export cover photos for entries --- .../system/exporter/WBB4xExporter.class.php | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/files/lib/system/exporter/WBB4xExporter.class.php b/files/lib/system/exporter/WBB4xExporter.class.php index e82b3f1..1750db5 100644 --- a/files/lib/system/exporter/WBB4xExporter.class.php +++ b/files/lib/system/exporter/WBB4xExporter.class.php @@ -2058,8 +2058,7 @@ final class WBB4xExporter extends AbstractExporter $additionalData['languageCode'] = $row['languageCode']; } if ($sourceVersion52 && $destVersion52 && $row['coverPhotoID']) { - $directory = \substr($row["fileHash"], 0, 2); - $additionalData['coverPhoto'] = "{$blogFilePath}images/coverPhotos/{$directory}/{$row["coverPhotoID"]}-{$row["fileHash"]}.{$row["fileExtension"]}"; + $additionalData['coverPhoto'] = $this->getCoverPhotoPath($blogFilePath, $row); } ImportHandler::getInstance() @@ -2122,6 +2121,24 @@ final class WBB4xExporter extends AbstractExporter '2.1.0 Alpha 1', '>=' ); + $sourceVersion52 = \version_compare( + $this->getPackageVersion('com.woltlab.blog'), + '5.2.0 Alpha 1', + '>=' + ); + $destVersion52 = \version_compare( + BLOGCore::getInstance()->getPackage()->packageVersion, + '5.2.0 Alpha 1', + '>=' + ); + + $sql = "SELECT packageDir + FROM wcf" . $this->dbNo . "_package + WHERE package = ?"; + $statement = $this->database->prepareStatement($sql, 1); + $statement->execute(['com.woltlab.blog']); + $packageDir = $statement->fetchColumn(); + $blogFilePath = FileUtil::getRealPath($this->fileSystemPath . '/' . $packageDir); // get entry ids $entryIDs = []; @@ -2163,11 +2180,21 @@ final class WBB4xExporter extends AbstractExporter $conditionBuilder = new PreparedStatementConditionBuilder(); $conditionBuilder->add('entry.entryID IN (?)', [$entryIDs]); - $sql = "SELECT entry.*, language.languageCode + if ($sourceVersion52 && $destVersion52) { + $sql = "SELECT entry.*, language.languageCode, coverPhoto.fileExtension, coverPhoto.fileHash + FROM blog" . $this->dbNo . "_entry entry + LEFT JOIN wcf" . $this->dbNo . "_language language + ON language.languageID = entry.languageID + LEFT JOIN blog" . $this->dbNo . "_cover_photo coverPhoto + ON entry.coverPhotoID = entry.coverPhotoID + " . $conditionBuilder; + } else { + $sql = "SELECT entry.*, language.languageCode FROM blog" . $this->dbNo . "_entry entry LEFT JOIN wcf" . $this->dbNo . "_language language ON language.languageID = entry.languageID " . $conditionBuilder; + } $statement = $this->database->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); while ($row = $statement->fetchArray()) { @@ -2181,6 +2208,9 @@ final class WBB4xExporter extends AbstractExporter if (isset($categories[$row['entryID']])) { $additionalData['categories'] = $categories[$row['entryID']]; } + if ($sourceVersion52 && $destVersion52 && $row['coverPhotoID']) { + $additionalData['coverPhoto'] = $this->getCoverPhotoPath($blogFilePath, $row); + } $data = [ 'userID' => $row['userID'], @@ -2215,6 +2245,16 @@ final class WBB4xExporter extends AbstractExporter } } + private function getCoverPhotoPath(string $blogFilePath, array $row): string + { + $coverPhotoID = $row["coverPhotoID"]; + $fileHash = $row["fileHash"]; + $fileExtension = $row["fileExtension"]; + $directory = \substr($fileHash, 0, 2); + + return "{$blogFilePath}images/coverPhotos/$directory/$coverPhotoID-$fileHash.$fileExtension"; + } + /** * Counts blog attachments. */ -- 2.20.1