feat(13-email-mailboxes): phase 13 complete — email DB foundation + SMTP mailbox CRUD

3 migrations (email_mailboxes, email_templates, email_logs), full CRUD
for SMTP mailboxes with encrypted passwords (IntegrationSecretCipher),
native SMTP connection test via stream_socket_client, sidebar navigation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-15 23:57:33 +01:00
parent 8b3fb3fd0b
commit 3223aac4d9
16 changed files with 1257 additions and 19 deletions

View File

@@ -92,6 +92,9 @@ Migracje z prefiksem `ensure_` to migracje kompensujące — zostały dodane
- 2026-03-15: Dodano migracje `20260315_000051_create_receipts_table.sql` — tabela wystawionych paragonow ze snapshotem danych (JSON seller/buyer/items), FK do orders i receipt_configs.
- 2026-03-15: Dodano migracje `20260315_000052_create_receipt_number_counters_table.sql` — liczniki numeracji paragonow per konfiguracja i okres (miesiac/rok).
- 2026-03-15: Dodano migracje `20260315_000053_extend_company_settings_extra_fields.sql` — rozszerzenie company_settings o bdo_number, regon, court_register, logo_path.
- 2026-03-15: Dodano migracje `20260315_000054_create_email_mailboxes_table.sql` — tabela skrzynek pocztowych SMTP (credentials szyfrowane IntegrationSecretCipher).
- 2026-03-15: Dodano migracje `20260315_000055_create_email_templates_table.sql` — tabela szablonow wiadomosci email z FK do email_mailboxes.
- 2026-03-15: Dodano migracje `20260315_000056_create_email_logs_table.sql` — tabela logow wyslanych wiadomosci z FK do email_templates, email_mailboxes i indeksami na order_id, status, sent_at.
## Tabele
@@ -384,6 +387,52 @@ Migracje z prefiksem `ensure_` to migracje kompensujące — zostały dodane
- Klucze obce:
- `receipt_counters_config_fk`: `config_id` -> `receipt_configs.id` (ON DELETE CASCADE).
### `email_mailboxes`
- Skrzynki pocztowe SMTP do wysylki wiadomosci e-mail.
- Kolumny:
- `id` INT UNSIGNED PK AUTO_INCREMENT
- `name` VARCHAR(100) NOT NULL — nazwa wyswietlana
- `smtp_host` VARCHAR(255) NOT NULL
- `smtp_port` SMALLINT UNSIGNED NOT NULL DEFAULT 587
- `smtp_encryption` ENUM('tls','ssl','none') NOT NULL DEFAULT 'tls'
- `smtp_username` VARCHAR(255) NOT NULL
- `smtp_password_encrypted` TEXT NOT NULL — szyfrowane IntegrationSecretCipher (AES-256-CBC+HMAC)
- `sender_email` VARCHAR(255) NOT NULL
- `sender_name` VARCHAR(200) DEFAULT NULL
- `is_default` TINYINT(1) NOT NULL DEFAULT 0
- `is_active` TINYINT(1) NOT NULL DEFAULT 1
- `created_at`, `updated_at` DATETIME
### `email_templates`
- Szablony wiadomosci e-mail z systemem zmiennych.
- Kolumny:
- `id` INT UNSIGNED PK AUTO_INCREMENT
- `name` VARCHAR(200) NOT NULL — nazwa szablonu
- `subject` VARCHAR(500) NOT NULL — temat (moze zawierac zmienne)
- `body_html` TEXT NOT NULL — tresc HTML (Quill.js output)
- `mailbox_id` INT UNSIGNED DEFAULT NULL — FK do email_mailboxes ON DELETE SET NULL
- `is_active` TINYINT(1) NOT NULL DEFAULT 1
- `created_at`, `updated_at` DATETIME
- Indeksy: `idx_email_templates_mailbox` (mailbox_id)
### `email_logs`
- Log wyslanych wiadomosci e-mail.
- Kolumny:
- `id` BIGINT UNSIGNED PK AUTO_INCREMENT
- `template_id` INT UNSIGNED DEFAULT NULL — FK do email_templates ON DELETE SET NULL
- `mailbox_id` INT UNSIGNED DEFAULT NULL — FK do email_mailboxes ON DELETE SET NULL
- `order_id` INT UNSIGNED DEFAULT NULL
- `recipient_email` VARCHAR(255) NOT NULL
- `recipient_name` VARCHAR(200) DEFAULT NULL
- `subject` VARCHAR(500) NOT NULL
- `body_html` TEXT NOT NULL — tresc po rozwinieciu zmiennych
- `attachments_json` JSON DEFAULT NULL — lista zalacznikow [{name, path, type}]
- `status` ENUM('sent','failed','pending') NOT NULL DEFAULT 'pending'
- `error_message` TEXT DEFAULT NULL
- `sent_at` DATETIME DEFAULT NULL
- `created_at` DATETIME
- Indeksy: `idx_email_logs_template`, `idx_email_logs_mailbox`, `idx_email_logs_order`, `idx_email_logs_status`, `idx_email_logs_sent_at`
## Zasady aktualizacji
- Po kazdej migracji dopisz:
- nowe/zmienione tabele i kolumny,