]> BookStack Code Mirror - bookstack/commitdiff
ZIP Exports: Changed the instance id mechanism 5260/head
authorDan Brown <redacted>
Wed, 27 Nov 2024 16:30:19 +0000 (16:30 +0000)
committerDan Brown <redacted>
Wed, 27 Nov 2024 16:30:19 +0000 (16:30 +0000)
Adds an instance id via app settings.

app/Exports/ZipExports/ZipExportBuilder.php
database/migrations/2024_11_27_171039_add_instance_id_setting.php [new file with mode: 0644]
dev/docs/portable-zip-file-format.md
tests/Exports/ZipExportTest.php

index 42fb03541c014a3c5a38ea18aaf05d3b63fddc6b..4c5c638f59193da085734b1294f67acf20228c7d 100644 (file)
@@ -69,8 +69,8 @@ class ZipExportBuilder
 
         $this->data['exported_at'] = date(DATE_ATOM);
         $this->data['instance'] = [
-            'version'       => trim(file_get_contents(base_path('version'))),
-            'id_ciphertext' => encrypt('bookstack'),
+            'id'      => setting('instance-id', ''),
+            'version' => trim(file_get_contents(base_path('version'))),
         ];
 
         $zipFile = tempnam(sys_get_temp_dir(), 'bszip-');
diff --git a/database/migrations/2024_11_27_171039_add_instance_id_setting.php b/database/migrations/2024_11_27_171039_add_instance_id_setting.php
new file mode 100644 (file)
index 0000000..ee1e90d
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\DB;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        DB::table('settings')->insert([
+            'setting_key' => 'instance-id',
+            'value' => Str::uuid(),
+            'created_at' => Carbon::now(),
+            'updated_at' => Carbon::now(),
+            'type' => 'string',
+        ]);
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        DB::table('settings')->where('setting_key', '=', 'instance-id')->delete();
+    }
+};
index fbb3178582415fc88bb46ec6bf07fa6e1b5f2f32..754cb4d3e9414070b5f67d3f8ca45a823481b49e 100644 (file)
@@ -93,12 +93,10 @@ The below details the objects & their properties used in Application Data.
 
 #### Instance
 
-These details are mainly informational regarding the exporting BookStack instance from where an export was created from.
+These details are informational regarding the exporting BookStack instance from where an export was created from.
 
+- `id` - String, required, unique identifier for the BookStack instance.
 - `version` - String, required, BookStack version of the export source instance.
-- `id_ciphertext` - String, required, identifier for the BookStack instance.
-
-The `id_ciphertext` is the ciphertext of encrypting the text `bookstack`. This is used as a simple & rough way for a BookStack instance to be able to identify if they were the source (by attempting to decrypt the ciphertext).
 
 #### Book
 
index 17891c73d73f171318b3712bb36730e5bbdeae52..ebe07d052bcd94a619ee68f9d0ea0878efc97785 100644 (file)
@@ -54,8 +54,10 @@ class ZipExportTest extends TestCase
         $version = trim(file_get_contents(base_path('version')));
         $this->assertEquals($version, $zip->data['instance']['version']);
 
-        $instanceId = decrypt($zip->data['instance']['id_ciphertext']);
-        $this->assertEquals('bookstack', $instanceId);
+        $zipInstanceId = $zip->data['instance']['id'];
+        $instanceId = setting('instance-id');
+        $this->assertNotEmpty($instanceId);
+        $this->assertEquals($instanceId, $zipInstanceId);
     }
 
     public function test_page_export()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.