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 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-29 10:52:44 -05:00
co-authored by Claude Sonnet 4.6
parent fb61a6e027
commit 32f87ef27c
+7 -4
View File
@@ -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;
}
}
}