# Merge Cochrane and HK into the property stages

## What it does

`funnels:merge-property-webinars` consolidates these UUID pairs, independently of their database IDs:

| Source | Destination |
| --- | --- |
| `07301db1-9ba1-4fd0-b6b6-8f7af56eadd3` (Cochrane Webinar) | `e28d76d4-008c-45a9-be38-1ad5c9ee5724` (Property Closing) |
| `84a8d1de-65c3-4df9-bea3-a06163284bb8` (HK data webinar) | `07ef866f-3b68-4c26-8e77-abd69c707df5` (Trust Nurturing) |

Trust Nurturing becomes Preview webinar; Property Closing becomes Project webinar with
Trust Nurturing as its candidate source. Historical journeys are not backfilled and no
messages, AI calls, Zoom operations or registrations are dispatched by this command.

## How it works

- Both merges run in one transaction, locking the four funnels and affected rows.
  Without `--apply`, the command only previews. A repeat is a no-op.
- Original slot, event, rule, registration and send IDs remain stable. Event children
  (attendance, Zoom, recordings, offers, responses) follow their unchanged event/slot IDs.
- Source-wide rules become source-slot rules, preserving their activation state. Merged
  slots do not inherit destination-wide welcome rules in media they did not originally use.
- Non-overlapping `lead_funnels` rows move with their attribution and assignment intact.
  Where a person already belongs to the destination, both original registration rows remain:
  the destination already contains the person; the inactive source retains the second
  first-touch history and send-ledger references. Neither history is overwritten or deleted.
  An AI-call opt-out in either record wins.
- `event_series.origin_funnel_id` retains the original landing design, share image and
  WhatsApp group context. The destination owns the actual registrations and rules.
- Source funnels become inactive, marked with `merged_into_funnel_id`, and leave the
  main list. Their manage URLs redirect to the destination. Old public root and slot URLs
  redirect to the moved slot, retaining query parameters. A stale registration form is
  resolved to that slot's next session, never all destination sessions. A moved slot with
  no upcoming session displays its design without a registerable session.
- Conflicting slot slugs, multi-slot sources, existing source journeys/question sets/
  rotations/VSL views/consultations, or unsupported trigger types stop the transaction.
  Review such new Production data before extending the migration policy.
- Every apply writes a private before-image under `storage/app/private/funnel-merges/`
  and prints its path and SHA-256. Preserve it with the deployment record. This is a
  data operation: rolling back the schema migration does **not** undo the merge. A data
  rollback requires reviewing that backup against any registrations received since merging.

### Production execution

Run from the Production application's release directory, using its normal deployment user
and PHP binary. Do not copy development `.env` or credentials. This command reads the
current Production rows; it does not import the development snapshot.

Use a maintenance window: block new requests, pause the site's scheduler and queue workers,
and allow in-flight jobs/requests to finish before applying. Keep them paused through the
code/schema update and merge so an old worker cannot process the new ownership mapping.
Use the site's actual service manager ([Horizon](/docs/modules_handbook/production-setup/horizon.md),
[scheduler](/docs/modules_handbook/production-setup/scheduler.md)); do not flush queues.

After deploying **all files in this change**, including the frontend build:

```bash
php artisan migrate --force
php artisan funnels:merge-property-webinars
php artisan funnels:merge-property-webinars --apply
php artisan funnels:merge-property-webinars
```

The preview must show the intended source/destination names. The final run should report
`already_merged: true` for both. If any command fails, keep maintenance active and inspect
the error before resuming traffic. Existing Journey migrations are prerequisites; running
only the new merge migration against an older release is insufficient.

Restart/resume workers on the **new release**, resume the scheduler, then reopen the site.
Check these URLs (append `?preview=1` when inspecting a webinar with no upcoming session):

- `/cochrane-webinar` → `/2-property-closing/cochrane-live`
- `/hk-data` → `/investment-masterclass/live-demo`
- Both original `/{funnel}/{slot}` URLs → the same destination slots.

These paths describe the current slugs; the redirect code resolves the actual stored slugs.

## Related files

- `app/Console/Commands/MergePropertyWebinars.php` — preview/apply CLI.
- `src/Event/Repositories/FunnelMergeRepository.php` — validation, backup and atomic writes.
- `database/migrations/2026_10_07_180000_add_funnel_merge_references.php` — additive references.
- `src/Event/EventSeries.php` — original marketing context relation.
- `app/Http/Controllers/Main/LandingController.php`, `resources/js/Pages/SlotLanding.vue` — URLs, designs, signup context.
- `app/Http/Controllers/Manage/Events/FunnelsController.php` — list and old manage links.
- `app/Actions/DispatchFunnelWelcomeAction.php` — merged-slot welcome scope.
- `src/Event/Support/FunnelWhatsappComposer.php`, `app/Jobs/Whatsapp/SendFunnelWhatsAppMessage.php` — original group context.
- `tests/Unit/Event/FunnelMergeTest.php` — isolated preview/apply, overlap, idempotence and atomic conflict checks.
