Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 50 additions & 5 deletions files/lib/system/exporter/WBB4xExporter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,12 @@ public function countBlogs()
*/
public function exportBlogs($offset, $limit)
{
$sourceVersion52 = \version_compare(
$sourceVersion62 = \version_compare(
$this->getPackageVersion('com.woltlab.blog'),
'6.2.0 Alpha 1',
'>='
);
$sourceVersion52 = !$sourceVersion62 && \version_compare(
$this->getPackageVersion('com.woltlab.blog'),
'5.2.0 Alpha 1',
'>='
Expand All @@ -2069,6 +2074,7 @@ public function exportBlogs($offset, $limit)
$packageDir = $statement->fetchColumn();
$blogFilePath = FileUtil::getRealPath($this->fileSystemPath . '/' . $packageDir);

$coverPhotoFiles = [];
if ($sourceVersion52) {
$sql = "SELECT blog.*, language.languageCode, coverPhoto.fileExtension, coverPhoto.fileHash
FROM blog" . $this->dbNo . "_blog blog
Expand All @@ -2079,13 +2085,24 @@ public function exportBlogs($offset, $limit)
WHERE blog.blogID BETWEEN ? AND ?
ORDER BY blog.blogID";
} else {
if ($sourceVersion62) {
$sql = "SELECT coverPhotoFileID
FROM blog" . $this->dbNo . "_blog
WHERE blogID BETWEEN ? AND ?
ORDER BY blogID";
$statement = $this->database->prepareUnmanaged($sql);
$statement->execute([$offset + 1, $offset + $limit]);
$coverPhotoFiles = $this->getFileLocations($statement->fetchAll(\PDO::FETCH_COLUMN));
}

$sql = "SELECT blog.*, language.languageCode
FROM blog" . $this->dbNo . "_blog blog
LEFT JOIN wcf" . $this->dbNo . "_language language
ON language.languageID = blog.languageID
WHERE blog.blogID BETWEEN ? AND ?
ORDER BY blog.blogID";
}

$statement = $this->database->prepareUnmanaged($sql);
$statement->execute([$offset + 1, $offset + $limit]);
while ($row = $statement->fetchArray()) {
Expand All @@ -2102,7 +2119,14 @@ public function exportBlogs($offset, $limit)
if ($row['languageCode']) {
$additionalData['languageCode'] = $row['languageCode'];
}
if ($sourceVersion52 && $row['coverPhotoID']) {

if ($sourceVersion62) {
if (!empty($row['coverPhotoFileID']) && isset($coverPhotoFiles[$row['coverPhotoFileID']])) {
['location' => $location, 'filename' => $filename] = $coverPhotoFiles[$row['coverPhotoFileID']];
$additionalData['coverPhotoLocation'] = $location;
$additionalData['coverPhotoFilename'] = $filename;
}
} elseif ($sourceVersion52 && $row['coverPhotoID']) {
$additionalData['coverPhoto'] = $this->getCoverPhotoPath($blogFilePath, $row);
}

Expand Down Expand Up @@ -2166,7 +2190,12 @@ public function exportBlogEntries($offset, $limit)
'2.1.0 Alpha 1',
'>='
);
$sourceVersion52 = \version_compare(
$sourceVersion62 = \version_compare(
$this->getPackageVersion('com.woltlab.blog'),
'6.2.0 Alpha 1',
'>='
);
$sourceVersion52 = !$sourceVersion62 && \version_compare(
$this->getPackageVersion('com.woltlab.blog'),
'5.2.0 Alpha 1',
'>='
Expand Down Expand Up @@ -2220,6 +2249,7 @@ public function exportBlogEntries($offset, $limit)
$conditionBuilder = new PreparedStatementConditionBuilder();
$conditionBuilder->add('entry.entryID IN (?)', [$entryIDs]);

$coverPhotoFiles = [];
if ($sourceVersion52) {
$sql = "SELECT entry.*, language.languageCode, coverPhoto.fileExtension, coverPhoto.fileHash
FROM blog" . $this->dbNo . "_entry entry
Expand All @@ -2229,6 +2259,15 @@ public function exportBlogEntries($offset, $limit)
ON entry.coverPhotoID = entry.coverPhotoID
" . $conditionBuilder;
} else {
if ($sourceVersion62) {
$sql = "SELECT entry.coverPhotoFileID
FROM blog" . $this->dbNo . "_entry entry
" . $conditionBuilder;
$statement = $this->database->prepareUnmanaged($sql);
$statement->execute($conditionBuilder->getParameters());
$coverPhotoFiles = $this->getFileLocations($statement->fetchAll(\PDO::FETCH_COLUMN));
}

$sql = "SELECT entry.*, language.languageCode
FROM blog" . $this->dbNo . "_entry entry
LEFT JOIN wcf" . $this->dbNo . "_language language
Expand All @@ -2248,7 +2287,13 @@ public function exportBlogEntries($offset, $limit)
if (isset($categories[$row['entryID']])) {
$additionalData['categories'] = $categories[$row['entryID']];
}
if ($sourceVersion52 && $row['coverPhotoID']) {
if ($sourceVersion62) {
if (!empty($row['coverPhotoFileID']) && isset($coverPhotoFiles[$row['coverPhotoFileID']])) {
['location' => $location, 'filename' => $filename] = $coverPhotoFiles[$row['coverPhotoFileID']];
$additionalData['coverPhotoLocation'] = $location;
$additionalData['coverPhotoFilename'] = $filename;
}
} elseif ($sourceVersion52 && $row['coverPhotoID']) {
$additionalData['coverPhoto'] = $this->getCoverPhotoPath($blogFilePath, $row);
}

Expand Down Expand Up @@ -4674,7 +4719,7 @@ private function getFilebaseDir()
*
* @param int[] $fileIDs
*
* @return array{int, array{location: string, filename: string}}
* @return array<int, array{location: string, filename: string}>
*/
private function getFileLocations(array $fileIDs): array
{
Expand Down