Projet

Général

Profil

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

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

1 be58a50c Assos Assos
<?php
2
3
/**
4
 * @file
5 32700c57 Assos Assos
 * LDAP module drush integration.
6 be58a50c Assos Assos
 */
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 32700c57 Assos Assos
  $items['ldap-servers-set-password'] = [
18 be58a50c Assos Assos
    'description' => 'Set the password of an otherwise already configured LDAP server.',
19 32700c57 Assos Assos
    'aliases' => ['lssp'],
20
    'arguments' => [
21
      'ldap_sid' => 'The configured LDAP server ID.',
22
    ],
23
    'options' => [
24
      'password' => 'The password to set for the server.',
25
    ],
26
    'examples' => [
27 be58a50c Assos Assos
      '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 32700c57 Assos Assos
    ],
30
  ];
31 be58a50c Assos Assos
  return $items;
32
}
33
34
/**
35
 * Callback for the ldap-servers-set-password command.
36
 *
37 32700c57 Assos Assos
 * @param string $ldap_sid
38
 *   The server ID for which to set the password.
39
 *
40 be58a50c Assos Assos
 * @option string --password Used to provide the password via an option in the Drush command.
41
 *
42
 * @return
43
 *   Error or success message.
44
 */
45
function drush_ldap_servers_set_password($ldap_sid = NULL) {
46
  // Check for the argument.
47
  if (!isset($ldap_sid)) {
48
    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.'));
49
  }
50
  // Instantiate the server configuration with the provided sid.
51
  ldap_servers_module_load_include('php', 'ldap_servers', 'LdapServerAdmin.class');
52
  $ldap_server = new LdapServerAdmin($ldap_sid);
53
  if (isset($ldap_server)) {
54
    // Retrieves the password from the --password option set in the drush command.
55
    $ldap_server->bindpw = drush_get_option('password');
56
    if (!isset($ldap_server->bindpw)) {
57 32700c57 Assos Assos
      return drupal_set_message(dt('No password was provided for @ldap_sid. A password has not been set.', ['@ldap_sid' => $ldap_sid]));
58 be58a50c Assos Assos
    }
59
    // Save the server configuration with the password.
60
    $ldap_server->save('edit');
61
    // Notify of success.
62 32700c57 Assos Assos
    return drupal_set_message(dt('Password for @ldap_sid has been set.', ['@ldap_sid' => $ldap_sid]));
63 be58a50c Assos Assos
  }
64
  // Provided server ID does not match any of the existing server IDs.
65
  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.',
66 32700c57 Assos Assos
    ['@ldap_sid' => $ldap_sid]));
67 be58a50c Assos Assos
}