From 03fa4fc127c410f0118155cfce19d6143cc847d4 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Tue, 2 Jan 2024 14:48:34 +0100 Subject: [PATCH] Insert function to export filebase licenses --- .../system/exporter/WBB4xExporter.class.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/files/lib/system/exporter/WBB4xExporter.class.php b/files/lib/system/exporter/WBB4xExporter.class.php index 7a656b5..ed5f571 100644 --- a/files/lib/system/exporter/WBB4xExporter.class.php +++ b/files/lib/system/exporter/WBB4xExporter.class.php @@ -3,6 +3,7 @@ namespace wcf\system\exporter; use blog\system\BLOGCore; +use filebase\data\license\License; use gallery\system\GALLERYCore; use wcf\data\object\type\ObjectTypeCache; use wcf\data\package\Package; @@ -101,6 +102,7 @@ final class WBB4xExporter extends AbstractExporter 'com.woltlab.filebase.category' => 'FilebaseCategories', 'com.woltlab.filebase.file' => 'FilebaseFiles', + 'com.woltlab.filebase.license' => 'FilebaseLicenses', 'com.woltlab.filebase.file.version' => 'FilebaseFileVersions', 'com.woltlab.filebase.file.comment' => 'FilebaseFileComments', 'com.woltlab.filebase.file.comment.response' => 'FilebaseFileCommentResponses', @@ -206,6 +208,7 @@ final class WBB4xExporter extends AbstractExporter ], 'com.woltlab.filebase.file' => [ 'com.woltlab.filebase.category', + 'com.woltlab.filebase.license', 'com.woltlab.filebase.file.attachment', 'com.woltlab.filebase.file.comment', 'com.woltlab.filebase.file.like', @@ -433,6 +436,9 @@ final class WBB4xExporter extends AbstractExporter if (\in_array('com.woltlab.filebase.category', $this->selectedData)) { $queue[] = 'com.woltlab.filebase.category'; } + if (\in_array('com.woltlab.filebase.license', $this->selectedData)) { + $queue[] = 'com.woltlab.filebase.license'; + } $queue[] = 'com.woltlab.filebase.file'; $queue[] = 'com.woltlab.filebase.file.version'; @@ -3036,6 +3042,67 @@ final class WBB4xExporter extends AbstractExporter $limit ); } + /** + * Counts filebase licenses. + */ + public function countFilebaseLicenses() + { + return $this->__getMaxID("filebase" . $this->dbNo . "_license", 'licenseID'); + } + + /** + * Exports filebase licenses. + * + * @param int $offset + * @param int $limit + */ + public function exportFilebaseLicenses($offset, $limit) + { + $sql = "SELECT * + FROM filebase" . $this->dbNo . "_license + WHERE licenseID BETWEEN ? AND ? + ORDER BY licenseID"; + $statement = $this->database->prepareStatement($sql); + $statement->execute([$offset + 1, $offset + $limit]); + + $sql = "SELECT language_item.languageItemValue, language.languageCode + FROM wcf1_language_item language_item + LEFT JOIN wcf1_language language ON (language.languageID = language_item.languageID) + WHERE language_item.languageItem = ?"; + $languageStatement = $this->database->prepareStatement($sql); + + while ($row = $statement->fetchArray()) { + $additionalData = []; + $data = [ + 'licenseName' => $row['licenseName'], + 'licenseURL' => $row['licenseURL'], + 'licenseType' => License::LICENSE_TYPE_URL, + ]; + if (\version_compare($this->getPackageVersion('com.woltlab.filebase'), '5.2.0 Alpha 1', '>=')) { + // support licenseType `text` + if ($row['licenseType'] === License::LICENSE_TYPE_TEXT) { + $data['licenseType'] = License::LICENSE_TYPE_TEXT; + $data['licenseText'] = $row['licenseText']; + + // load multi-language license text + if (\preg_match('~^filebase\.file\.license\d+\.licenseText$~', $data['licenseText'])) { + $languageStatement->execute([$data['licenseText']]); + while ($languageRow = $languageStatement->fetchArray()) { + $additionalData['licenseText'][$languageRow['languageCode']] = $languageRow['languageItemValue']; + } + } + } + } + + ImportHandler::getInstance() + ->getImporter('com.woltlab.filebase.license') + ->import( + $row['licenseID'], + $data, + $additionalData + ); + } + } /** * Counts filebase files. -- 2.20.1