dolibarr  19.0.0-dev
sync_members_types_dolibarr2ldap.php
Go to the documentation of this file.
1 #!/usr/bin/env php
2 <?php
28 if (!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
37 if (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 
42 if (!isset($argv[1]) || !$argv[1]) {
43  print "Usage: ".$script_file." now\n";
44  exit(-1);
45 }
46 
47 $now = $argv[1];
48 
49 require_once $path."../../htdocs/master.inc.php";
50 require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
51 require_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);
62 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
63 dol_syslog($script_file." launched with arg ".join(',', $argv));
64 
65 /*
66  * if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
67  * {
68  * print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
69  * exit(-1);
70  * }
71  */
72 
73 if (!empty($dolibarr_main_db_readonly)) {
74  print "Error: instance in read-onyl mode\n";
75  exit(-1);
76 }
77 
78 
79 $sql = "SELECT rowid";
80 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type";
81 
82 $resql = $db->query($sql);
83 if ($resql) {
84  $num = $db->num_rows($resql);
85  $i = 0;
86 
87  $ldap = new Ldap();
88  $result = $ldap->connect_bind();
89 
90  if ($result > 0) {
91  while ($i < $num) {
92  $ldap->error = "";
93 
94  $obj = $db->fetch_object($resql);
95 
96  $membertype = new AdherentType($db);
97  $membertype->id = $obj->rowid;
98  $membertype->fetch($membertype->id);
99 
100  print $langs->trans("UpdateMemberType")." rowid=".$membertype->id." ".$membertype->label;
101 
102  $oldobject = $membertype;
103 
104  $oldinfo = $membertype->_load_ldap_info();
105  $olddn = $membertype->_load_ldap_dn($oldinfo);
106 
107  $info = $membertype->_load_ldap_info();
108  $dn = $membertype->_load_ldap_dn($info);
109 
110  $result = $ldap->add($dn, $info, $user); // Wil fail if already exists
111  $result = $ldap->update($dn, $info, $user, $olddn);
112  if ($result > 0) {
113  print " - ".$langs->trans("OK");
114  } else {
115  $error++;
116  print " - ".$langs->trans("KO").' - '.$ldap->error;
117  }
118  print "\n";
119 
120  $i++;
121  }
122 
123  $ldap->unbind();
124  } else {
125  print $ldap->error;
126  }
127 } else {
128  dol_print_error($db);
129 }
130 
131 exit($error);
Class to manage members type.
Class to manage LDAP features.
Definition: ldap.class.php:35
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
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.