Bestehende Kunden-Integrationen der Altportale laufen nach dem Relaunch weiter, ohne dass Kunden etwas umstellen muessen: 1. legacy:import-api-keys uebernimmt die api_keys aus den Legacy-DBs (sf_guard_user_profile) als Sanctum-Tokens mit identischem Secret (Sanctum loest Tokens ohne id|-Praefix per sha256-Hash auf) — nur fuer berechtigte Nutzer (aktiver Zahlungsstatus/Bestandsschutz, ApiAccessEligibilityService); idempotent, mit Dry-Run. Probe gegen die lokalen Snapshots: 406 Keys wuerden uebernommen. 2. Die Auth-Middleware uebersetzt die alten Uebergabeformen (X-ApiKey- Header, api_key-Parameter) fuer gueltige Keys in Bearer; unbekannte Keys erhalten weiterhin 410 mit Migrationshinweis. 3. Die dokumentierten /service/...-Pfade der Alt-API sind als Aliasse auf die v1-Controller gelegt (pressreleases inkl. Bilder, companies lesend); nicht uebernommene Alt-Endpoints (Pressemappen/Kontakte anlegen) antworten 410 mit Hinweis auf Kundenkonto und neue Doku. API-Seite + OpenAPI entsprechend aktualisiert; Go-Live-Checkliste um den Import-Schritt (nach dem Grandfathering) ergaenzt. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
82 lines
2.9 KiB
PHP
82 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\Api\LegacyApiKeyImporter;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/**
|
|
* Importiert die Legacy-api_keys der Altportale als Sanctum-Tokens
|
|
* (Übernahme bestehender API-Integrationen, 06.07.2026). Quelle sind die
|
|
* read-only Legacy-Verbindungen; berechtigt ist, wer auch selbst ein Token
|
|
* erstellen dürfte (aktiver Zahlungsstatus/Bestandsschutz). Wiederholbar:
|
|
* bereits importierte Schlüssel werden übersprungen.
|
|
*
|
|
* Verwendung:
|
|
* php artisan legacy:import-api-keys --dry-run
|
|
* php artisan legacy:import-api-keys --portal=businessportal24
|
|
*/
|
|
class ImportLegacyApiKeys extends Command
|
|
{
|
|
protected $signature = 'legacy:import-api-keys
|
|
{--portal=all : presseecho | businessportal24 | all}
|
|
{--dry-run : Nur anzeigen, nichts schreiben}';
|
|
|
|
protected $description = 'Übernimmt die api_keys der Legacy-Portale als Sanctum-Tokens (bestehende Integrationen bleiben gültig).';
|
|
|
|
private const CONNECTIONS = [
|
|
'presseecho' => 'mysql_presseecho',
|
|
'businessportal24' => 'mysql_businessportal',
|
|
];
|
|
|
|
public function handle(LegacyApiKeyImporter $importer): int
|
|
{
|
|
$portalOption = (string) $this->option('portal');
|
|
$dryRun = (bool) $this->option('dry-run');
|
|
|
|
$portals = $portalOption === 'all' ? array_keys(self::CONNECTIONS) : [$portalOption];
|
|
|
|
if (array_diff($portals, array_keys(self::CONNECTIONS)) !== []) {
|
|
$this->error('Ungültiges Portal. Erlaubt: presseecho, businessportal24, all.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
if ($dryRun) {
|
|
$this->warn('[DRY-RUN] Kein tatsächlicher Schreibvorgang.');
|
|
}
|
|
|
|
foreach ($portals as $portal) {
|
|
$rows = DB::connection(self::CONNECTIONS[$portal])
|
|
->table('sf_guard_user_profile')
|
|
->whereNotNull('api_key')
|
|
->where('api_key', '!=', '')
|
|
->get(['user_id', 'api_key'])
|
|
->map(fn (object $row): array => [
|
|
'legacy_id' => (int) $row->user_id,
|
|
'api_key' => (string) $row->api_key,
|
|
]);
|
|
|
|
$result = $importer->import($portal, $rows, $dryRun);
|
|
|
|
$this->table(
|
|
['Portal', 'Keys in Legacy-DB', 'Importiert', 'Schon vorhanden', 'Nicht berechtigt', 'Kein User-Mapping'],
|
|
[[
|
|
$portal,
|
|
$rows->count(),
|
|
$result['imported'],
|
|
$result['already_present'],
|
|
$result['ineligible'],
|
|
$result['unknown_user'],
|
|
]],
|
|
);
|
|
|
|
foreach ($result['ineligible_users'] as $email) {
|
|
$this->warn("Nicht berechtigt (kein aktiver Zahlungsstatus): {$email}");
|
|
}
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|