mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/site_users.git
synced 2026-03-08 17:37:41 -03:00
fix: Corrige mapeamentos LDAP com campos nulos na config ativa
Adiciona update_10003 e update_10004 para normalizar entradas de ldapUserSyncMappings que possuem prov_events, config_module, prov_module ou outros campos nulos, evitando TypeError no FieldProvider do ldap_user. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user