From c6b27bcb227401ceb93ce2d69b77a2bbeccca18c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 20 Sep 2023 21:50:55 +0300 Subject: add option to ignore app/schema version differences --- init.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/init.php b/init.php index ec6b9c3..a6ab0d3 100644 --- a/init.php +++ b/init.php @@ -8,6 +8,7 @@ class Data_Migration extends Plugin { $host->add_command("data-only-marked", "only export starred (or archived) articles", $this, "", ""); $host->add_command("data-import", "import articles", $this, ":", "FILE.zip"); $host->add_command("data-export", "export articles", $this, ":", "FILE.zip"); + $host->add_command("data-ignore-version", "ignore version differences (use at your own risk!)", $this, "", ""); } function about() { @@ -34,6 +35,14 @@ class Data_Migration extends Plugin { // } + /** + * @param array $args + * @return void + */ + function data_ignore_version(array $args) : void { + // + } + /** * @param array $args * @return void @@ -42,6 +51,11 @@ class Data_Migration extends Plugin { function data_import(array $args) : void { $user = $args["data_user"]; $input_file = $args["data_import"]; + $ignore_version = isset($args["data_ignore_version"]); + + if ($ignore_version) { + Debug::log("warning: all version checks will be ignored when importing"); + } if (!$user) { Debug::log("error: please set username using --data_user"); @@ -78,8 +92,8 @@ class Data_Migration extends Plugin { $batch = json_decode($zip->getFromIndex($i), true); if ($batch) { - if ($batch["version"] == self::DATA_FORMAT_VERSION) { - if ($batch["schema-version"] == SCHEMA_VERSION) { + if ($batch["version"] == self::DATA_FORMAT_VERSION || $ignore_version) { + if ($batch["schema-version"] == Config::SCHEMA_VERSION || $ignore_version) { $total_processed += count($batch["articles"]); list ($batch_imported, $batch_feeds_created) = $this->import_article_batch($owner_uid, $batch["articles"]); @@ -89,7 +103,7 @@ class Data_Migration extends Plugin { } else { Debug::log("batch has incorrect schema format version (expected: " . - SCHEMA_VERSION . ", got: " . $batch["schema-version"]); + Config::SCHEMA_VERSION . ", got: " . $batch["schema-version"]); } } else { Debug::log("batch has incorrect data format version (expected: " . @@ -163,7 +177,7 @@ class Data_Migration extends Plugin { $batch = [ "version" => self::DATA_FORMAT_VERSION, - "schema-version" => SCHEMA_VERSION, + "schema-version" => Config::SCHEMA_VERSION, "articles" => $this->get_export_batch($owner_uid, $offset, $batch_size, $only_marked) ]; -- cgit v1.2.3