다음 코드를 사용합니다.
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'user')
->propertyCondition('status', 0)
// Avoid loading the anonymous user.
->propertyCondition('uid', 0, '<>')
// Comment out the next line if you need to enable also the super user.
->propertyCondition('uid', 1, '<>')
->execute();
if (isset($result['user'])) {
// Disable the email sent when the user account is enabled.
// Use this code if you don't use the code marked with (1).
// $old_value = variable_get('user_mail_status_activated_notify', TRUE);
// variable_set('user_mail_status_activated_notify', FALSE);
$uids = array_keys($result['user']);
$users = entity_load('user', $uids);
foreach ($users as $uid => $user) {
$user->status = 1;
$original = clone $user; // (1)
$user->original = $original; // (1)
user_save($user);
}
// Restore the value of the Drupal variable.
// Use this code if you don't use the code marked with (1).
// variable_set('user_mail_status_activated_notify', $old_value);
}
- 이 코드는 활성화되지 않은 계정 만로드합니다. 이미 활성화 된 계정을로드하는 것은 쓸모가 없습니다.
- 이 코드는 익명 사용자 계정 (실제 계정이 아님)을로드하지 않도록합니다.
Clive는 user_save () 를 사용 하면 Drupal이 활성화 된 사용자에게 이메일을 보낼 수 있다고 말합니다 . 함수에서 사용 된 코드는 다음과 같습니다.
// Send emails after we have the new user object.
if ($account->status != $account->original->status) {
// The user's status is changing; conditionally send notification email.
$op = $account->status == 1 ? 'status_activated' : 'status_blocked';
_user_mail_notify($op, $account);
}
내 코드를 사용하면 조건 $account->status != $account->original->status이 확인되지 않고 이메일이 전송되지 않습니다. 또는 코드에 표시된 대로을 FALSE호출 하기 전에 Drupal 변수 "user_mail_status_activated_notify"의 값을 설정할 수 user_save()있습니다. 해당 Drupal 변수의 값을 변경하면 전역 적으로 영향을 미치며 다른 코드가 값을로 변경하면 작동하지 않습니다 TRUE. 내 코드와 함께 저장되는 사용자 개체에 대해 호출 이 사용자에게 전자 메일을 효과적으로 보내지 않도록 $user->original하려면 $user개체 의 복사본으로 설정 하는 것이 유일한 방법 user_save()입니다.