Skip to content

Commit bdca9fc

Browse files
committed
ZIP Exports: Changed the instance id mechanism
Adds an instance id via app settings.
1 parent edb684c commit bdca9fc

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

app/Exports/ZipExports/ZipExportBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ protected function build(): string
6969

7070
$this->data['exported_at'] = date(DATE_ATOM);
7171
$this->data['instance'] = [
72-
'version' => trim(file_get_contents(base_path('version'))),
73-
'id_ciphertext' => encrypt('bookstack'),
72+
'id' => setting('instance-id', ''),
73+
'version' => trim(file_get_contents(base_path('version'))),
7474
];
7575

7676
$zipFile = tempnam(sys_get_temp_dir(), 'bszip-');
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Support\Carbon;
5+
use Illuminate\Support\Facades\DB;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
DB::table('settings')->insert([
15+
'setting_key' => 'instance-id',
16+
'value' => Str::uuid(),
17+
'created_at' => Carbon::now(),
18+
'updated_at' => Carbon::now(),
19+
'type' => 'string',
20+
]);
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*/
26+
public function down(): void
27+
{
28+
DB::table('settings')->where('setting_key', '=', 'instance-id')->delete();
29+
}
30+
};

dev/docs/portable-zip-file-format.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,10 @@ The below details the objects & their properties used in Application Data.
9393

9494
#### Instance
9595

96-
These details are mainly informational regarding the exporting BookStack instance from where an export was created from.
96+
These details are informational regarding the exporting BookStack instance from where an export was created from.
9797

98+
- `id` - String, required, unique identifier for the BookStack instance.
9899
- `version` - String, required, BookStack version of the export source instance.
99-
- `id_ciphertext` - String, required, identifier for the BookStack instance.
100-
101-
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).
102100

103101
#### Book
104102

tests/Exports/ZipExportTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ public function test_export_metadata()
5454
$version = trim(file_get_contents(base_path('version')));
5555
$this->assertEquals($version, $zip->data['instance']['version']);
5656

57-
$instanceId = decrypt($zip->data['instance']['id_ciphertext']);
58-
$this->assertEquals('bookstack', $instanceId);
57+
$zipInstanceId = $zip->data['instance']['id'];
58+
$instanceId = setting('instance-id');
59+
$this->assertNotEmpty($instanceId);
60+
$this->assertEquals($instanceId, $zipInstanceId);
5961
}
6062

6163
public function test_page_export()

0 commit comments

Comments
 (0)