diff --git a/site_users.install b/site_users.install index 95ae700..13f795f 100644 --- a/site_users.install +++ b/site_users.install @@ -287,3 +287,75 @@ function site_users_update_10002() { return t('Social links field created successfully.'); } + +/** + * Corrige mapeamentos LDAP com prov_events nulo na config ativa. + */ +function site_users_update_10003() { + $config = \Drupal::configFactory()->getEditable('ldap_user.settings'); + $mappings = $config->get('ldapUserSyncMappings'); + + if (empty($mappings)) { + return t('Nenhum mapeamento LDAP encontrado.'); + } + + $changed = FALSE; + foreach ($mappings as $direction => $direction_mappings) { + foreach ($direction_mappings as $id => $mapping) { + if (!is_array($mapping['prov_events'] ?? NULL)) { + $mappings[$direction][$id]['prov_events'] = []; + $changed = TRUE; + } + } + } + + if ($changed) { + $config->set('ldapUserSyncMappings', $mappings)->save(); + return t('Mapeamentos LDAP corrigidos: prov_events nulo substituído por array vazio.'); + } + + return t('Nenhuma correção necessária nos mapeamentos LDAP.'); +} + +/** + * Corrige mapeamentos LDAP com campos de string nulos na config ativa. + */ +function site_users_update_10004() { + $config = \Drupal::configFactory()->getEditable('ldap_user.settings'); + $mappings = $config->get('ldapUserSyncMappings'); + + if (empty($mappings)) { + return t('Nenhum mapeamento LDAP encontrado.'); + } + + $changed = FALSE; + $string_defaults = [ + 'ldap_attr' => '', + 'user_attr' => '', + 'user_tokens' => '', + 'config_module' => 'ldap_user', + 'prov_module' => 'ldap_user', + ]; + + foreach ($mappings as $direction => $direction_mappings) { + foreach ($direction_mappings as $id => $mapping) { + foreach ($string_defaults as $field => $default) { + if (!isset($mapping[$field]) || !is_string($mapping[$field])) { + $mappings[$direction][$id][$field] = $default; + $changed = TRUE; + } + } + if (!isset($mapping['convert'])) { + $mappings[$direction][$id]['convert'] = FALSE; + $changed = TRUE; + } + } + } + + if ($changed) { + $config->set('ldapUserSyncMappings', $mappings)->save(); + return t('Mapeamentos LDAP corrigidos: campos de string nulos normalizados.'); + } + + return t('Nenhuma correção necessária nos mapeamentos LDAP.'); +}