Files
firefly-iii/app/Support/System/GeneratesInstallationId.php

63 lines
1.8 KiB
PHP
Raw Normal View History

2020-06-06 06:57:44 +02:00
<?php
2020-06-30 19:05:35 +02:00
/**
* GeneratesInstallationId.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2020-06-06 06:57:44 +02:00
declare(strict_types=1);
namespace FireflyIII\Support\System;
use FireflyIII\Exceptions\FireflyException;
2020-06-06 06:57:44 +02:00
use Log;
use Ramsey\Uuid\Uuid;
/**
* Trait GeneratesInstallationId
*/
trait GeneratesInstallationId
{
/**
*
*/
protected function generateInstallationId(): void
{
try {
2021-05-24 08:50:17 +02:00
$config = app('fireflyconfig')->get('installation_id');
2021-03-21 09:15:40 +01:00
} catch (FireflyException $e) {
Log::info('Could not create or generate installation ID. Do not continue.');
2021-03-21 09:15:40 +01:00
return;
}
2020-06-18 18:14:10 +02:00
// delete if wrong UUID:
if (null !== $config && 'b2c27d92-be90-5c10-8589-005df5b314e6' === $config->data) {
$config = null;
}
2020-06-06 06:57:44 +02:00
if (null === $config) {
2020-06-18 18:14:10 +02:00
$uuid4 = Uuid::uuid4();
2021-03-21 09:15:40 +01:00
$uniqueId = (string)$uuid4;
2020-06-06 06:57:44 +02:00
Log::info(sprintf('Created Firefly III installation ID %s', $uniqueId));
app('fireflyconfig')->set('installation_id', $uniqueId);
}
}
}