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