Page MenuHomePhorge

D5823.1774825438.diff
No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None

D5823.1774825438.diff

diff --git a/src/app/DataMigrator/Driver/DAV.php b/src/app/DataMigrator/Driver/DAV.php
--- a/src/app/DataMigrator/Driver/DAV.php
+++ b/src/app/DataMigrator/Driver/DAV.php
@@ -14,11 +14,12 @@
use App\DataMigrator\Interface\ImporterInterface;
use App\DataMigrator\Interface\Item;
use App\DataMigrator\Interface\ItemSet;
+use App\DataMigrator\Interface\FetchItemSetInterface;
use App\User;
use App\Utils;
use Illuminate\Http\Client\RequestException;
-class DAV implements ExporterInterface, ImporterInterface
+class DAV implements ExporterInterface, ImporterInterface, FetchItemSetInterface
{
/** @var int Max number of items to migrate in one go */
protected const CHUNK_SIZE = 25;
@@ -208,21 +209,15 @@
}
/**
- * Fetching an item
+ * Set the item content from the fetch result
*/
- public function fetchItem(Item $item): void
+ private function setItemContentFromResult(Item $item, $result): void
{
- $result = $this->client->getObjects(dirname($item->id), $this->type2DAV($item->folder->type), [$item->id]);
-
- if ($result === false) {
- throw new \Exception("Failed to fetch DAV item for {$item->id}");
- }
-
// Make the item compatible with standards (and Cyrus DAV) if possible
// We try to prevent the event to be not accepted by the DAV server as much as we can.
- $result[0]->repair();
+ $result->repair();
- $content = (string) $result[0];
+ $content = (string) $result;
if (strlen($content) > Engine::MAX_ITEM_SIZE) {
// Save the item content to a file
@@ -239,6 +234,52 @@
}
}
+ /**
+ * Fetching an item
+ */
+ public function fetchItem(Item $item): void
+ {
+ \Log::info("fetchItem: " . $item->id);
+ $result = $this->client->getObjects(dirname($item->id), $this->type2DAV($item->folder->type), [$item->id]);
+
+ if ($result === false) {
+ throw new \Exception("Failed to fetch DAV item for {$item->id}");
+ }
+
+ $this->setItemContentFromResult($item, $result[0]);
+
+ }
+
+ /**
+ * Fetching an item set
+ */
+ public function fetchItemSet(ItemSet $set, $callback): void
+ {
+ if (empty($set->items)) {
+ \Log::info("Empty set");
+ return;
+ }
+
+ $folder = dirname($set->items[0]->id);
+ $type = $this->type2DAV($set->items[0]->folder->type);
+ $ids = [];
+ foreach ($set->items as $item) {
+ $ids[] = $item->id;
+ }
+
+ $result = $this->client->getObjects($folder, $type, $ids);
+
+ if ($result === false) {
+ throw new \Exception("Failed to fetch DAV items for {$folder}");
+ }
+
+ for ($i = 0; $i < count($result); $i++) {
+ $item = $set->items[$i];
+ $this->setItemContentFromResult($item, $result[$i]);
+ $callback($item);
+ }
+ }
+
/**
* Fetch a list of folder items
*/
diff --git a/src/app/DataMigrator/Driver/Kolab.php b/src/app/DataMigrator/Driver/Kolab.php
--- a/src/app/DataMigrator/Driver/Kolab.php
+++ b/src/app/DataMigrator/Driver/Kolab.php
@@ -7,13 +7,15 @@
use App\DataMigrator\Engine;
use App\DataMigrator\Interface\Folder;
use App\DataMigrator\Interface\ImporterInterface;
+use App\DataMigrator\Interface\FetchItemSetInterface;
use App\DataMigrator\Interface\Item;
+use App\DataMigrator\Interface\ItemSet;
use App\User;
/**
* Data migration from/to a Kolab server
*/
-class Kolab extends IMAP
+class Kolab extends IMAP implements FetchItemSetInterface
{
protected const CTYPE_KEY = '/shared/vendor/kolab/folder-type';
protected const CTYPE_KEY_PRIVATE = '/private/vendor/kolab/folder-type';
@@ -178,6 +180,21 @@
}
}
+ /**
+ * Fetching an item set
+ */
+ public function fetchItemSet(ItemSet $set, $callback): void
+ {
+ if (in_array($set->items[0]->folder->type, self::DAV_TYPES)) {
+ $this->davDriver->fetchItemSet($set, $callback);
+ } else {
+ foreach ($set->items as $item) {
+ $this->fetchItem($item);
+ $callback($item);
+ }
+ }
+ }
+
/**
* Fetching an item
*/

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 29, 11:03 PM (3 d, 21 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18778614
Default Alt Text
D5823.1774825438.diff (4 KB)

Event Timeline