vB 5: Add support for file system attachments
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 19 Nov 2021 13:25:08 +0000 (14:25 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 30 Jun 2022 14:38:34 +0000 (16:38 +0200)
files/lib/system/exporter/VB5xExporter.class.php

index 60f8709420721933c762211219663f4f20c27442..048f0f48fc38de1679d27ecc5d4a6e12d95b4272 100644 (file)
@@ -159,8 +159,13 @@ class VB5xExporter extends AbstractExporter
 
         if (\in_array('com.woltlab.wbb.attachment', $this->selectedData)) {
             if ($this->readOption('attachfile') != self::ATTACHFILE_DATABASE) {
-                // TODO: Not yet supported
-                return false;
+                $path = $this->readOption('attachpath');
+                if (!\str_starts_with($path, '/')) {
+                    $path = \realpath($this->fileSystemPath . $path);
+                }
+                if (!\is_dir($path)) {
+                    return false;
+                }
             }
         }
 
@@ -982,6 +987,22 @@ class VB5xExporter extends AbstractExporter
                         $file = FileUtil::getTemporaryFilename('attachment_');
                         \file_put_contents($file, $row['filedata']);
                         break;
+                    case self::ATTACHFILE_FILESYSTEM:
+                        $file = $this->readOption('attachpath');
+                        if (!StringUtil::startsWith($file, '/')) {
+                            $file = \realpath($this->fileSystemPath . $file);
+                        }
+                        $file = FileUtil::addTrailingSlash($file);
+                        $file .= $row['userid'] . '/' . $row['filedataid'] . '.attach';
+                        break;
+                    case self::ATTACHFILE_FILESYSTEM_SUBFOLDER:
+                        $file = $this->readOption('attachpath');
+                        if (!StringUtil::startsWith($file, '/')) {
+                            $file = \realpath($this->fileSystemPath . $file);
+                        }
+                        $file = FileUtil::addTrailingSlash($file);
+                        $file .= \implode('/', \str_split($row['userid'])) . '/' . $row['filedataid'] . '.attach';
+                        break;
                 }
 
                 // unable to read file -> abort