asdfsad
All checks were successful
Deploy / deploy-staging (push) Successful in 24s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-06-22 01:47:21 +02:00
parent f9e41380b5
commit cfcb37ca7e
2 changed files with 124 additions and 17 deletions

View File

@@ -3,6 +3,11 @@ declare(strict_types=1);
namespace Modules\MiningChecker\Api;
use Modules\FxRates\Domain\FxRatesService as SharedFxRatesService;
use Modules\FxRates\Infrastructure\ConnectionFactory as SharedFxConnectionFactory;
use Modules\FxRates\Infrastructure\FxRatesRepository as SharedFxRatesRepository;
use Modules\FxRates\Infrastructure\ModuleConfig as SharedFxModuleConfig;
use Modules\FxRates\Infrastructure\SettingsStore as SharedFxSettingsStore;
use Modules\MiningChecker\Domain\AnalyticsService;
use Modules\MiningChecker\Domain\FxService;
use Modules\MiningChecker\Domain\OcrService;
@@ -40,6 +45,9 @@ final class Router
private ?FxService $fx = null;
private ?array $fxRatesSettingsCache = null;
private ?array $currencyCatalogCache = null;
private ?SharedFxRatesService $sharedFxRatesService = null;
private ?SharedFxRatesRepository $sharedFxRatesRepository = null;
private bool $sharedFxRatesResolved = false;
private DebugTrace $debug;
public function __construct(string $moduleBasePath)
@@ -770,14 +778,12 @@ final class Router
private function fxHistory(): array
{
if (!modules()->isEnabled('fx-rates') || !modules()->hasFunction('fx-rates', 'recent_fetches')) {
$shared = $this->sharedFxRatesService();
if ($shared === null) {
return [];
}
$fetches = module_fn('fx-rates', 'recent_fetches', 30);
if (!is_array($fetches)) {
return [];
}
$fetches = $shared->recentFetches(30);
$rows = [];
foreach ($fetches as $fetch) {
@@ -810,7 +816,8 @@ final class Router
private function migrateLegacyFxRates(string $projectKey): array
{
if (!modules()->isEnabled('fx-rates') || !modules()->hasFunction('fx-rates', 'repository')) {
$fxRepository = $this->sharedFxRatesRepository();
if ($fxRepository === null) {
throw new ApiException('Das Modul fx-rates ist nicht verfuegbar.', 422);
}
@@ -818,10 +825,8 @@ final class Router
$this->debug->add('legacy_fx_migrate.start', [
'project_key' => $projectKey,
]);
module_fn('fx-rates', 'ensure_schema');
$legacyRows = $this->repository()->listAllFxRates();
$legacyFetches = $this->groupLegacyFxFetches($legacyRows);
$fxRepository = module_fn('fx-rates', 'repository');
$this->debug->add('legacy_fx_migrate.loaded', [
'legacy_rows' => count($legacyRows),
'legacy_fetches' => count($legacyFetches),
@@ -2310,11 +2315,12 @@ final class Router
return $this->fxRatesSettingsCache;
}
if (!modules()->isEnabled('fx-rates') || !modules()->hasFunction('fx-rates', 'settings')) {
$settingsStore = $this->sharedFxRatesSettingsStore();
if ($settingsStore === null) {
return $this->fxRatesSettingsCache = [];
}
$settings = module_fn('fx-rates', 'settings');
$settings = $settingsStore->load();
return $this->fxRatesSettingsCache = is_array($settings) ? $settings : [];
}
@@ -2412,17 +2418,88 @@ final class Router
private function syncFxRatesPreferredCurrencies(array $preferredCurrencies): void
{
if (!modules()->isEnabled('fx-rates') || !modules()->hasFunction('fx-rates', 'save_runtime_settings')) {
$settingsStore = $this->sharedFxRatesSettingsStore();
if ($settingsStore === null) {
return;
}
module_fn('fx-rates', 'save_runtime_settings', [
$settingsStore->save([
'preferred_currencies' => $preferredCurrencies,
]);
$this->fxRatesSettingsCache = null;
$this->currencyCatalogCache = null;
}
private function sharedFxRatesService(): ?SharedFxRatesService
{
$this->resolveSharedFxRates();
return $this->sharedFxRatesService;
}
private function sharedFxRatesRepository(): ?SharedFxRatesRepository
{
$this->resolveSharedFxRates();
return $this->sharedFxRatesRepository;
}
private function sharedFxRatesSettingsStore(): ?SharedFxSettingsStore
{
$this->resolveSharedFxRates();
if ($this->sharedFxRatesRepository === null) {
return null;
}
$moduleBasePath = $this->sharedFxRatesModulePath();
if ($moduleBasePath === null) {
return null;
}
return new SharedFxSettingsStore(SharedFxModuleConfig::load($moduleBasePath));
}
private function resolveSharedFxRates(): void
{
if ($this->sharedFxRatesResolved) {
return;
}
$this->sharedFxRatesResolved = true;
$moduleBasePath = $this->sharedFxRatesModulePath();
if ($moduleBasePath === null) {
return;
}
try {
$bootstrap = $moduleBasePath . '/bootstrap.php';
require_once $bootstrap;
$config = SharedFxModuleConfig::load($moduleBasePath);
$settingsStore = new SharedFxSettingsStore($config);
$repository = new SharedFxRatesRepository(
SharedFxConnectionFactory::make($settingsStore),
$config->tablePrefix()
);
$repository->ensureSchema();
$this->sharedFxRatesRepository = $repository;
$this->sharedFxRatesService = new SharedFxRatesService($repository, $settingsStore->load());
} catch (\Throwable $exception) {
$this->debug->add('fx_rates.shared_unavailable', [
'message' => $exception->getMessage(),
]);
$this->sharedFxRatesRepository = null;
$this->sharedFxRatesService = null;
}
}
private function sharedFxRatesModulePath(): ?string
{
$moduleBasePath = dirname($this->moduleBasePath) . '/fx-rates';
return is_dir($moduleBasePath) && is_file($moduleBasePath . '/bootstrap.php')
? $moduleBasePath
: null;
}
private function isCryptoCurrencyCode(string $code): bool
{
return in_array(strtoupper(trim($code)), [

View File

@@ -3,6 +3,11 @@ declare(strict_types=1);
namespace Modules\MiningChecker\Domain;
use Modules\FxRates\Domain\FxRatesService as SharedFxRatesService;
use Modules\FxRates\Infrastructure\ConnectionFactory as SharedFxConnectionFactory;
use Modules\FxRates\Infrastructure\FxRatesRepository as SharedFxRatesRepository;
use Modules\FxRates\Infrastructure\ModuleConfig as SharedFxModuleConfig;
use Modules\FxRates\Infrastructure\SettingsStore as SharedFxSettingsStore;
use Modules\MiningChecker\Infrastructure\MiningRepository;
use Modules\MiningChecker\Support\DebugTrace;
@@ -19,6 +24,8 @@ final class FxService
private array $memoryCache = [];
private array $snapshotCache = [];
private ?DebugTrace $debug;
private bool $sharedServiceResolved = false;
private ?object $sharedService = null;
public function __construct(
?MiningRepository $repository = null,
@@ -893,15 +900,38 @@ final class FxService
private function sharedFxService(): ?object
{
if (!function_exists('modules') || !modules()->isEnabled('fx-rates') || !modules()->hasFunction('fx-rates', 'service')) {
return null;
if ($this->sharedServiceResolved) {
return $this->sharedService;
}
try {
$service = module_fn('fx-rates', 'service');
return is_object($service) ? $service : null;
$moduleBasePath = dirname(__DIR__, 2) . '/../fx-rates';
$bootstrap = $moduleBasePath . '/bootstrap.php';
if (!is_file($bootstrap)) {
$this->sharedServiceResolved = true;
return $this->sharedService = null;
}
require_once $bootstrap;
if (!class_exists(SharedFxModuleConfig::class) || !class_exists(SharedFxRatesService::class)) {
$this->sharedServiceResolved = true;
return $this->sharedService = null;
}
$config = SharedFxModuleConfig::load($moduleBasePath);
$settingsStore = new SharedFxSettingsStore($config);
$repository = new SharedFxRatesRepository(
SharedFxConnectionFactory::make($settingsStore),
$config->tablePrefix()
);
$repository->ensureSchema();
$this->sharedServiceResolved = true;
return $this->sharedService = new SharedFxRatesService($repository, $settingsStore->load());
} catch (\Throwable) {
return null;
$this->sharedServiceResolved = true;
return $this->sharedService = null;
}
}