From 32f87ef27c94ee3d256ab23201a1e4cd043ed244 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Mon, 29 Jun 2026 10:52:44 -0500 Subject: [PATCH] fix: company save no longer deactivates on partial updates The checkbox-to-0 logic was running on every save including partial saves (e.g. bot-config only sends config_json). This silently set is_active=0 every time the bot config was saved. Now checkbox defaults only apply when 'name' is present in the data, which is the case only for full company-form saves. Co-Authored-By: Claude Sonnet 4.6 --- services/CompanyRepository.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/services/CompanyRepository.php b/services/CompanyRepository.php index 5563250..ba06d34 100644 --- a/services/CompanyRepository.php +++ b/services/CompanyRepository.php @@ -43,10 +43,13 @@ class CompanyRepository $fields = ['name', 'display_name', 'phone_number_id', 'display_phone', 'api_base_url', 'api_key', 'bot_type', 'requires_approval', 'is_active', 'config_json', 'erp_active_users']; - // Checkboxes: absent when unchecked — explicitly set to 0 so UPDATE clears them - foreach (['requires_approval', 'is_active'] as $cb) { - if (!array_key_exists($cb, $data)) { - $data[$cb] = 0; + // Checkboxes only default to 0 on full company-form saves (when 'name' is present). + // Partial saves (e.g. bot-config saving only config_json) must NOT touch is_active. + if (array_key_exists('name', $data)) { + foreach (['requires_approval', 'is_active'] as $cb) { + if (!array_key_exists($cb, $data)) { + $data[$cb] = 0; + } } }