30if (!defined(
'NOSESSION')) {
31 define(
'NOSESSION',
'1');
34$sapi_type = php_sapi_name();
35$script_file = basename(__FILE__);
39if (substr($sapi_type, 0, 3) ==
'cgi') {
40 echo
"Error: You are using PHP for CGI. To execute ".$script_file.
" from command line, you must use PHP for CLI mode.\n";
44require_once $path.
"../../htdocs/master.inc.php";
45require_once DOL_DOCUMENT_ROOT.
'/core/lib/functionscli.lib.php';
46require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
47require_once DOL_DOCUMENT_ROOT.
"/core/class/ldap.class.php";
48require_once DOL_DOCUMENT_ROOT.
"/adherents/class/adherent_type.class.php";
57$langs->loadLangs(array(
"main",
"errors"));
60$version = constant(
'DOL_VERSION');
65$hookmanager->initHooks(array(
'cli'));
73print
"***** ".$script_file.
" (".$version.
") pid=".
dol_getmypid().
" *****\n";
74dol_syslog($script_file.
" launched with arg ".join(
',', $argv));
80$required_fields = array_unique(array_values(array_filter($required_fields,
"dolValidElementType")));
82if (!isset($argv[1])) {
84 print
"Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
88foreach ($argv as $key => $val) {
89 if ($val ==
'commitiferror') {
92 if (preg_match(
'/--server=([^\s]+)$/', $val, $reg)) {
93 $conf->global->LDAP_SERVER_HOST = $reg[1];
95 if (preg_match(
'/--excludeuser=([^\s]+)$/', $val, $reg)) {
96 $excludeuser = explode(
',', $reg[1]);
98 if (preg_match(
'/-y$/', $val, $reg)) {
103if (!empty($dolibarr_main_db_readonly)) {
104 print
"Error: instance in read-onyl mode\n";
108print
"Mails sending disabled (useless in batch mode)\n";
109$conf->global->MAIN_DISABLE_ALL_MAILS = 1;
111print
"----- Synchronize all records from LDAP database:\n";
118print
"----- To Dolibarr database:\n";
119print
"type=".$conf->db->type.
"\n";
120print
"host=".$conf->db->host.
"\n";
121print
"port=".$conf->db->port.
"\n";
122print
"login=".$conf->db->user.
"\n";
123print
"database=".$conf->db->name.
"\n";
124print
"----- Options:\n";
125print
"commitiferror=".$forcecommit.
"\n";
126print
"Mapped LDAP fields=".join(
',', $required_fields).
"\n";
130 print
"Hit Enter to continue or CTRL+C to stop...\n";
131 $input = trim(fgets(STDIN));
135 print $langs->trans(
"Error").
': '.$langs->trans(
"LDAP setup for members types not defined inside Dolibarr");
140$result = $ldap->connectBind();
142 $justthese = array();
145 $conf->global->LDAP_MEMBER_TYPE_ACTIVE = 0;
148 if (is_array($ldaprecords)) {
152 foreach ($ldaprecords as $key => $ldapgroup) {
155 $membertype->label = $ldapgroup[
getDolGlobalString(
'LDAP_MEMBER_TYPE_FIELD_FULLNAME')];
156 $membertype->description = $ldapgroup[
getDolGlobalString(
'LDAP_MEMBER_TYPE_FIELD_DESCRIPTION')];
157 $membertype->entity =
$conf->entity;
161 if ($membertype->id > 0) {
162 print $langs->transnoentities(
"MemberTypeUpdate").
' # '.$key.
': name='.$membertype->label;
163 $res = $membertype->update($user);
166 print
' --> Updated member type id='.$membertype->id.
' name='.$membertype->label;
169 print
' --> '.$res.
' '.$membertype->error;
173 print $langs->transnoentities(
"MemberTypeCreate").
' # '.$key.
': name='.$membertype->label;
174 $res = $membertype->create($user);
177 print
' --> Created member type id='.$membertype->id.
' name='.$membertype->label;
180 print
' --> '.$res.
' '.$membertype->error;
188 if (!$error || $forcecommit) {
190 print $langs->transnoentities(
"NoErrorCommitIsDone").
"\n";
192 print $langs->transnoentities(
"ErrorButCommitIsDone").
"\n";
196 print $langs->transnoentities(
"ErrorSomeErrorWereFoundRollbackIsDone", $error).
"\n";
218function dolValidElementType($element)
220 return (trim($element) !=
'');
Class to manage members type.
Class to manage LDAP features.
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...