Skip to content

Commit

Permalink
New: More robust LDAP synchronizing
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Aug 11, 2009
1 parent 9382e5b commit 7ef1ef9
Show file tree
Hide file tree
Showing 19 changed files with 229 additions and 104 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -32,6 +32,7 @@ For users:
- New: Add log tab on emailing module.
- New: Minor enhancements in look themes.
- New: Add option to hide help in menu.
- New: Added a "force LDAP synchronize" on member and contact cards.
- Fix: "Now" link works when date popup is not used.
- Fix: Debug seriously the email notification module.
- Fix: Error Call to a member function trans when refusing a supplier order.
Expand All @@ -44,6 +45,7 @@ For users:
new product lines.
- Fix: CC and BCC in emails was not used if using SMTPS handler.
- Fix: Last character was lost when text end with n or r.
- Fix: LDAP synchronization is now more robust.

For translators:
- Update some language files.
Expand All @@ -61,6 +63,8 @@ For developers:
- Better W3C standard.
- Can add init data when enabling a module.
- Can fix some corruptions in database by calling the update page with action=repair
- Log files contains more information (PHP_SELD added and OS user used for log of
command lines scripts)


***** Changelog for 2.6 compared to 2.5 *****
Expand Down
6 changes: 3 additions & 3 deletions htdocs/adherents/adherent.class.php
Expand Up @@ -96,12 +96,12 @@ class Adherent extends CommonObject
// var $public;
var $array_options;

var $oldcopy; // To contains a clone of this when we need to save old properties of object


/**
\brief Adherent
\param DB base de donnees
\param id id de l'adherent
* \brief Adherent
* \param DB base de donnees
*/
function Adherent($DB)
{
Expand Down
2 changes: 2 additions & 0 deletions htdocs/adherents/fiche.php
Expand Up @@ -209,6 +209,8 @@
// Create new object
if ($result > 0)
{
$adh->oldcopy=dol_clone($adh);

// Modifie valeures
$adh->prenom = trim($_POST["prenom"]);
$adh->nom = trim($_POST["nom"]);
Expand Down
58 changes: 52 additions & 6 deletions htdocs/adherents/ldap.php
Expand Up @@ -18,11 +18,11 @@
*/

/**
\file htdocs/adherents/ldap.php
\ingroup ldap
\brief Page fiche LDAP adherent
\version $Id$
*/
* \file htdocs/adherents/ldap.php
* \ingroup ldap
* \brief Page fiche LDAP adherent
* \version $Id$
*/

require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php");
Expand Down Expand Up @@ -64,7 +64,36 @@
}


/*
* Actions
*/

if ($_GET["action"] == 'dolibarr2ldap')
{
$message="";

$db->begin();

$ldap=new Ldap();
$result=$ldap->connect_bind();

$info=$adh->_load_ldap_info();
$dn=$adh->_load_ldap_dn($info);
$olddn=$dn; // We can say that old dn = dn as we force synchro

$result=$ldap->update($dn,$info,$user,$olddn);

if ($result >= 0)
{
$message.='<div class="ok">'.$langs->trans("MemberSynchronized").'</div>';
$db->commit();
}
else
{
$message.='<div class="error">'.$ldap->error.'</div>';
$db->rollback();
}
}



Expand Down Expand Up @@ -138,7 +167,24 @@

print '</div>';

print '<br>';

if ($message) { print $message; }


/*
* Barre d'actions
*/

print '<div class="tabsAction">';

if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$adh->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
}

print "</div>\n";

if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') print "<br>\n";



Expand Down
6 changes: 4 additions & 2 deletions htdocs/contact.class.php
Expand Up @@ -65,6 +65,8 @@ class Contact extends CommonObject
var $user_id;
var $user_login;

var $oldcopy; // To contains a clone of this when we need to save old properties of object


/**
* \brief Constructeur de l'objet contact
Expand Down Expand Up @@ -375,7 +377,7 @@ function update_perso($id, $user=0)
/*
* \brief Charge l'objet contact
* \param id id du contact
* \param user Utilisateur lie au contact pour une alerte
* \param user Utilisateur abonnes aux alertes si on veut les alertes de ce contact
* \return int -1 if KO, 0 if OK but not found, 1 if OK
*/
function fetch($id, $user=0)
Expand Down Expand Up @@ -442,7 +444,7 @@ function fetch($id, $user=0)
$this->user_id = $obj->user_id;
$this->user_login = $obj->user_login;

// Recherche le user Dolibarr li� � ce contact
// Recherche le user Dolibarr lie a ce contact
$sql = "SELECT u.rowid ";
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE u.fk_socpeople = ". $this->id;
Expand Down
3 changes: 3 additions & 0 deletions htdocs/contact/fiche.php
Expand Up @@ -144,6 +144,9 @@
if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
{
$contact = new Contact($db);
$contact->fetch($_POST["contactid"]);

$contact->oldcopy=dol_clone($contact);

$contact->old_name = $_POST["old_name"];
$contact->old_firstname = $_POST["old_firstname"];
Expand Down
76 changes: 62 additions & 14 deletions htdocs/contact/ldap.php
Expand Up @@ -18,11 +18,11 @@
*/

/**
\file htdocs/contact/ldap.php
\ingroup ldap
\brief Page fiche LDAP contact
\version $Id$
*/
* \file htdocs/contact/ldap.php
* \ingroup ldap
* \brief Page fiche LDAP contact
* \version $Id$
*/

require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/contact.class.php");
Expand All @@ -43,11 +43,41 @@
$contact->fetch($_GET["id"], $user);


/*
* Actions
*/

if ($_GET["action"] == 'dolibarr2ldap')
{
$message="";

$db->begin();

$ldap=new Ldap();
$result=$ldap->connect_bind();

$info=$contact->_load_ldap_info();
$dn=$contact->_load_ldap_dn($info);
$olddn=$dn; // We can say that old dn = dn as we force synchro

$result=$ldap->update($dn,$info,$user,$olddn);

if ($result >= 0)
{
$message.='<div class="ok">'.$langs->trans("ContactSynchronized").'</div>';
$db->commit();
}
else
{
$message.='<div class="error">'.$ldap->error.'</div>';
$db->rollback();
}
}


/*
* View
*/
* View
*/

llxHeader();

Expand All @@ -72,16 +102,16 @@
// Company
if ($contact->socid > 0)
{
$objsoc = new Societe($db);
$objsoc->fetch($contact->socid);
$objsoc = new Societe($db);
$objsoc->fetch($contact->socid);

print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
}
else
{
print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">';
print $langs->trans("ContactNotLinkedToCompany");
print '</td></tr>';
print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">';
print $langs->trans("ContactNotLinkedToCompany");
print '</td></tr>';
}

// Civility
Expand All @@ -104,7 +134,25 @@

print '</div>';

print '<br>';

if ($message) { print $message; }


/*
* Barre d'actions
*/

print '<div class="tabsAction">';

if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$contact->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
}

print "</div>\n";

if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') print "<br>\n";



// Affichage attributs LDAP
Expand Down
24 changes: 8 additions & 16 deletions htdocs/includes/triggers/interface_modLdap_Ldapsynchro.class.php
Expand Up @@ -135,10 +135,8 @@ function run_trigger($action,$object,$user,$langs,$conf)
$ldap=new Ldap();
$ldap->connect_bind();

$oldobject=$object; // TODO Get oldobject

$oldinfo=$oldobject->_load_ldap_info();
$olddn=$oldobject->_load_ldap_dn($oldinfo);
$oldinfo=$object->oldcopy->_load_ldap_info();
$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);

$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
Expand Down Expand Up @@ -205,10 +203,8 @@ function run_trigger($action,$object,$user,$langs,$conf)
$ldap=new Ldap();
$ldap->connect_bind();

$oldobject=$object; // TODO Get oldobject

$oldinfo=$oldobject->_load_ldap_info();
$olddn=$oldobject->_load_ldap_dn($oldinfo);
$oldinfo=$object->oldcopy->_load_ldap_info();
$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);

$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
Expand Down Expand Up @@ -268,10 +264,8 @@ function run_trigger($action,$object,$user,$langs,$conf)
$ldap=new Ldap();
$ldap->connect_bind();

$oldobject=$object; // TODO Get oldobject

$oldinfo=$oldobject->_load_ldap_info();
$olddn=$oldobject->_load_ldap_dn($oldinfo);
$oldinfo=$object->oldcopy->_load_ldap_info();
$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);

$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
Expand Down Expand Up @@ -384,10 +378,8 @@ function run_trigger($action,$object,$user,$langs,$conf)
$ldap=new Ldap();
$ldap->connect_bind();

$oldobject=$object; // TODO Get oldobject

$oldinfo=$oldobject->_load_ldap_info();
$olddn=$oldobject->_load_ldap_dn($oldinfo);
$oldinfo=$object->oldcopy->_load_ldap_info();
$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);

$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
Expand Down
2 changes: 2 additions & 0 deletions htdocs/langs/en_US/ldap.lang
Expand Up @@ -24,5 +24,7 @@ LDAPFieldLastSubscriptionAmount=Last subscription amount
SynchronizeDolibarr2Ldap=Synchronize user (Dolibarr -> LDAP)
UserSynchronized=User synchronized
GroupSynchronized=Group synchronized
MemberSynchronized=Member synchronized
ContactSynchronized=Contact synchronized
ForceSynchronize=Force synchronizing Dolibarr -> LDAP
ErrorFailedToReadLDAP=Failed to read LDAP database. Check LDAP module setup and database accessibility.
2 changes: 2 additions & 0 deletions htdocs/langs/fr_FR/ldap.lang
Expand Up @@ -24,5 +24,7 @@ LDAPFieldLastSubscriptionAmount=Montant dernière adhésion
SynchronizeDolibarr2Ldap=Synchroniser utilisateur (Dolibarr -> LDAP)
UserSynchronized=Utilisateur synchronisé
GroupSynchronized=Groupe synchronisé
MemberSynchronized=Adhérent synchronisé
ContactSynchronized=Contact synchronizé
ForceSynchronize=Forcer synchro Dolibarr -> LDAP
ErrorFailedToReadLDAP=Echec de la lecture de l'annuaire LDAP. Vérifier la configuration du module LDAP et l'accessibilité de l'annuaire.
23 changes: 22 additions & 1 deletion htdocs/lib/functions.lib.php
@@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2000-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
Expand Down Expand Up @@ -35,6 +35,27 @@
if (! defined('DOL_DOCUMENT_ROOT')) define('DOL_DOCUMENT_ROOT', '..');
if (! defined('ADODB_DATE_VERSION')) include_once(DOL_DOCUMENT_ROOT."/includes/adodbtime/adodb-time.inc.php");


/**
* \brief Create a clone of instance of object (new instance with same properties)
* This function works for both PHP4 and PHP5
* \param object Object to clone
* \return date Timestamp
*/
function dol_clone($object)
{
dol_syslog("Functions.lib::dol_clone Clone object");

// We create dynamically a clone function, making a =
if (version_compare(phpversion(), '5.0') < 0 && ! function_exists('clone'))
{
eval('function clone($object){return($object);}');
}
$myclone=clone($object);
return $myclone;
}


/**
* \brief Return date for now
* \param mode 'gmt' => we return GMT timestamp,
Expand Down

0 comments on commit 7ef1ef9

Please sign in to comment.