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/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 0a5a1e1ee90..c06c43eb4a4 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3383,9 +3383,8 @@ abstract class CommonObject /** * Call trigger based on this instance - * - * NB: Error from trigger are stacked in errors - * NB2: if trigger fail, action should be canceled. + * NB: Error from trigger are stacked in interface->errors + * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. * * @param string $trigger_name trigger's name to execute * @param User $user Object user @@ -3393,23 +3392,23 @@ abstract class CommonObject */ function call_trigger($trigger_name, $user) { - global $langs,$conf; - - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); - if ($result < 0) { - if (!empty($this->errors)) - { - $this->errors=array_merge($this->errors,$interface->errors); - } - else - { - $this->errors=$interface->errors; - } - } - return $result; + global $langs,$conf; + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); + if ($result < 0) + { + if (!empty($this->errors)) + { + $this->errors=array_merge($this->errors,$interface->errors); + } + else + { + $this->errors=$interface->errors; + } + } + return $result; } } diff --git a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php index 8eb0c33d11f..539bc169958 100644 --- a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php +++ b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php @@ -293,29 +293,28 @@ class doc_generic_odt extends ModeleThirdPartyDoc // setVars failed, probably because key not found } } - - + + // Replace tags of lines for contacts $contact_arrray=array(); - + $sql = "SELECT p.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p"; $sql .= " WHERE p.fk_soc = ".$object->id; - - dol_syslog('doc_generic_odt ::', LOG_DEBUG); + $result = $this->db->query($sql); $num = $this->db->num_rows($result); - + $var=true; if ($num) { $i=0; $contactstatic = new Contact($this->db); - + while($i < $num) { $obj = $this->db->fetch_object($result); - + $contact_arrray[$i] = $obj->rowid; $i++; } @@ -325,7 +324,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc try { $listlines = $odfHandler->setSegment('companycontacts'); - + foreach($contact_arrray as $array_key => $contact_id) { $res_contact = $contactstatic->fetch($contact_id); @@ -354,11 +353,16 @@ class doc_generic_odt extends ModeleThirdPartyDoc //return -1; } } - + + // Make substitutions into odt of thirdparty + external modules + $tmparray=$this->get_substitutionarray_thirdparty($object,$outputlangs); + complete_substitutions_array($tmparray, $outputlangs, $object); + // Call the ODTSubstitution hook $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - //var_dump($object->id); exit; + + // Replace variables into document foreach($tmparray as $key=>$value) { try { @@ -389,11 +393,6 @@ class doc_generic_odt extends ModeleThirdPartyDoc { } } - - - // Make substitutions into odt of thirdparty + external modules - $tmparray=$this->get_substitutionarray_thirdparty($object,$outputlangs); - complete_substitutions_array($tmparray, $outputlangs, $object); // Call the beforeODTSave hook $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 1ecfefc6d82..9e8b5539c20 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -667,7 +667,7 @@ class User extends CommonObject { // Call trigger $result=$this->call_trigger('USER_ENABLEDISABLE',$user); - if ($result < 0) { $error++; } + if ($result < 0) { $error++; } // End call triggers } @@ -756,14 +756,14 @@ class User extends CommonObject { // Call trigger $result=$this->call_trigger('USER_DELETE',$user); - if ($result < 0) - { + if ($result < 0) + { $error++; $this->db->rollback(); - return -1; - } + return -1; + } // End call triggers - + $this->db->commit(); return 1; } @@ -866,7 +866,7 @@ class User extends CommonObject { // Call trigger $result=$this->call_trigger('USER_CREATE',$user); - if ($result < 0) { $error++; } + if ($result < 0) { $error++; } // End call triggers } @@ -949,9 +949,9 @@ class User extends CommonObject { // Call trigger $result=$this->call_trigger('USER_CREATE_FROM_CONTACT',$user); - if ($result < 0) { $error++; $this->db->rollback(); return -1; } + if ($result < 0) { $error++; $this->db->rollback(); return -1; } // End call triggers - + $this->db->commit(); return $this->id; } @@ -1261,7 +1261,7 @@ class User extends CommonObject { // Call trigger $result=$this->call_trigger('USER_MODIFY',$user); - if ($result < 0) { $error++; } + if ($result < 0) { $error++; } // End call triggers } @@ -1352,7 +1352,7 @@ class User extends CommonObject if (! is_object($this->oldcopy)) $this->oldcopy=dol_clone($this); $this->db->begin(); - + $sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql.= " SET pass_crypted = '".$this->db->escape($password_crypted)."',"; $sql.= " pass_temp = null"; @@ -1408,10 +1408,10 @@ class User extends CommonObject { // Call trigger $result=$this->call_trigger('USER_NEW_PASSWORD',$user); - if ($result < 0) { $error++; $this->db->rollback(); return -1; } + if ($result < 0) { $error++; $this->db->rollback(); return -1; } // End call triggers } - + $this->db->commit(); return $this->pass; } @@ -1666,7 +1666,7 @@ class User extends CommonObject // Call trigger $result=$this->call_trigger('USER_SETINGROUP',$user); - if ($result < 0) { $error++; } + if ($result < 0) { $error++; } // End call triggers } @@ -1720,7 +1720,7 @@ class User extends CommonObject // Call trigger $result=$this->call_trigger('USER_REMOVEFROMGROUP',$user); - if ($result < 0) { $error++; } + if ($result < 0) { $error++; } // End call triggers } @@ -2281,7 +2281,7 @@ class User extends CommonObject dol_syslog(get_class($this)."::get_full_tree dol_sort_array", LOG_DEBUG); $this->users=dol_sort_array($this->users, 'fullname', 'asc', true, false); - //$this->debug_users(); + //var_dump($this->users); return $this->users; } @@ -2322,24 +2322,5 @@ class User extends CommonObject return; } - /** - * Affiche contenu de $this->users - * - * @return void - */ - function debug_users() - { - // Affiche $this->users - foreach($this->users as $key => $val) - { - print 'id: '.$this->users[$key]['id']; - print ' name: '.$this->users[$key]['name']; - print ' parent: '.$this->users[$key]['fk_user']; - print ' fullpath: '.$this->users[$key]['fullpath']; - print ' fullname: '.$this->users[$key]['fullname']; - print "
\n"; - } - } - } diff --git a/scripts/members/sync_members_dolibarr2ldap.php b/scripts/members/sync_members_dolibarr2ldap.php index c5307b17673..072d78f6317 100755 --- a/scripts/members/sync_members_dolibarr2ldap.php +++ b/scripts/members/sync_members_dolibarr2ldap.php @@ -82,6 +82,7 @@ print "Press a key to confirm...\n"; $input = trim(fgets(STDIN)); print "Warning, this operation may result in data loss if it failed.\n"; print "Be sure to have a backup of your LDAP database (With OpenLDAP: slapcat > save.ldif).\n"; + print "Hit Enter to continue or CTRL+C to stop...\n"; $input = trim(fgets(STDIN)); diff --git a/scripts/members/sync_members_ldap2dolibarr.php b/scripts/members/sync_members_ldap2dolibarr.php index 9a662839a3f..d081065a3fa 100755 --- a/scripts/members/sync_members_ldap2dolibarr.php +++ b/scripts/members/sync_members_ldap2dolibarr.php @@ -93,16 +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]; - -print "***** $script_file ($version) *****\n"; - 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 @@ -138,8 +139,6 @@ if ($typeid <= 0) } -print "Press a key to confirm..."; -$input = trim(fgets(STDIN)); print "Hit Enter to continue or CTRL+C to stop...\n"; $input = trim(fgets(STDIN)); diff --git a/scripts/user/sync_groups_ldap2dolibarr.php b/scripts/user/sync_groups_ldap2dolibarr.php index fa29e4465c0..3170714124b 100755 --- a/scripts/user/sync_groups_ldap2dolibarr.php +++ b/scripts/user/sync_groups_ldap2dolibarr.php @@ -70,18 +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]; - -print "***** $script_file ($version) *****\n"; 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 @@ -103,8 +104,7 @@ print "----- Options:\n"; print "commitiferror=".$forcecommit."\n"; print "Mapped LDAP fields=".join(',',$required_fields)."\n"; print "\n"; -print "Press a key to confirm..."; -$input = trim(fgets(STDIN)); + print "Hit Enter to continue or CTRL+C to stop...\n"; $input = trim(fgets(STDIN)); diff --git a/scripts/user/sync_users_ldap2dolibarr.php b/scripts/user/sync_users_ldap2dolibarr.php index a1237b999cb..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,18 +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]; - -print "***** $script_file ($version) *****\n"; - 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 @@ -114,10 +114,10 @@ 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"; -print "Press a key to confirm..."; -$input = trim(fgets(STDIN)); + print "Hit Enter to continue or CTRL+C to stop...\n"; $input = trim(fgets(STDIN)); @@ -182,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) {