diff --git a/app/Domain/Catalog/OfferService.php b/app/Domain/Catalog/OfferService.php index 44fdc8f..cc82e89 100644 --- a/app/Domain/Catalog/OfferService.php +++ b/app/Domain/Catalog/OfferService.php @@ -8,6 +8,20 @@ class OfferService { public function __construct(private readonly BundleService $bundles) {} + public function currentActiveVersion(Offer $offer): OfferVersion + { + $version = $offer->versions() + ->where('status', OfferStatus::Aktiv) + ->orderByDesc('number') + ->first(); + + if ($version === null) { + throw new DomainRuleException('Das Angebot hat keine aktive Fassung.'); + } + + return $version; + } + /** * @param array $capabilities * @param array $options @@ -77,6 +91,13 @@ public function activate(Offer $offer, array $lines, array $attributes = []): Of $scope = $this->scopeFor($lines); return DB::transaction(function () use ($offer, $lines, $attributes, $scope): OfferVersion { + $offer = Offer::query()->lockForUpdate()->findOrFail($offer->id); + + OfferVersion::query() + ->where('offer_id', $offer->id) + ->where('status', OfferStatus::Aktiv) + ->update(['status' => OfferStatus::Beendet->value]); + $version = $offer->versions()->create([ 'number' => ((int) $offer->versions()->max('number')) + 1, 'status' => OfferStatus::Entwurf, diff --git a/app/Domain/Catalog/OfferVersion.php b/app/Domain/Catalog/OfferVersion.php index 80efbc5..679b261 100644 --- a/app/Domain/Catalog/OfferVersion.php +++ b/app/Domain/Catalog/OfferVersion.php @@ -34,11 +34,24 @@ protected function casts(): array protected static function booted(): void { static::updating(function (OfferVersion $version): void { - if (in_array(StatusValue::of($version->getOriginal('status')), [ - OfferStatus::Aktiv->value, - OfferStatus::Beendet->value, - ], true)) { - throw new DomainRuleException('Eine aktivierte Angebotsfassung ist unveränderlich.'); + $original = StatusValue::of($version->getOriginal('status')); + $next = StatusValue::of($version->status); + + if ($original === OfferStatus::Beendet->value) { + throw new DomainRuleException('Eine beendete Angebotsfassung ist unveränderlich.'); + } + + if ($original === OfferStatus::Aktiv->value) { + if ($next !== OfferStatus::Beendet->value) { + throw new DomainRuleException('Eine aktive Angebotsfassung lässt sich nur durch Beendigung schließen.'); + } + + $dirty = $version->getDirty(); + unset($dirty['status'], $dirty['updated_at']); + + if ($dirty !== []) { + throw new DomainRuleException('Eine aktive Angebotsfassung lässt sich nur durch Beendigung schließen.'); + } } }); } diff --git a/app/Domain/Commerce/Checkout.php b/app/Domain/Commerce/Checkout.php index 1064fa5..6084070 100644 --- a/app/Domain/Commerce/Checkout.php +++ b/app/Domain/Commerce/Checkout.php @@ -4,7 +4,7 @@ use App\Domain\Catalog\DomainRuleException; use App\Domain\Catalog\Offer; -use App\Domain\Catalog\OfferStatus; +use App\Domain\Catalog\OfferService; use App\Domain\Entitlement\Acquisition; use App\Domain\Entitlement\AcquisitionType; use App\Domain\Entitlement\GrantIssuer; @@ -17,7 +17,10 @@ class Checkout { - public function __construct(private readonly GrantIssuer $grants) {} + public function __construct( + private readonly GrantIssuer $grants, + private readonly OfferService $offers, + ) {} public function place(User $user, Offer $offer): Order { @@ -25,9 +28,9 @@ public function place(User $user, Offer $offer): Order throw new DomainRuleException('Nur ein aktives Mitglied kann kaufen.'); } - $version = $offer->versions()->where('status', OfferStatus::Aktiv)->orderByDesc('number')->first(); + $version = $this->offers->currentActiveVersion($offer); - if ($version === null || $version->grant_kind !== 'kauf' || $version->holder_kind !== 'person') { + if ($version->grant_kind !== 'kauf' || $version->holder_kind !== 'person') { throw new DomainRuleException('Dieses Angebot kann nicht als persönlicher Kauf bestellt werden.'); } @@ -35,7 +38,7 @@ public function place(User $user, Offer $offer): Order throw new DomainRuleException('Der Kauf braucht einen Preis an der Angebotsfassung.'); } - return DB::transaction(function () use ($user, $version): Order { + return DB::transaction(function () use ($user, $offer, $version): Order { $order = Order::query()->create([ 'user_id' => $user->id, 'party_id' => $user->party_id, @@ -44,6 +47,7 @@ public function place(User $user, Offer $offer): Order ]); $line = $order->lines()->create([ 'offer_version_id' => $version->id, + 'offer_name' => $offer->name, 'price_cents' => $version->price_cents, 'term_rule' => $version->term_rule, 'update_promise' => $version->update_promise, diff --git a/app/Domain/Commerce/OrderLine.php b/app/Domain/Commerce/OrderLine.php index 6ce4cc9..13e4a18 100644 --- a/app/Domain/Commerce/OrderLine.php +++ b/app/Domain/Commerce/OrderLine.php @@ -12,6 +12,7 @@ class OrderLine extends Model protected $fillable = [ 'order_id', 'offer_version_id', + 'offer_name', 'price_cents', 'term_rule', 'update_promise', diff --git a/app/Domain/Entitlement/GrantIssuer.php b/app/Domain/Entitlement/GrantIssuer.php index da69f93..46d6ff7 100644 --- a/app/Domain/Entitlement/GrantIssuer.php +++ b/app/Domain/Entitlement/GrantIssuer.php @@ -4,6 +4,7 @@ use App\Domain\Catalog\DomainRuleException; use App\Domain\Catalog\Offer; +use App\Domain\Catalog\OfferService; use App\Domain\Catalog\OfferStatus; use App\Domain\Catalog\OfferVersion; use App\Models\User; @@ -11,9 +12,11 @@ class GrantIssuer { + public function __construct(private readonly OfferService $offers) {} + public function claim(User $user, Offer $offer): Acquisition { - $version = $this->activeVersion($offer); + $version = $this->offers->currentActiveVersion($offer); if (! in_array($version->grant_kind, ['auf_abruf', 'bei_registrierung'], true)) { throw new DomainRuleException('Dieses Angebot wird nicht frei vergeben.'); @@ -32,8 +35,9 @@ public function grantRegistrationOffers(User $user): void ->where('status', OfferStatus::Aktiv) ->where('grant_kind', 'bei_registrierung') ->where('holder_kind', 'person') - ->with('offer') + ->orderByDesc('number') ->get() + ->unique('offer_id') ->each(function (OfferVersion $version) use ($user): void { $this->issue($user, $version, AcquisitionType::FreierAbruf, 'offer', $version->offer_id); }); @@ -47,7 +51,7 @@ public function grantManually(User $user, Offer $offer, User $actor, string $rea throw new DomainRuleException('Eine manuelle Vergabe braucht eine Begründung.'); } - $version = $this->activeVersion($offer); + $version = $this->offers->currentActiveVersion($offer); if ($version->holder_kind !== 'person') { throw new DomainRuleException('Dieses Angebot richtet sich nicht an Personen.'); @@ -118,15 +122,4 @@ public function issue( return $acquisition->load('grants'); }); } - - private function activeVersion(Offer $offer): OfferVersion - { - $version = $offer->versions()->where('status', OfferStatus::Aktiv)->orderByDesc('number')->first(); - - if ($version === null) { - throw new DomainRuleException('Das Angebot hat keine aktive Fassung.'); - } - - return $version; - } } diff --git a/database/migrations/2026_11_16_100000_add_offer_name_to_order_lines.php b/database/migrations/2026_11_16_100000_add_offer_name_to_order_lines.php new file mode 100644 index 0000000..99ede3d --- /dev/null +++ b/database/migrations/2026_11_16_100000_add_offer_name_to_order_lines.php @@ -0,0 +1,22 @@ +string('offer_name')->nullable()->after('offer_version_id'); + }); + } + + public function down(): void + { + Schema::table('order_lines', function (Blueprint $table) { + $table->dropColumn('offer_name'); + }); + } +}; \ No newline at end of file diff --git a/docs/analysen/befund-paket-0-testinstanz-2026-03-15.md b/docs/analysen/befund-paket-0-testinstanz-2026-03-15.md new file mode 100644 index 0000000..34e346c --- /dev/null +++ b/docs/analysen/befund-paket-0-testinstanz-2026-03-15.md @@ -0,0 +1,55 @@ +# Paket 0 — Lesender Befund (Testinstanz `luf-test`) + +Stand: 2026-03-15. Quelle: nur lesende SQL-Abfragen gegen PostgreSQL im Container `luf-test-db-1` (`luf_test` / `luf_test`). Keine Schreibzugriffe, keine Produktion. + +## Angebote mit mehr als einer aktiven Fassung + +Kein Treffer. Jedes Angebot hat höchstens eine Fassung im Status `aktiv`. + +| offer_id | offer_name (fachlich) | aktive Fassungen | Nummern | Vergabearten | +|---:|---|---:|---|---| +| — | — | 0 | — | — | + +## Aktive Fassungen (Überblick) + +| offer_id | Bezeichnung | Nummer | grant_kind | price_cents | +|---:|---|---:|---|---:| +| 1 | Kostenloses Merkblatt | 1 | auf_abruf | — | +| 2 | Testkauf Programm | 1 | kauf | 500 | + +## Registrierung heute + +Aktive Fassungen mit `grant_kind = bei_registrierung` und `holder_kind = person`: **0**. + +Die heutige Implementierung vergäbe bei Registrierung **keine** Angebote aus dieser Kategorie. Dubletten wären relevant, sobald Registrierungsangebote aktiv sind; aktuell nicht messbar. + +Hinweis zum künftigen Codepfad (Paket 1, G8): Nach Freigabe liest die Registrierung je Angebot nur die **höchste** aktive Nummer — nicht mehr alle parallelen Fassungen. + +## Bestellzeilen ohne Bezeichnungskopie + +Spalte `offer_name` auf `order_lines`: **fehlt** (noch nicht migriert auf Test). + +| Kennzahl | Wert | +|---|---:| +| Bestellzeilen gesamt | 3 | +| Zeilen ohne Kopie (Spalte fehlt) | 3 | + +Eine nachträgliche Befüllung alter Zeilen ist nicht vorgesehen (Paket 1). + +## Grants bei Dubletten-Angeboten + +Keine Dubletten → keine grant-spezifische Auswertung je paralleler Fassung. + +Überblick Grants je Angebot (`reference_type = offer`): + +| offer_id | Anzahl Grants | +|---:|---:| +| 1 | 2 | + +## Freigabe zur Bereinigung + +**Nicht erforderlich** auf Test: es gibt keine überzähligen aktiven Fassungen. Die Bereinigung wartet auf künftige Befunde oder andere Umgebungen. + +## Wiederverwendbare Abfragen + +`scripts/paket0-readonly.sql` und `scripts/paket0-readonly-extra.sql` (nur lesend). \ No newline at end of file diff --git a/resources/views/member/order.blade.php b/resources/views/member/order.blade.php index 168f6b3..66081fb 100644 --- a/resources/views/member/order.blade.php +++ b/resources/views/member/order.blade.php @@ -10,7 +10,7 @@ @endif

Status: {{ $order->status }}

@foreach ($order->lines as $line) -

{{ $line->offerVersion->offer->name ?? 'Angebot' }} · {{ number_format($line->price_cents / 100, 2, ',', '.') }} €

+

{{ filled($line->offer_name) ? $line->offer_name : ($line->offerVersion->offer->name ?? 'Angebot') }} · {{ number_format($line->price_cents / 100, 2, ',', '.') }} €

@endforeach @if ($testPayment && $order->status === 'offen')
diff --git a/scripts/paket0-readonly-extra.sql b/scripts/paket0-readonly-extra.sql new file mode 100644 index 0000000..d122182 --- /dev/null +++ b/scripts/paket0-readonly-extra.sql @@ -0,0 +1,19 @@ +\echo '=== Aktive Angebotsfassungen (Überblick) ===' +SELECT ov.offer_id, o.name, ov.number, ov.grant_kind, ov.price_cents +FROM offer_versions ov +JOIN offers o ON o.id = ov.offer_id +WHERE ov.status = 'aktiv' +ORDER BY ov.offer_id, ov.number; + +\echo '=== Heutige Registrierungslogik: alle aktiven personen-Registrierungsfassungen ===' +SELECT count(*)::int AS would_issue_count +FROM offer_versions +WHERE status = 'aktiv' AND grant_kind = 'bei_registrierung' AND holder_kind = 'person'; + +\echo '=== Grants je Angebot (über acquisition reference offer) ===' +SELECT a.reference_id AS offer_id, count(DISTINCT g.id)::int AS grant_count +FROM acquisitions a +JOIN grants g ON g.acquisition_id = a.id +WHERE a.reference_type = 'offer' +GROUP BY a.reference_id +ORDER BY a.reference_id; \ No newline at end of file diff --git a/scripts/paket0-readonly.sql b/scripts/paket0-readonly.sql new file mode 100644 index 0000000..281d836 --- /dev/null +++ b/scripts/paket0-readonly.sql @@ -0,0 +1,52 @@ +-- Paket 0: lesende Bestandsaufnahme (Testinstanz). Keine Schreibzugriffe. + +\echo '=== Angebote mit mehr als einer aktiven Fassung ===' +SELECT o.id AS offer_id, + o.name AS offer_name, + count(*)::int AS active_count, + string_agg(ov.number::text, ',' ORDER BY ov.number) AS active_numbers, + string_agg(DISTINCT ov.grant_kind, ',') AS grant_kinds +FROM offers o +JOIN offer_versions ov ON ov.offer_id = o.id AND ov.status = 'aktiv' +GROUP BY o.id, o.name +HAVING count(*) > 1 +ORDER BY o.id; + +\echo '=== Alle aktiven Registrierungsfassungen ===' +SELECT ov.offer_id, + o.name AS offer_name, + ov.id AS version_id, + ov.number, + ov.grant_kind +FROM offer_versions ov +JOIN offers o ON o.id = ov.offer_id +WHERE ov.status = 'aktiv' + AND ov.grant_kind = 'bei_registrierung' + AND ov.holder_kind = 'person' +ORDER BY ov.offer_id, ov.number; + +\echo '=== Spalte offer_name auf order_lines ===' +SELECT column_name +FROM information_schema.columns +WHERE table_schema = 'public' + AND table_name = 'order_lines' + AND column_name = 'offer_name'; + +\echo '=== Anzahl Bestellzeilen gesamt ===' +SELECT count(*)::int AS order_line_count FROM order_lines; + +\echo '=== Grants mit offer_version_id in conditions (aktive Dubletten-Angebote) ===' +SELECT ov.offer_id, + ov.number AS version_number, + (a.conditions->>'offer_version_id') AS stored_version_id, + count(g.id)::int AS grant_count +FROM offer_versions ov +JOIN offers o ON o.id = ov.offer_id +LEFT JOIN acquisitions a ON (a.conditions->>'offer_version_id')::bigint = ov.id +LEFT JOIN grants g ON g.acquisition_id = a.id +WHERE ov.status = 'aktiv' + AND ov.offer_id IN ( + SELECT offer_id FROM offer_versions WHERE status = 'aktiv' GROUP BY offer_id HAVING count(*) > 1 + ) +GROUP BY ov.offer_id, ov.number, a.conditions->>'offer_version_id' +ORDER BY ov.offer_id, ov.number; \ No newline at end of file diff --git a/tests/Feature/OfferActivationParallelTest.php b/tests/Feature/OfferActivationParallelTest.php new file mode 100644 index 0000000..4522a2b --- /dev/null +++ b/tests/Feature/OfferActivationParallelTest.php @@ -0,0 +1,107 @@ +databasePath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'luf_parallel_'.Str::uuid()->toString().'.sqlite'; + touch($this->databasePath); + + config(['database.connections.sqlite.database' => $this->databasePath]); + DB::purge('sqlite'); + DB::reconnect('sqlite'); + Artisan::call('migrate', ['--force' => true]); + } + + protected function tearDown(): void + { + if ($this->databasePath !== null && is_file($this->databasePath)) { + @unlink($this->databasePath); + } + + config(['database.connections.sqlite.database' => ':memory:']); + DB::purge('sqlite'); + + parent::tearDown(); + } + + public function test_overlapping_activations_leave_exactly_one_active_version(): void + { + [$article, $rights, $offer] = $this->offerWithArticle(); + + $baseEnv = [ + 'APP_ENV' => 'testing', + 'APP_KEY' => config('app.key'), + 'DB_CONNECTION' => 'sqlite', + 'DB_DATABASE' => $this->databasePath, + 'CACHE_STORE' => 'array', + 'QUEUE_CONNECTION' => 'sync', + 'SESSION_DRIVER' => 'array', + ]; + + $worker = base_path('tests/Support/offer_activate_worker.php'); + + $results = Process::pool(function ($pool) use ($baseEnv, $worker, $offer, $article, $rights): void { + $pool->as('a') + ->path(base_path()) + ->env($baseEnv) + ->timeout(120) + ->command([PHP_BINARY, $worker, $this->databasePath, (string) $offer->id, (string) $article->id, (string) $rights->id, '1000', '80']); + $pool->as('b') + ->path(base_path()) + ->env($baseEnv) + ->timeout(120) + ->command([PHP_BINARY, $worker, $this->databasePath, (string) $offer->id, (string) $article->id, (string) $rights->id, '2000', '0']); + })->start()->wait(); + + $this->assertTrue($results['a']->successful(), $results['a']->errorOutput()); + $this->assertTrue($results['b']->successful(), $results['b']->errorOutput()); + + $active = OfferVersion::query()->where('offer_id', $offer->id)->where('status', OfferStatus::Aktiv)->get(); + $this->assertCount(1, $active); + + $versions = OfferVersion::query()->where('offer_id', $offer->id)->orderBy('number')->get(); + $this->assertCount(2, $versions); + $this->assertSame(OfferStatus::Beendet, $versions->first()->status); + $this->assertContains($versions->last()->price_cents, [1000, 2000]); + $this->assertNotSame($versions->first()->price_cents, $versions->last()->price_cents); + } + + /** + * @return array{0: LicenseArticle, 1: RightsProfileVersion, 2: Offer} + */ + private function offerWithArticle(): array + { + $content = app(ContentService::class); + $version = $content->publishElementVersion($content->createElement('text', 'text', 'Basis'), 'Basis'); + $article = app(ArticleService::class)->publishRelease( + app(ArticleService::class)->create('parallel-basis'), + $version, + 'Paralleltest.', + )->article->fresh(); + $rights = app(OfferService::class)->createRightsProfile('Lesen', 'ehrenamtlich', ['text' => ['ansehen']]); + $offer = app(OfferService::class)->create('Parallelangebot'); + + return [$article, $rights, $offer]; + } +} \ No newline at end of file diff --git a/tests/Feature/OfferVersioningTest.php b/tests/Feature/OfferVersioningTest.php new file mode 100644 index 0000000..43512de --- /dev/null +++ b/tests/Feature/OfferVersioningTest.php @@ -0,0 +1,170 @@ +offerWithArticle(); + $offers = app(OfferService::class); + + $first = $offers->activate($offer, [ + ['target' => $article, 'rights' => $rights], + ], ['grant_kind' => 'kauf', 'price_cents' => 500]); + + $second = $offers->activate($offer, [ + ['target' => $article, 'rights' => $rights], + ], ['grant_kind' => 'kauf', 'price_cents' => 900]); + + $first->refresh(); + $second->refresh(); + + $this->assertSame(OfferStatus::Beendet, $first->status); + $this->assertSame(500, $first->price_cents); + $this->assertSame(OfferStatus::Aktiv, $second->status); + $this->assertSame(1, OfferVersion::query()->where('offer_id', $offer->id)->where('status', OfferStatus::Aktiv)->count()); + } + + public function test_an_active_version_cannot_change_except_to_beendet(): void + { + [, $rights, $offer] = $this->offerWithArticle(); + $version = app(OfferService::class)->activate($offer, [ + ['target' => $this->publishedArticle('preis', 'Preis'), 'rights' => $rights], + ], ['grant_kind' => 'kauf', 'price_cents' => 100]); + + $version->price_cents = 200; + + $this->expectException(DomainRuleException::class); + $version->save(); + } + + public function test_registration_uses_only_the_highest_active_duplicate_version(): void + { + [, $rights, $offer] = $this->offerWithArticle(); + $offers = app(OfferService::class); + $low = $offers->activate($offer, [ + ['target' => $this->publishedArticle('reg-a', 'Reg A'), 'rights' => $rights], + ], ['grant_kind' => 'bei_registrierung']); + + $high = OfferVersion::query()->create([ + 'offer_id' => $offer->id, + 'number' => $low->number + 1, + 'status' => OfferStatus::Aktiv, + 'term_rule' => $low->term_rule, + 'update_promise' => $low->update_promise, + 'dynamic' => false, + 'grant_kind' => 'bei_registrierung', + 'holder_kind' => 'person', + 'activated_at' => now(), + ]); + + $user = User::factory()->create(); + app(GrantIssuer::class)->grantRegistrationOffers($user); + + $acquisitions = Acquisition::query() + ->where('party_id', $user->party_id) + ->where('reference_type', 'offer') + ->where('reference_id', $offer->id) + ->get(); + + $this->assertCount(1, $acquisitions); + $this->assertSame($high->id, (int) ($acquisitions->first()->conditions['offer_version_id'] ?? 0)); + + app(GrantIssuer::class)->grantRegistrationOffers($user); + $this->assertSame(1, Acquisition::query()->where('party_id', $user->party_id)->where('reference_id', $offer->id)->count()); + } + + public function test_order_line_stores_offer_name_and_keeps_it_when_the_offer_is_renamed(): void + { + [, $rights, $offer] = $this->offerWithArticle(); + $offers = app(OfferService::class); + $offers->activate($offer, [ + ['target' => $this->publishedArticle('kauf', 'Kauf'), 'rights' => $rights], + ], ['grant_kind' => 'kauf', 'price_cents' => 1200]); + + $member = User::factory()->create(); + $order = app(Checkout::class)->place($member, $offer); + $line = $order->lines()->first(); + + $this->assertSame('Testangebot', $line->offer_name); + + $offer->update(['name' => 'Umbenannt']); + + $response = $this->actingAs($member)->get(route('member.order', $order)); + + $response->assertOk()->assertSee('Testangebot')->assertDontSee('Umbenannt'); + } + + public function test_an_existing_grant_keeps_snapshot_and_release_reference(): void + { + [$article, $rights, $offer] = $this->offerWithArticle(); + app(OfferService::class)->activate($offer, [ + ['target' => $article, 'rights' => $rights], + ], ['grant_kind' => 'auf_abruf']); + + $member = User::factory()->create(); + app(GrantIssuer::class)->claim($member, $offer); + $grant = Grant::query()->first(); + $snapshot = $grant->rights_snapshot; + $releaseId = $grant->release_at_grant_id; + + app(OfferService::class)->activate($offer, [ + ['target' => $article, 'rights' => $rights], + ], ['grant_kind' => 'auf_abruf']); + + $grant->refresh(); + $this->assertSame($snapshot, $grant->rights_snapshot); + $this->assertSame($releaseId, $grant->release_at_grant_id); + } + + /** + * @return array{0: LicenseArticle, 1: RightsProfileVersion, 2: Offer} + */ + private function offerWithArticle(): array + { + $article = $this->publishedArticle('basis', 'Basis'); + $rights = $this->rights(); + $offer = app(OfferService::class)->create('Testangebot'); + + return [$article, $rights, $offer]; + } + + private function publishedArticle(string $code, string $title): LicenseArticle + { + $content = app(ContentService::class); + $version = $content->publishElementVersion($content->createElement('text', 'text', $title), $title); + + return app(ArticleService::class)->publishRelease( + app(ArticleService::class)->create($code), + $version, + 'Testartikel.', + )->article->fresh(); + } + + private function rights(): RightsProfileVersion + { + return app(OfferService::class)->createRightsProfile('Lesen', 'ehrenamtlich', [ + 'text' => ['ansehen'], + ]); + } +} \ No newline at end of file diff --git a/tests/Support/offer_activate_worker.php b/tests/Support/offer_activate_worker.php new file mode 100644 index 0000000..db940e9 --- /dev/null +++ b/tests/Support/offer_activate_worker.php @@ -0,0 +1,47 @@ + \n"); + exit(2); +} + +$database = $argv[1]; +$offerId = (int) $argv[2]; +$articleId = (int) $argv[3]; +$rightsId = (int) $argv[4]; +$priceCents = (int) $argv[5]; +$delayMs = (int) $argv[6]; + +putenv('APP_ENV=testing'); +putenv('DB_CONNECTION=sqlite'); +putenv('DB_DATABASE='.$database); + +require __DIR__.'/../../vendor/autoload.php'; +$app = require __DIR__.'/../../bootstrap/app.php'; +$app->make(Kernel::class)->bootstrap(); + +if ($delayMs > 0) { + usleep($delayMs * 1000); +} + +$offers = app(OfferService::class); +$offer = Offer::query()->findOrFail($offerId); +$article = LicenseArticle::query()->findOrFail($articleId); +$rights = RightsProfileVersion::query()->findOrFail($rightsId); + +$offers->activate($offer, [ + ['target' => $article, 'rights' => $rights], +], [ + 'grant_kind' => 'kauf', + 'price_cents' => $priceCents, +]); + +echo "ok\n"; \ No newline at end of file