ZIP Exports: Changed the instance id mechanism
Some checks failed
analyse-php / build (push) Has been cancelled
lint-php / build (push) Has been cancelled
test-migrations / build (8.1) (push) Has been cancelled
test-migrations / build (8.2) (push) Has been cancelled
test-migrations / build (8.3) (push) Has been cancelled
test-php / build (8.1) (push) Has been cancelled
test-php / build (8.2) (push) Has been cancelled
test-php / build (8.3) (push) Has been cancelled

Adds an instance id via app settings.
This commit is contained in:
Dan Brown 2024-11-27 16:30:19 +00:00
parent edb684c72c
commit bdca9fc1ce
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
4 changed files with 38 additions and 8 deletions

View File

@ -69,8 +69,8 @@ class ZipExportBuilder
$this->data['exported_at'] = date(DATE_ATOM); $this->data['exported_at'] = date(DATE_ATOM);
$this->data['instance'] = [ $this->data['instance'] = [
'version' => trim(file_get_contents(base_path('version'))), 'id' => setting('instance-id', ''),
'id_ciphertext' => encrypt('bookstack'), 'version' => trim(file_get_contents(base_path('version'))),
]; ];
$zipFile = tempnam(sys_get_temp_dir(), 'bszip-'); $zipFile = tempnam(sys_get_temp_dir(), 'bszip-');

View File

@ -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();
}
};

View File

@ -93,12 +93,10 @@ The below details the objects & their properties used in Application Data.
#### Instance #### 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. - `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 #### Book

View File

@ -54,8 +54,10 @@ class ZipExportTest extends TestCase
$version = trim(file_get_contents(base_path('version'))); $version = trim(file_get_contents(base_path('version')));
$this->assertEquals($version, $zip->data['instance']['version']); $this->assertEquals($version, $zip->data['instance']['version']);
$instanceId = decrypt($zip->data['instance']['id_ciphertext']); $zipInstanceId = $zip->data['instance']['id'];
$this->assertEquals('bookstack', $instanceId); $instanceId = setting('instance-id');
$this->assertNotEmpty($instanceId);
$this->assertEquals($instanceId, $zipInstanceId);
} }
public function test_page_export() public function test_page_export()