27if (!defined(
'NOSESSION')) {
28 define(
'NOSESSION',
'1');
31$sapi_type = php_sapi_name();
32$script_file = basename(__FILE__);
36if (substr($sapi_type, 0, 3) ==
'cgi') {
37 echo
"Error: You are using PHP for CGI. To execute ".$script_file.
" from command line, you must use PHP for CLI mode.\n";
41require_once $path.
"../../htdocs/master.inc.php";
42require_once DOL_DOCUMENT_ROOT.
"/contact/class/contact.class.php";
43require_once DOL_DOCUMENT_ROOT.
"/user/class/user.class.php";
44require_once DOL_DOCUMENT_ROOT.
"/core/class/ldap.class.php";
47$version = DOL_VERSION;
51$hookmanager->initHooks(array(
'cli'));
59print
"***** ".$script_file.
" (".$version.
") pid=".
dol_getmypid().
" *****\n";
60dol_syslog($script_file.
" launched with arg ".join(
',', $argv));
62if (!isset($argv[1]) || !$argv[1]) {
63 print
"Usage: $script_file now [-y]\n";
67foreach ($argv as $key => $val) {
68 if (preg_match(
'/-y$/', $val, $reg)) {
75if (!empty($dolibarr_main_db_readonly)) {
76 print
"Error: instance in read-only mode\n";
80print
"Mails sending disabled (useless in batch mode)\n";
81$conf->global->MAIN_DISABLE_ALL_MAILS = 1;
83print
"----- Synchronize all records from Dolibarr database:\n";
84print
"type=".$conf->db->type.
"\n";
85print
"host=".$conf->db->host.
"\n";
86print
"port=".$conf->db->port.
"\n";
87print
"login=".$conf->db->user.
"\n";
89print
"database=".$conf->db->name.
"\n";
91print
"----- To LDAP database:\n";
100 print
"Press a key to confirm...\n";
101 $input = trim(fgets(STDIN));
102 print
"Warning, this operation may result in data loss if it failed.\n";
103 print
"Be sure to have a backup of your LDAP database (With OpenLDAP: slapcat > save.ldif).\n";
104 print
"Hit Enter to continue or CTRL+C to stop...\n";
105 $input = trim(fgets(STDIN));
115$sql =
"SELECT rowid";
116$sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople";
118$resql = $db->query($sql);
120 $num = $db->num_rows($resql);
124 $ldap->connectBind();
129 $obj = $db->fetch_object($resql);
132 $contact->id = $obj->rowid;
133 $contact->fetch($contact->id);
135 print $langs->trans(
"UpdateContact").
" rowid=".$contact->id.
" ".$contact->getFullName($langs);
137 $oldobject = $contact;
139 $oldinfo = $oldobject->_load_ldap_info();
140 $olddn = $oldobject->_load_ldap_dn($oldinfo);
142 $info = $contact->_load_ldap_info();
143 $dn = $contact->_load_ldap_dn($info);
145 $result = $ldap->add($dn, $info, $user);
146 $result = $ldap->update($dn, $info, $user, $olddn);
148 print
" - ".$langs->trans(
"OK");
151 print
" - ".$langs->trans(
"KO").
' - '.$ldap->error;
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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.