[turba] LDAP composed primary Key

Marco Brandizi zakmck at virgilio.it
Wed Dec 17 12:48:32 PST 2003


Hi all

I'm importing, via Turba / CSV import, in LDAP a long address list.
Since practically I don't have a primary key (all the fields are a key,
there are almost identical rows and I don't have time to check 1000
entries), I would like to use this as primary:

                   // Generates MD5 unique ID from record
                   $attrs = '';
                   foreach ( $attributes as $attr ) {
                     if ( $attrs ) $attrs .= '';
                     $attrs .= $attr;
                   }
                   $dn .= 'uid=' . md5 ( $attrs ) . ',';


i.e.: the primary key is an hash of the entire row.

But unfortunately Turba expects a list of attributes as key
specification, so that I've hacked lib/driver/ldap.php, in the following
way:

     function makeKey($attributes)
     {
         $dn = '';
         if (is_array($this->_params['dn'])) {
             foreach ($this->_params['dn'] as $param) {
/* Marco Brandizi, Oct 2003, A VERY dirty trick to support dn dynamic */
               if ( $param == 'uid' )
               {
                   // Generates MD5 unique ID from record
                   $attrs = '';
                   foreach ( $attributes as $attr ) {
                     if ( $attrs ) $attrs .= '';
                     $attrs .= $attr;
                   }
                   $dn .= 'uid=' . md5 ( $attrs ) . ',';

               }
               else
// End of Brandizi Trick
                   if (isset($attributes[$param])) {
                     $dn .= $param . '=' . $attributes[$param] . ',';
                   }
             }
         }

         $dn .= $this->_params['root'];
         return $dn;
     }

Also I need some other slight changes, see the attachement (comments 
with BRANDIZI).

Is there a cleaner way to do what I want? For example, telling Turba it
should pass a parameter to eval()? It would be nice even something less
than I'm doing, for example the simple ability to specify the key is the
concatenation of several attributes.

NOTE: About this latter point, I cannot write (in config/sources.php)
...
         'dn' => array( 'cn', 'sn' ),
...

Since the result would be "dn=cn=Marco,sn=Brandizi..." and with this
search string, LDAP expects to find a node whose father the node having 
sn=Brandizi.




More information about the turba mailing list