Skip to content

Firefly III: a personal finances manager

Better generation of installation ID.

James Colef5c075936fb1
diff --git a/app/Console/Commands/UpgradeFireflyInstructions.php b/app/Console/Commands/UpgradeFireflyInstructions.php
index 35d042a5dc..5a70f5936d 100644
--- a/app/Console/Commands/UpgradeFireflyInstructions.php
+++ b/app/Console/Commands/UpgradeFireflyInstructions.php
@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands;
+use FireflyIII\Support\System\GeneratesInstallationId;
use Illuminate\Console\Command;
/**
@@ -32,6 +33,8 @@ use Illuminate\Console\Command;
*/
class UpgradeFireflyInstructions extends Command
{
+ use GeneratesInstallationId;
+
/**
* The console command description.
*
@@ -50,6 +53,7 @@ class UpgradeFireflyInstructions extends Command
*/
public function handle(): int
{
+ $this->generateInstallationId();
if ('update' === (string) $this->argument('task')) {
$this->updateInstructions();
}
@@ -64,6 +68,7 @@ class UpgradeFireflyInstructions extends Command
app('telemetry')->feature('system.database.driver', env('DB_CONNECTION', '(unknown)'));
app('telemetry')->feature('system.os.is_docker', $isDocker);
app('telemetry')->feature('system.command.executed', $this->signature);
+
return 0;
}
diff --git a/app/Http/Middleware/InstallationId.php b/app/Http/Middleware/InstallationId.php
index 8e326da273..f8c7de54c3 100644
--- a/app/Http/Middleware/InstallationId.php
+++ b/app/Http/Middleware/InstallationId.php
@@ -26,8 +26,7 @@ namespace FireflyIII\Http\Middleware;
use Closure;
use FireflyIII\Exceptions\FireflyException;
-use Log;
-use Ramsey\Uuid\Uuid;
+use FireflyIII\Support\System\GeneratesInstallationId;
/**
*
@@ -35,6 +34,7 @@ use Ramsey\Uuid\Uuid;
*/
class InstallationId
{
+ use GeneratesInstallationId;
/**
* Handle an incoming request.
*
@@ -48,13 +48,7 @@ class InstallationId
*/
public function handle($request, Closure $next)
{
- $config = app('fireflyconfig')->get('installation_id', null);
- if (null === $config) {
- $uuid5 = Uuid::uuid5(Uuid::NAMESPACE_URL, 'firefly-iii.org');
- $uniqueId = (string) $uuid5;
- Log::info(sprintf('Created Firefly III installation ID %s', $uniqueId));
- app('fireflyconfig')->set('installation_id', $uniqueId);
- }
+ $this->generateInstallationId();
return $next($request);
}
diff --git a/app/Support/System/GeneratesInstallationId.php b/app/Support/System/GeneratesInstallationId.php
new file mode 100644
index 0000000000..9dac7661eb
--- /dev/null
+++ b/app/Support/System/GeneratesInstallationId.php
@@ -0,0 +1,28 @@
+<?php
+declare(strict_types=1);
+
+namespace FireflyIII\Support\System;
+
+use Log;
+use Ramsey\Uuid\Uuid;
+
+/**
+ * Trait GeneratesInstallationId
+ */
+trait GeneratesInstallationId
+{
+ /**
+ *
+ */
+ protected function generateInstallationId(): void
+ {
+ $config = app('fireflyconfig')->get('installation_id', null);
+ if (null === $config) {
+ $uuid5 = Uuid::uuid5(Uuid::NAMESPACE_URL, 'firefly-iii.org');
+ $uniqueId = (string) $uuid5;
+ Log::info(sprintf('Created Firefly III installation ID %s', $uniqueId));
+ app('fireflyconfig')->set('installation_id', $uniqueId);
+ }
+ }
+
+}
diff --git a/app/Support/Telemetry.php b/app/Support/Telemetry.php
index cc9c3aacb6..7b8a5cba76 100644
--- a/app/Support/Telemetry.php
+++ b/app/Support/Telemetry.php
@@ -24,6 +24,7 @@ namespace FireflyIII\Support;
use Carbon\Carbon;
use FireflyIII\Models\Telemetry as TelemetryModel;
+use FireflyIII\Support\System\GeneratesInstallationId;
use JsonException;
use Log;
@@ -32,6 +33,7 @@ use Log;
*/
class Telemetry
{
+ use GeneratesInstallationId;
/**
* Feature telemetry stores a $value for the given $feature.
* Will only store the given $feature / $value combination once.
@@ -166,9 +168,12 @@ class Telemetry
*/
private function storeEntry(string $type, string $name, string $value): void
{
+ $this->generateInstallationId();
+ $config = app('fireflyconfig')->get('installation_id', null);
+ $installationId = null !== $config ? $config->data : 'empty';
TelemetryModel::create(
[
- 'installation_id' => \FireflyConfig::get('installation_id', '')->data,
+ 'installation_id' => $installationId,
'key' => $name,
'type' => $type,
'value' => $value,