Insert function to export filebase licenses
authorCyperghost <olaf_schmitz_1@t-online.de>
Tue, 2 Jan 2024 13:48:34 +0000 (14:48 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Tue, 2 Jan 2024 13:48:34 +0000 (14:48 +0100)
files/lib/system/exporter/WBB4xExporter.class.php

index 7a656b5b259409e36400d2f329458dbc08beb16b..ed5f571200845c0c195f68ab6c2713bf2637791a 100644 (file)
@@ -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.