dolibarr 19.0.3
sync_members_types_dolibarr2ldap.php
Go to the documentation of this file.
1#!/usr/bin/env php
2<?php
28if (!defined('NOSESSION')) {
29 define('NOSESSION', '1');
30}
31
32$sapi_type = php_sapi_name();
33$script_file = basename(__FILE__);
34$path = __DIR__.'/';
35
36// Test if batch mode
37if (substr($sapi_type, 0, 3) == 'cgi') {
38 echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
39 exit(-1);
40}
41
42if (!isset($argv[1]) || !$argv[1]) {
43 print "Usage: ".$script_file." now\n";
44 exit(-1);
45}
46
47$now = $argv[1];
48
49require_once $path."../../htdocs/master.inc.php";
50require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
51require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php";
52
53// Global variables
54$version = constant('DOL_VERSION');
55$error = 0;
56
57/*
58 * Main
59 */
60
61@set_time_limit(0);
62print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
63dol_syslog($script_file." launched with arg ".join(',', $argv));
64
65/*
66 * if (getDolGlobalString('LDAP_SYNCHRO_ACTIVE')) {
67 * print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
68 * exit(-1);
69 * }
70 */
71
72if (!empty($dolibarr_main_db_readonly)) {
73 print "Error: instance in read-onyl mode\n";
74 exit(-1);
75}
76
77
78$sql = "SELECT rowid";
79$sql .= " FROM ".MAIN_DB_PREFIX."adherent_type";
80
81$resql = $db->query($sql);
82if ($resql) {
83 $num = $db->num_rows($resql);
84 $i = 0;
85
86 $ldap = new Ldap();
87 $result = $ldap->connect_bind();
88
89 if ($result > 0) {
90 while ($i < $num) {
91 $ldap->error = "";
92
93 $obj = $db->fetch_object($resql);
94
95 $membertype = new AdherentType($db);
96 $membertype->id = $obj->rowid;
97 $membertype->fetch($membertype->id);
98
99 print $langs->trans("UpdateMemberType")." rowid=".$membertype->id." ".$membertype->label;
100
101 $oldobject = $membertype;
102
103 $oldinfo = $membertype->_load_ldap_info();
104 $olddn = $membertype->_load_ldap_dn($oldinfo);
105
106 $info = $membertype->_load_ldap_info();
107 $dn = $membertype->_load_ldap_dn($info);
108
109 $result = $ldap->add($dn, $info, $user); // Wil fail if already exists
110 $result = $ldap->update($dn, $info, $user, $olddn);
111 if ($result > 0) {
112 print " - ".$langs->trans("OK");
113 } else {
114 $error++;
115 print " - ".$langs->trans("KO").' - '.$ldap->error;
116 }
117 print "\n";
118
119 $i++;
120 }
121
122 $ldap->unbind();
123 } else {
124 print $ldap->error;
125 }
126} else {
127 dol_print_error($db);
128}
129
130exit($error);
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='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.