asdasd
This commit is contained in:
@@ -430,6 +430,7 @@ final class MiningRepository
|
||||
'project_key' => $projectKey,
|
||||
'measured_at' => $payload['measured_at'] ?? null,
|
||||
'price_currency' => $payload['price_currency'] ?? null,
|
||||
'fx_fetch_id' => $payload['fx_fetch_id'] ?? null,
|
||||
]);
|
||||
$params = [
|
||||
'project_key' => $projectKey,
|
||||
@@ -438,6 +439,7 @@ final class MiningRepository
|
||||
'coins_total' => $payload['coins_total'],
|
||||
'price_per_coin' => $payload['price_per_coin'],
|
||||
'price_currency' => $payload['price_currency'],
|
||||
'fx_fetch_id' => $payload['fx_fetch_id'] ?? null,
|
||||
'note' => $payload['note'],
|
||||
'source' => $payload['source'],
|
||||
'image_path' => $payload['image_path'],
|
||||
@@ -449,10 +451,10 @@ final class MiningRepository
|
||||
if ($this->driver === 'pgsql') {
|
||||
$stmt = $this->pdo->prepare(
|
||||
'INSERT INTO ' . $this->table('measurements') . ' (
|
||||
project_key, owner_sub, measured_at, coins_total, price_per_coin, price_currency, note,
|
||||
project_key, owner_sub, measured_at, coins_total, price_per_coin, price_currency, fx_fetch_id, note,
|
||||
source, image_path, ocr_raw_text, ocr_confidence, ocr_flags
|
||||
) VALUES (
|
||||
:project_key, :owner_sub, :measured_at, :coins_total, :price_per_coin, :price_currency, :note,
|
||||
:project_key, :owner_sub, :measured_at, :coins_total, :price_per_coin, :price_currency, :fx_fetch_id, :note,
|
||||
:source, :image_path, :ocr_raw_text, :ocr_confidence, CAST(:ocr_flags AS jsonb)
|
||||
)
|
||||
RETURNING *'
|
||||
@@ -465,10 +467,10 @@ final class MiningRepository
|
||||
|
||||
$stmt = $this->pdo->prepare(
|
||||
'INSERT INTO ' . $this->table('measurements') . ' (
|
||||
project_key, owner_sub, measured_at, coins_total, price_per_coin, price_currency, note,
|
||||
project_key, owner_sub, measured_at, coins_total, price_per_coin, price_currency, fx_fetch_id, note,
|
||||
source, image_path, ocr_raw_text, ocr_confidence, ocr_flags
|
||||
) VALUES (
|
||||
:project_key, :owner_sub, :measured_at, :coins_total, :price_per_coin, :price_currency, :note,
|
||||
:project_key, :owner_sub, :measured_at, :coins_total, :price_per_coin, :price_currency, :fx_fetch_id, :note,
|
||||
:source, :image_path, :ocr_raw_text, :ocr_confidence, :ocr_flags
|
||||
)'
|
||||
);
|
||||
@@ -497,6 +499,38 @@ final class MiningRepository
|
||||
}
|
||||
}
|
||||
|
||||
public function setMeasurementFxFetchId(string $projectKey, int $measurementId, ?int $fxFetchId): ?array
|
||||
{
|
||||
if ($measurementId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$stmt = $this->pdo->prepare(
|
||||
'UPDATE ' . $this->table('measurements') . '
|
||||
SET fx_fetch_id = :fx_fetch_id
|
||||
WHERE project_key = :project_key AND owner_sub = :owner_sub AND id = :id'
|
||||
);
|
||||
$stmt->execute([
|
||||
'fx_fetch_id' => $fxFetchId,
|
||||
'project_key' => $projectKey,
|
||||
'owner_sub' => $this->ownerSub,
|
||||
'id' => $measurementId,
|
||||
]);
|
||||
|
||||
$fetch = $this->pdo->prepare(
|
||||
'SELECT * FROM ' . $this->table('measurements') . '
|
||||
WHERE project_key = :project_key AND owner_sub = :owner_sub AND id = :id LIMIT 1'
|
||||
);
|
||||
$fetch->execute([
|
||||
'project_key' => $projectKey,
|
||||
'owner_sub' => $this->ownerSub,
|
||||
'id' => $measurementId,
|
||||
]);
|
||||
|
||||
$row = $fetch->fetch();
|
||||
return is_array($row) ? $this->normalizeRow($row) : null;
|
||||
}
|
||||
|
||||
public function replaceMeasurementRates(int $measurementId, string $projectKey, array $rates): void
|
||||
{
|
||||
$delete = $this->pdo->prepare('DELETE FROM ' . $this->table('measurement_rates') . ' WHERE measurement_id = :measurement_id AND owner_sub = :owner_sub');
|
||||
|
||||
@@ -184,6 +184,10 @@ final class SchemaManager
|
||||
$this->upgradeSettingsPreferredCurrenciesColumn();
|
||||
$applied[] = 'settings_preferences';
|
||||
}
|
||||
if ($this->tableExists($this->prefix . 'measurements') && !$this->columnExists($this->prefix . 'measurements', 'fx_fetch_id')) {
|
||||
$this->ensureMeasurementFxReferenceColumn();
|
||||
$applied[] = 'measurement_fx_reference';
|
||||
}
|
||||
|
||||
if (!$this->tableExists($this->prefix . 'measurement_rates')) {
|
||||
$this->ensureMeasurementRatesTable();
|
||||
@@ -298,6 +302,10 @@ final class SchemaManager
|
||||
$this->upgradeSettingsPreferredCurrenciesColumn();
|
||||
$applied[] = 'settings_preferences';
|
||||
}
|
||||
if ($this->tableExists($this->prefix . 'measurements') && !$this->columnExists($this->prefix . 'measurements', 'fx_fetch_id')) {
|
||||
$this->ensureMeasurementFxReferenceColumn();
|
||||
$applied[] = 'measurement_fx_reference';
|
||||
}
|
||||
|
||||
if (!$this->tableExists($this->prefix . 'fx_fetches') || !$this->tableExists($this->prefix . 'fx_rates')) {
|
||||
$this->ensureFxRatesTable();
|
||||
@@ -404,6 +412,40 @@ final class SchemaManager
|
||||
$this->ensureLegacyMinerOfferImportColumns();
|
||||
}
|
||||
|
||||
private function ensureMeasurementFxReferenceColumn(): void
|
||||
{
|
||||
$table = $this->prefix . 'measurements';
|
||||
if (!$this->tableExists($table)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$statements = $this->driver === 'pgsql'
|
||||
? [
|
||||
'ALTER TABLE ' . $table . ' ADD COLUMN IF NOT EXISTS fx_fetch_id BIGINT',
|
||||
'CREATE INDEX IF NOT EXISTS idx_miningcheck_measurements_fx_fetch ON ' . $table . ' (fx_fetch_id)',
|
||||
]
|
||||
: [
|
||||
'ALTER TABLE `' . $table . '` ADD COLUMN fx_fetch_id BIGINT UNSIGNED NULL',
|
||||
'ALTER TABLE `' . $table . '` ADD INDEX idx_miningcheck_measurements_fx_fetch (fx_fetch_id)',
|
||||
];
|
||||
|
||||
foreach ($statements as $statement) {
|
||||
try {
|
||||
$this->executeUpgradeStatements([$statement], 'Messpunkt-FX-Referenz konnte nicht angelegt werden.');
|
||||
} catch (\Throwable $exception) {
|
||||
$message = strtolower($exception->getMessage());
|
||||
if (
|
||||
($this->driver === 'mysql' && (str_contains($message, 'duplicate column') || str_contains($message, 'duplicate key name'))) ||
|
||||
($this->driver === 'pgsql' && str_contains($message, 'already exists'))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function ensureLegacyMinerOfferImportColumns(): void
|
||||
{
|
||||
$table = $this->prefix . 'miner_offers';
|
||||
@@ -579,6 +621,10 @@ final class SchemaManager
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->tableExists($this->prefix . 'measurements') && !$this->columnExists($this->prefix . 'measurements', 'fx_fetch_id')) {
|
||||
$upgrades[] = 'measurement_fx_reference';
|
||||
}
|
||||
|
||||
if (!$this->tableExists($this->prefix . 'fx_fetches') || !$this->tableExists($this->prefix . 'fx_rates')) {
|
||||
$upgrades[] = 'fx_rates_table';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user