You are here

function ldapdata_node_update in LDAP integration 6

Drupal 7 hook_node_update. Handles the case of content profile updates being written back to ldap if needed.

Parameters

Object $node:

1 call to ldapdata_node_update()
ldapdata_nodeapi in ./ldapdata.module
Implementation of hook_nodeapi().

File

./ldapdata.module, line 1095
ldapdata provides data maping against ldap server.

Code

function ldapdata_node_update($node) {
  global $_ldapdata_ldap;

  // Is this being called after the normal sync rules have been applied?
  if (isset($node->ldap_synched)) {
    return;
  }
  if (module_exists('content_profile') && is_content_profile($node->type)) {
    $account = user_load($node->uid);

    // Only care about ldap authenticated users.
    if (!isset($account->ldap_authentified)) {
      return;
    }

    // Setup the global $_ldapdata_ldap object.
    if (!_ldapdata_init($account)) {
      return;
    }
    $writeout = _ldapdata_user_update_content_profile($node, $account);
    if ($writeout) {
      $bind_info = _ldapdata_edition($account);
      if (!$_ldapdata_ldap
        ->connect($bind_info['dn'], $bind_info['pass'])) {
        watchdog('ldapdata', "User update: user %name's data could not be updated in the LDAP directory", array(
          '%name' => $account->name,
        ), WATCHDOG_NOTICE);
        return;
      }
      if (!$_ldapdata_ldap
        ->writeAttributes($account->ldap_dn, $writeout)) {
        drupal_set_message(t('The data was not written to LDAP.'), 'error');
      }
    }
    $_ldapdata_ldap
      ->disconnect();
    $node->ldap_synched = TRUE;

    // Just in case update called twice in a page.
  }
}