function services_security_update_reset_users_with_password_one_op in Services 7.3
1 string reference to 'services_security_update_reset_users_with_password_one_op'
File
- ./
services.module, line 121 - Provides a generic but powerful API for web services.
Code
function services_security_update_reset_users_with_password_one_op($progress, $limit, $max, &$context) {
//Set default starting values
if (empty($context['sandbox'])) {
$context['sandbox'] = array();
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_user'] = 0;
$context['sandbox']['max'] = $limit;
}
// Required for user_check_password.
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
//Set the password we are looking for.
$password = "1";
//Fetch all users in our current range.
$result = db_select('users', 'u')
->fields('u', array(
'uid',
'pass',
))
->orderBy('u.uid', 'ASC')
->range($progress, $limit)
->execute()
->fetchAll();
// Loop through our ranged results and check their password.
foreach ($result as $row) {
$uid = $row->uid;
$pass = $row->pass;
//Setup account object, much faster than user_load
$account = new stdClass();
$account->uid = $uid;
$account->pass = $pass;
// Check the current user's password against the password.
if (user_check_password($password, $account)) {
// This means we have a matched password.
// Process the user
$updated_user = db_update('users')
->fields(array(
'pass' => "ZZZservices_security",
))
->condition('uid', $uid)
->execute();
$context['results'][] = 'Updating user uid: ' . $uid;
}
// Update our progress information.
$context['sandbox']['progress']++;
$context['sandbox']['current_user'] = $uid;
// update progress for message
$shown_progress = $progress + $limit;
// update message during each run so you know where you are in the process
$context['message'] = 'Checking user uid: ' . $uid;
}
// Inform the batch engine that we are not finished,
// and provide an estimation of the completion level we reached.
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['max'] - $context['sandbox']['progress'] <= $limit || $context['sandbox']['progress'] >= $context['sandbox']['max'];
}
}