diff options
author | Andrew Dolgov <[email protected]> | 2021-02-27 21:56:45 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-02-27 21:56:45 +0300 |
commit | 4b90e6c0e152c2ee4ce3045ec13c29c9117470fc (patch) | |
tree | 76dedfccad3264bd0da862f483dcda38707b160a | |
parent | c4ee42e6edeedccd63208157c071d4a802842e25 (diff) |
transform ver.2 guid on import respecting target user ID
-rw-r--r-- | init.php | 25 |
1 files changed, 21 insertions, 4 deletions
@@ -26,7 +26,7 @@ class Data_Migration extends Plugin { // } - function data_import($args) { + function data_import(array $args) { $user = $args["data_user"]; $input_file = $args["data_import"]; @@ -94,7 +94,7 @@ class Data_Migration extends Plugin { } } - function data_export($args) { + function data_export(array $args) { $user = $args["data_user"]; $output_file = $args["data_export"]; $only_marked = isset($args["data_only_marked"]); @@ -167,7 +167,7 @@ class Data_Migration extends Plugin { } } - private function get_export_batch($owner_uid, $offset, $batch_size, $only_marked) { + private function get_export_batch(int $owner_uid, int $offset, int $batch_size, bool $only_marked) { $rv = []; Debug::log("processing articles, offset: $offset"); @@ -218,7 +218,22 @@ class Data_Migration extends Plugin { return $rv; } - private function import_article_batch($owner_uid, $articles) { + private function convert_guid(string $guid, int $owner_uid) { + if (strpos($guid, 'SHA1:') === 0) { + return $guid; // legacy format + } else { + $obj = json_decode($guid, true); + + if ($obj && $obj["ver"] == 2) { + $obj["uid"] = $owner_uid; + return json_encode($obj); + } else { + return $guid; + } + } + } + + private function import_article_batch(int $owner_uid, array $articles) { $total_imported = 0; $total_feeds_created = 0; @@ -226,6 +241,8 @@ class Data_Migration extends Plugin { $this->pdo->beginTransaction(); + $article["guid"] = $this->convert_guid($article["guid"], $owner_uid); + $sth = $this->pdo->prepare("SELECT id FROM ttrss_entries WHERE guid = ?"); $sth->execute([$article['guid']]); |