Projet

Général

Profil

Paste
Télécharger (2,53 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_servers / ldap_servers.drush.inc @ be58a50c

1
<?php
2

    
3
/**
4
 * @file
5
 *   LDAP module drush integration.
6
 */
7

    
8
/**
9
 * Implements hook_drush_command().
10
 *
11
 * @return
12
 *   An associative array describing your command(s).
13
 *
14
 * @see drush_parse_command()
15
 */
16
function ldap_servers_drush_command() {
17
  $items['ldap-servers-set-password'] = array(
18
    'description' => 'Set the password of an otherwise already configured LDAP server.',
19
    'aliases' => array('lssp'),
20
    'arguments' => array(
21
      'ldap_sid' => 'The configured LDAP server ID.'
22
    ),
23
    'options' => array(
24
      'password' => 'The password to set for the server.'
25
    ),
26
    'examples' => array(
27
      'drush lssp LDAP_SERVER_ID --password="PASSWORD"' => 'Sets the password for LDAP_SERVER_ID. Replace LDAP_SERVER_ID with the "Machine name for this configuration." of
28
        the server found at /admin/config/people/ldap/servers, and replace PASSWORD with your password.',
29
    ),
30
  );
31
  return $items;
32
}
33

    
34
/**
35
 * Callback for the ldap-servers-set-password command.
36
 *
37
 * @param string $ldap_sid The server ID for which to set the password.
38
 * @option string --password Used to provide the password via an option in the Drush command.
39
 *
40
 * @return
41
 *   Error or success message.
42
 */
43
function drush_ldap_servers_set_password($ldap_sid = NULL) {
44
  // Check for the argument.
45
  if (!isset($ldap_sid)) {
46
    return drush_set_error(t('The server ID was not included as an argument. Use the "Machine name for this server configuration." found on the edit screen for that server.'));
47
  }
48
  // Instantiate the server configuration with the provided sid.
49
  ldap_servers_module_load_include('php', 'ldap_servers', 'LdapServerAdmin.class');
50
  $ldap_server = new LdapServerAdmin($ldap_sid);
51
  if (isset($ldap_server)) {
52
    // Retrieves the password from the --password option set in the drush command.
53
    $ldap_server->bindpw = drush_get_option('password');
54
    if (!isset($ldap_server->bindpw)) {
55
      return drupal_set_message(dt('No password was provided for @ldap_sid. A password has not been set.', array('@ldap_sid' => $ldap_sid)));
56
    }
57
    // Save the server configuration with the password.
58
    $ldap_server->save('edit');
59
    // Notify of success.
60
    return drupal_set_message(dt('Password for @ldap_sid has been set.', array('@ldap_sid' => $ldap_sid)));
61
  }
62
  // Provided server ID does not match any of the existing server IDs.
63
  return drush_set_error(dt('@ldap_sid does not match the server ID of any configured servers.  Use the "Machine name for this server configuration." found on the edit screen for that server.',
64
    array('@ldap_sid' => $ldap_sid)));
65
}