reset.login.provision.inc 1.09 KB
Newer Older
1 2 3 4 5 6 7
<?php
/**
 * @file
 *   Provision hooks for the provision login_reset command.
 */

/**
8
 * Provision login-reset command
9 10 11 12 13 14 15 16
 *
 * These are the hooks that will be executed by the drush_invoke function
 * when generating a one-time login reset URL.
 */

/**
 * Generate a one-time login reset url
 */
17
function drush_provision_drupal_provision_login_reset() {
18
  drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL);
19 20 21
  // Drupal 7/8 take a uid as an integer and not an array
  if (drush_drupal_major_version() >= 7) {
    $account = user_load(1);
22 23
  }
  else {
24 25 26
    $account = user_load(array('uid' => 1));
  }
  if (empty($account)) {
27
    return drush_set_error('PROVISION_UNABLE_TO_LOAD_UID_1', 'Could not load the admin user with uid 1 on this site.');
28
  }
29
  $onetime = user_pass_reset_url($account) . '/login';
30 31
  // pass the login link to the front end
  drush_set_option('login_link', $onetime);
32
  drush_log(t('Login url: !onetime', array('!onetime' => $onetime)), 'success');
33 34 35 36 37 38 39 40

  if (drush_drupal_major_version() >= 7) {
    drupal_session_destroy_uid(1);
  }
  else {
    // valid for d5 and d6
    sess_destroy_uid(1);
  }
41
}