Fix various sonatype issues.

This commit is contained in:
James Cole
2022-03-30 06:54:59 +02:00
parent 65764199fe
commit 8f98be32f9
16 changed files with 123 additions and 91 deletions

View File

@@ -39,6 +39,7 @@ use FireflyIII\Services\Internal\Destroy\CurrencyDestroyService;
use FireflyIII\Services\Internal\Update\CurrencyUpdateService;
use FireflyIII\User;
use Illuminate\Support\Collection;
use JsonException;
use Log;
/**
@@ -200,6 +201,25 @@ class CurrencyRepository implements CurrencyRepositoryInterface
$currency->save();
}
/**
* @inheritDoc
*/
public function ensureMinimalEnabledCurrencies(): void
{
// if no currencies are enabled, enable the first one in the DB (usually the EUR)
if (0 === $this->get()->count()) {
/** @var TransactionCurrency $first */
$first = $this->getAll()->first();
if (null === $first) {
throw new FireflyException('No currencies found. You broke Firefly III');
}
Log::channel('audit')->info(sprintf('Auto-enabled currency %s.', $first->code));
$this->enable($first);
app('preferences')->set('currencyPreference', $first->code);
app('preferences')->mark();
}
}
/**
* Find by currency code, return NULL if unfound.
* Used in Import Currency!
@@ -274,7 +294,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
*
* @return TransactionCurrency
* @throws FireflyException
* @throws \JsonException
* @throws JsonException
*/
public function findCurrency(?int $currencyId, ?string $currencyCode): TransactionCurrency
{

View File

@@ -35,7 +35,6 @@ use Illuminate\Support\Collection;
*/
interface CurrencyRepositoryInterface
{
/**
* @param TransactionCurrency $currency
*
@@ -80,6 +79,11 @@ interface CurrencyRepositoryInterface
*/
public function enable(TransactionCurrency $currency): void;
/**
* @return void
*/
public function ensureMinimalEnabledCurrencies(): void;
/**
* Find by ID, return NULL if not found.
*