$settings Rows of the former `settings` table (key => value) * @param bool $encryptBank true for raw database writes; the model's own cast encrypts otherwise * @return array */ public static function forLegacyLandlord(array $settings = [], bool $encryptBank = true): array { return [ 'owner_name' => self::baseline('fewo.owner.name'), 'owner_street' => self::baseline('fewo.owner.street'), 'owner_city' => self::baseline('fewo.owner.city'), 'owner_phone' => self::baseline('fewo.owner.phone'), 'contact_email' => self::setting($settings, 'addresses.contact') ?? self::baseline('fewo.owner.email'), 'notification_emails' => self::setting($settings, 'addresses.notifications') ?? config('fewo.notification_email'), 'sender_name' => self::setting($settings, 'addresses.sender_name') ?? self::baseline('mail.from.name'), 'sender_email' => self::setting($settings, 'addresses.sender_email') ?? self::baseline('mail.from.address'), 'bank_account_holder' => self::bank(self::baseline('fewo.bank.account_holder'), $encryptBank), 'bank_iban' => self::bank(self::baseline('fewo.bank.iban'), $encryptBank), 'bank_bic' => self::bank(self::baseline('fewo.bank.bic'), $encryptBank), 'bank_name' => self::bank(self::baseline('fewo.bank.bank_name'), $encryptBank), 'operating_mode' => ($settings['operations.mode'] ?? 'test') === 'live' ? 'live' : 'test', 'test_recipient' => self::setting($settings, 'operations.test_recipient'), 'deposit_due_days' => self::baseline('fewo.deposit_due_days'), 'review_request_after_days' => self::baseline('fewo.review_request_after_days'), ]; } /** * The mailbox the single-landlord installation used, taken from the .env for a raw database write. * * @return array */ public static function mailboxFromConfig(): array { return [ 'mailbox_host' => config('fewo.mailbox.host'), 'mailbox_port' => config('fewo.mailbox.port'), 'mailbox_encryption' => config('fewo.mailbox.encryption'), 'mailbox_username' => config('fewo.mailbox.username'), 'mailbox_password' => self::bank(config('fewo.mailbox.password'), true), 'mailbox_folder' => config('fewo.mailbox.folder'), ]; } /** * The value of the installation, not the one a landlord may already have laid over the configuration. */ private static function baseline(string $key): mixed { return app(TenantConfig::class)->baselineValue($key); } /** * @param array $settings */ private static function setting(array $settings, string $key): ?string { return filled($settings[$key] ?? null) ? (string) $settings[$key] : null; } public static function bank(mixed $value, bool $encrypt): ?string { if (blank($value)) { return null; } return $encrypt ? Crypt::encryptString((string) $value) : (string) $value; } }