Projet

Général

Profil

Révision 32700c57

Ajouté par Assos Assos il y a environ 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ldap/ldap_user/ldap_user.test_form.inc
17 17
 * @return
18 18
 *   The form structure.
19 19
 */
20

  
21 20
function ldap_user_test_form($form, &$form_state, $op = NULL) {
22 21

  
23 22
  $username = @$_SESSION['ldap_user_test_form']['testing_drupal_username'];
......
27 26
  $form['#prefix'] .= t('This form simply tests an LDAP User configuration against an individual ldap or drupal user.
28 27
    It makes no changes to the drupal or ldap user.');
29 28

  
30
  $form['testing_drupal_username'] = array(
29
  $form['testing_drupal_username'] = [
31 30
    '#type' => 'textfield',
32 31
    '#title' => t('Testing Drupal Username'),
33 32
    '#default_value' => $username,
......
35 34
    '#size' => 30,
36 35
    '#maxlength' => 255,
37 36
    '#description' => t('This is optional and used for testing this server\'s configuration against an actual username.  The user need not exist in Drupal and testing will not affect the user\'s LDAP or Drupal Account.'),
38
  );
39

  
40
  $form['test_mode'] = array(
41
      '#type' => 'radios',
42
      '#title' => t('Testing Mode'),
43
      '#required' => 0,
44
      '#default_value' => isset( $_SESSION['ldap_user_test_form']['test_mode']) ? $_SESSION['ldap_user_test_form']['test_mode'] : 'query',
45
      '#options' => array(
46
        'query' => t('Test Query.  Will not alter anything in drupal or LDAP'),
47
        'execute' => t('Execute Action.  Will perform provisioning configured for events below.  If this is selected only one action should be selected below'),
48
      ),
49
    );
37
  ];
38

  
39
  $form['test_mode'] = [
40
    '#type' => 'radios',
41
    '#title' => t('Testing Mode'),
42
    '#required' => 0,
43
    '#default_value' => isset($_SESSION['ldap_user_test_form']['test_mode']) ? $_SESSION['ldap_user_test_form']['test_mode'] : 'query',
44
    '#options' => [
45
      'query' => t('Test Query.  Will not alter anything in drupal or LDAP'),
46
      'execute' => t('Execute Action.  Will perform provisioning configured for events below.  If this is selected only one action should be selected below'),
47
    ],
48
  ];
50 49

  
51 50
  $synch_trigger_options = ldap_user_synch_triggers_key_values();
52 51

  
53
  $selected_actions = isset($_SESSION['ldap_user_test_form']['action']) ? $_SESSION['ldap_user_test_form']['action'] : array();
54
  $form['action'] = array(
55
      '#type' => 'checkboxes',
56
      '#title' => t('Actions/Event Handlers to Test'),
57
      '#required' => 0,
58
      '#default_value' => $selected_actions,
59
      '#options' => $synch_trigger_options,
60
      '#states' => array(
61
        'visible' => array(   // action to take.
62
          ':input[name="wsEnabled"]' => array('checked' => TRUE),
63
        ),
64
      ),
65
    );
66

  
67
  $form['submit'] = array(
52
  $selected_actions = isset($_SESSION['ldap_user_test_form']['action']) ? $_SESSION['ldap_user_test_form']['action'] : [];
53
  $form['action'] = [
54
    '#type' => 'checkboxes',
55
    '#title' => t('Actions/Event Handlers to Test'),
56
    '#required' => 0,
57
    '#default_value' => $selected_actions,
58
    '#options' => $synch_trigger_options,
59
    '#states' => [
60
      'visible' => [
61
        ':input[name="wsEnabled"]' => ['checked' => TRUE],
62
      ],
63
    ],
64
  ];
65

  
66
  $form['submit'] = [
68 67
    '#type' => 'submit',
69 68
    '#value' => 'test',
70 69
    '#weight' => 100,
71
  );
70
  ];
72 71

  
73 72
  return $form;
74 73
}
75 74

  
75
/**
76
 *
77
 */
76 78
function ldap_user_test_form_validate($form, &$form_state) {
77 79
  if ($form_state['values']['test_mode'] == 'execute'  &&
78
    count(array_filter($form_state['values']['action'])) > 1 ) {
80
    count(array_filter($form_state['values']['action'])) > 1) {
79 81
    form_set_error('test_mode', t('Only one action may be selected for "Execute Action" testing mode.'));
80 82
  }
81 83

  
82

  
83 84
}
84 85

  
85 86
/**
......
96 97

  
97 98
    $user_object = user_load_by_name($username);
98 99
    if ($user_object) {
99
      $user_entities = entity_load('user', array($user_object->uid));
100
      $user_entities = entity_load('user', [$user_object->uid]);
100 101
      $user_entity = $user_entities[$user_object->uid];
101 102
    }
102 103
    else {
......
104 105
    }
105 106

  
106 107
    $ldap_user_conf = ldap_user_conf();
107
    $test_servers = array();
108
    $test_servers = [];
108 109
    $user_ldap_entry = FALSE;
109 110
    if ($ldap_user_conf->drupalAcctProvisionServer) {
110 111
      $test_servers[LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER] = $ldap_user_conf->drupalAcctProvisionServer;
......
116 117
        $user_ldap_entry = ldap_servers_get_user_ldap_data($username, $ldap_user_conf->ldapEntryProvisionServer);
117 118
      }
118 119
    }
119
    $results = array();
120
    $results = [];
120 121
    $results['username'] = $username;
121 122
    $results['user object (before provisioning or synching)'] = $user_object;
122 123
    $results['user entity (before provisioning or synching)'] = $user_entity;
......
124 125
    $results['ldap_user_conf'] = $ldap_user_conf;
125 126

  
126 127
    if (is_object($user_object)) {
127
      $authmaps = db_query("SELECT aid, uid, module, authname FROM {authmap} WHERE uid = :uid", array(':uid' => $user_object->uid))->fetchAllAssoc('aid', PDO::FETCH_ASSOC);
128
      $authmaps = db_query("SELECT aid, uid, module, authname FROM {authmap} WHERE uid = :uid", [':uid' => $user_object->uid])->fetchAllAssoc('aid', PDO::FETCH_ASSOC);
128 129
    }
129 130
    else {
130 131
      $authmaps = 'No authmaps available.  Authmaps only shown if user account exists beforehand';
131
      $user_object = new stdClass(); // need for testing.
132
      // Need for testing.
133
      $user_object = new stdClass();
132 134
      $user_object->name = $username;
133 135
    }
134 136
    $results['User Authmap'] = $authmaps;
......
136 138

  
137 139
    $save = ($form_state['values']['test_mode'] == 'execute');
138 140
    $test_query = ($form_state['values']['test_mode'] != 'execute');
139
    $user_edit = array('name' => $username);
141
    $user_edit = ['name' => $username];
140 142

  
141 143
    foreach (array_filter($selected_actions) as $i => $synch_trigger) {
142 144
      $synch_trigger_description = $synch_trigger_options[$synch_trigger];
143
      foreach (array(LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) as $direction) {
145
      foreach ([LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY] as $direction) {
144 146
        if ($ldap_user_conf->provisionEnabled($direction, $synch_trigger)) {
145 147
          if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
146 148
            $discard = $ldap_user_conf->provisionDrupalAccount(NULL, $user_edit, NULL, $save);
......
161 163
        }
162 164
      }
163 165
    }
164
    // do all synchs second, in case logic of form changes to allow executing mulitple events
166
    // Do all synchs second, in case logic of form changes to allow executing mulitple events.
165 167
    foreach (array_filter($selected_actions) as $i => $synch_trigger) {
166 168
      $synch_trigger_description = $synch_trigger_options[$synch_trigger];
167
      foreach (array(LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) as $direction) {
169
      foreach ([LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY] as $direction) {
168 170
        if ($ldap_user_conf->provisionEnabled($direction, $synch_trigger)) {
169 171
          if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
170 172
            $discard = $ldap_user_conf->synchToDrupalAccount(NULL, $user_edit, NULL, $test_query);
171 173
            $results['synchToDrupalAccount method results']["context = $synch_trigger_description"]['proposed'] = $user_edit;
172 174
          }
173
          else { // to ldap
174
            $provision_result = $ldap_user_conf->synchToLdapEntry($user_object, $user_edit, array(), $test_query);
175
          // To ldap.
176
          else {
177
            $provision_result = $ldap_user_conf->synchToLdapEntry($user_object, $user_edit, [], $test_query);
175 178
            $results['synchToLdapEntry method results']["context = $synch_trigger_description"] = $provision_result;
176 179
          }
177 180
        }
......
179 182
          if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
180 183
            $results['synchToDrupalAccount method results']["context = $synch_trigger_description"] = 'Not enabled.';
181 184
          }
182
          else { // to ldap
185
          // To ldap.
186
          else {
183 187
            $results['synchToLdapEntry method results']["context = $synch_trigger_description"] = 'Not enabled.';
184 188
          }
185 189
        }
186 190
      }
187 191
    }
188 192

  
189

  
190 193
    if (function_exists('dpm')) {
191 194
      dpm($results);
192 195
    }

Formats disponibles : Unified diff