From 823e976f39f394ef685ce919d1b91a8547da984c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Sat, 5 Jul 2014 12:27:35 +0200 Subject: [PATCH] Change the way parameters are provides to scripts sync_xxx_ldap2dolibarr.php --- ChangeLog | 6 ++++- .../members/sync_members_ldap2dolibarr.php | 11 ++++++---- scripts/user/sync_groups_ldap2dolibarr.php | 11 ++++++---- scripts/user/sync_users_ldap2dolibarr.php | 22 ++++++++++++++----- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 139069474c9..30b640ac130 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,7 +23,6 @@ For users: - Fix: [ bug #1502 ] DON_CREATE trigger does not intercept trigger action - Fix: [ bug #1505, #1504] Project trigger problem - For translators: - Update language files. @@ -31,6 +30,11 @@ For developers: - New: Add hook "searchAgendaFrom". - New: Add trigger DON_UPDATE, DON_DELETE +WARNING: Following change may create regression for some external modules, but was necessary to make +Dolibarr better: + +- Change the way parameters are provides to scripts sync_xxx_ldap2dolibarr.php + ***** ChangeLog for 3.6 compared to 3.5.* ***** For users: diff --git a/scripts/members/sync_members_ldap2dolibarr.php b/scripts/members/sync_members_ldap2dolibarr.php index 07cf3f45ac3..d081065a3fa 100755 --- a/scripts/members/sync_members_ldap2dolibarr.php +++ b/scripts/members/sync_members_ldap2dolibarr.php @@ -93,14 +93,17 @@ $required_fields = array( $required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement"))); -if ($argv[3]) $conf->global->LDAP_SERVER_HOST=$argv[2]; - if (! isset($argv[2]) || ! is_numeric($argv[2])) { - print "Usage: $script_file (nocommitiferror|commitiferror) id_member_type [ldapserverhost]\n"; + print "Usage: $script_file (nocommitiferror|commitiferror) id_member_type [--server=ldapserverhost]\n"; exit(-1); } + $typeid=$argv[2]; -if ($argv[1] == 'commitiferror') $forcecommit=1; +foreach($argv as $key => $val) +{ + if ($val == 'commitiferror') $forcecommit=1; + if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; +} print "Mails sending disabled (useless in batch mode)\n"; $conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails diff --git a/scripts/user/sync_groups_ldap2dolibarr.php b/scripts/user/sync_groups_ldap2dolibarr.php index 1da80e57d4e..3170714124b 100755 --- a/scripts/user/sync_groups_ldap2dolibarr.php +++ b/scripts/user/sync_groups_ldap2dolibarr.php @@ -70,16 +70,19 @@ $required_fields = array( // Remove from required_fields all entries not configured in LDAP (empty) and duplicated $required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement"))); -if ($argv[2]) $conf->global->LDAP_SERVER_HOST=$argv[2]; if (! isset($argv[1])) { //print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n"; - print "Usage: $script_file (nocommitiferror|commitiferror) [ldapserverhost]\n"; + print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...]\n"; exit(-1); } -$groupid=$argv[3]; -if ($argv[1] == 'commitiferror') $forcecommit=1; +foreach($argv as $key => $val) +{ + if ($val == 'commitiferror') $forcecommit=1; + if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; + if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); +} print "Mails sending disabled (useless in batch mode)\n"; $conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails diff --git a/scripts/user/sync_users_ldap2dolibarr.php b/scripts/user/sync_users_ldap2dolibarr.php index b7d041f64f9..774a56c45e5 100755 --- a/scripts/user/sync_users_ldap2dolibarr.php +++ b/scripts/user/sync_users_ldap2dolibarr.php @@ -47,6 +47,7 @@ $langs->load("errors"); $version=DOL_VERSION; $error=0; $forcecommit=0; +$excludeuser=array(); /* @@ -83,16 +84,17 @@ $required_fields = array( // Remove from required_fields all entries not configured in LDAP (empty) and duplicated $required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement"))); -if ($argv[2]) $conf->global->LDAP_SERVER_HOST=$argv[2]; - if (! isset($argv[1])) { - //print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n"; - print "Usage: $script_file (nocommitiferror|commitiferror) [ldapserverhost]\n"; + print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...]\n"; exit(-1); } -if ($argv[1] == 'commitiferror') $forcecommit=1; - +foreach($argv as $key => $val) +{ + if ($val == 'commitiferror') $forcecommit=1; + if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; + if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); +} print "Mails sending disabled (useless in batch mode)\n"; $conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails @@ -112,6 +114,7 @@ print "login=".$conf->db->user."\n"; print "database=".$conf->db->name."\n"; print "----- Options:\n"; print "commitiferror=".$forcecommit."\n"; +print "excludeuser=".join(',',$excludeuser)."\n"; print "Mapped LDAP fields=".join(',',$required_fields)."\n"; print "\n"; @@ -179,6 +182,13 @@ if ($result >= 0) // Warning $ldapuser has a key in lowercase foreach ($ldaprecords as $key => $ldapuser) { + // If login into exclude list, we discard record + if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN],$excludeuser)) + { + print $langs->transnoentities("UserDiscarded").' # '.$key.': login='.$ldapuser[$conf->global->LDAP_FIELD_LOGIN].' --> Discarded'."\n"; + continue; + } + $fuser = new User($db); if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) { -- GitLab