asdfsad
This commit is contained in:
@@ -3,6 +3,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Modules\MiningChecker\Api;
|
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\AnalyticsService;
|
||||||
use Modules\MiningChecker\Domain\FxService;
|
use Modules\MiningChecker\Domain\FxService;
|
||||||
use Modules\MiningChecker\Domain\OcrService;
|
use Modules\MiningChecker\Domain\OcrService;
|
||||||
@@ -40,6 +45,9 @@ final class Router
|
|||||||
private ?FxService $fx = null;
|
private ?FxService $fx = null;
|
||||||
private ?array $fxRatesSettingsCache = null;
|
private ?array $fxRatesSettingsCache = null;
|
||||||
private ?array $currencyCatalogCache = null;
|
private ?array $currencyCatalogCache = null;
|
||||||
|
private ?SharedFxRatesService $sharedFxRatesService = null;
|
||||||
|
private ?SharedFxRatesRepository $sharedFxRatesRepository = null;
|
||||||
|
private bool $sharedFxRatesResolved = false;
|
||||||
private DebugTrace $debug;
|
private DebugTrace $debug;
|
||||||
|
|
||||||
public function __construct(string $moduleBasePath)
|
public function __construct(string $moduleBasePath)
|
||||||
@@ -770,14 +778,12 @@ final class Router
|
|||||||
|
|
||||||
private function fxHistory(): array
|
private function fxHistory(): array
|
||||||
{
|
{
|
||||||
if (!modules()->isEnabled('fx-rates') || !modules()->hasFunction('fx-rates', 'recent_fetches')) {
|
$shared = $this->sharedFxRatesService();
|
||||||
|
if ($shared === null) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$fetches = module_fn('fx-rates', 'recent_fetches', 30);
|
$fetches = $shared->recentFetches(30);
|
||||||
if (!is_array($fetches)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$rows = [];
|
$rows = [];
|
||||||
foreach ($fetches as $fetch) {
|
foreach ($fetches as $fetch) {
|
||||||
@@ -810,7 +816,8 @@ final class Router
|
|||||||
|
|
||||||
private function migrateLegacyFxRates(string $projectKey): array
|
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);
|
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', [
|
$this->debug->add('legacy_fx_migrate.start', [
|
||||||
'project_key' => $projectKey,
|
'project_key' => $projectKey,
|
||||||
]);
|
]);
|
||||||
module_fn('fx-rates', 'ensure_schema');
|
|
||||||
$legacyRows = $this->repository()->listAllFxRates();
|
$legacyRows = $this->repository()->listAllFxRates();
|
||||||
$legacyFetches = $this->groupLegacyFxFetches($legacyRows);
|
$legacyFetches = $this->groupLegacyFxFetches($legacyRows);
|
||||||
$fxRepository = module_fn('fx-rates', 'repository');
|
|
||||||
$this->debug->add('legacy_fx_migrate.loaded', [
|
$this->debug->add('legacy_fx_migrate.loaded', [
|
||||||
'legacy_rows' => count($legacyRows),
|
'legacy_rows' => count($legacyRows),
|
||||||
'legacy_fetches' => count($legacyFetches),
|
'legacy_fetches' => count($legacyFetches),
|
||||||
@@ -2310,11 +2315,12 @@ final class Router
|
|||||||
return $this->fxRatesSettingsCache;
|
return $this->fxRatesSettingsCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!modules()->isEnabled('fx-rates') || !modules()->hasFunction('fx-rates', 'settings')) {
|
$settingsStore = $this->sharedFxRatesSettingsStore();
|
||||||
|
if ($settingsStore === null) {
|
||||||
return $this->fxRatesSettingsCache = [];
|
return $this->fxRatesSettingsCache = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$settings = module_fn('fx-rates', 'settings');
|
$settings = $settingsStore->load();
|
||||||
return $this->fxRatesSettingsCache = is_array($settings) ? $settings : [];
|
return $this->fxRatesSettingsCache = is_array($settings) ? $settings : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2412,17 +2418,88 @@ final class Router
|
|||||||
|
|
||||||
private function syncFxRatesPreferredCurrencies(array $preferredCurrencies): void
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
module_fn('fx-rates', 'save_runtime_settings', [
|
$settingsStore->save([
|
||||||
'preferred_currencies' => $preferredCurrencies,
|
'preferred_currencies' => $preferredCurrencies,
|
||||||
]);
|
]);
|
||||||
$this->fxRatesSettingsCache = null;
|
$this->fxRatesSettingsCache = null;
|
||||||
$this->currencyCatalogCache = 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
|
private function isCryptoCurrencyCode(string $code): bool
|
||||||
{
|
{
|
||||||
return in_array(strtoupper(trim($code)), [
|
return in_array(strtoupper(trim($code)), [
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Modules\MiningChecker\Domain;
|
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\Infrastructure\MiningRepository;
|
||||||
use Modules\MiningChecker\Support\DebugTrace;
|
use Modules\MiningChecker\Support\DebugTrace;
|
||||||
|
|
||||||
@@ -19,6 +24,8 @@ final class FxService
|
|||||||
private array $memoryCache = [];
|
private array $memoryCache = [];
|
||||||
private array $snapshotCache = [];
|
private array $snapshotCache = [];
|
||||||
private ?DebugTrace $debug;
|
private ?DebugTrace $debug;
|
||||||
|
private bool $sharedServiceResolved = false;
|
||||||
|
private ?object $sharedService = null;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
?MiningRepository $repository = null,
|
?MiningRepository $repository = null,
|
||||||
@@ -893,15 +900,38 @@ final class FxService
|
|||||||
|
|
||||||
private function sharedFxService(): ?object
|
private function sharedFxService(): ?object
|
||||||
{
|
{
|
||||||
if (!function_exists('modules') || !modules()->isEnabled('fx-rates') || !modules()->hasFunction('fx-rates', 'service')) {
|
if ($this->sharedServiceResolved) {
|
||||||
return null;
|
return $this->sharedService;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$service = module_fn('fx-rates', 'service');
|
$moduleBasePath = dirname(__DIR__, 2) . '/../fx-rates';
|
||||||
return is_object($service) ? $service : null;
|
$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) {
|
} catch (\Throwable) {
|
||||||
return null;
|
$this->sharedServiceResolved = true;
|
||||||
|
return $this->sharedService = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user