summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2023-09-20 21:50:55 +0300
committerAndrew Dolgov <[email protected]>2023-09-20 21:50:55 +0300
commitc6b27bcb227401ceb93ce2d69b77a2bbeccca18c (patch)
treedf13a1d2feb9db9475a92bdebbecc582980c06cd
parentfc8d2f723dbf18ceff67e140fad2c69c7f9c3899 (diff)
add option to ignore app/schema version differences
-rw-r--r--init.php22
1 files 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<string> $args
+ * @return void
+ */
+ function data_ignore_version(array $args) : void {
+ //
+ }
+
/**
* @param array<string> $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)
];