Commit 38168470 authored by catch's avatar catch

Issue #1807266 by cam8001, barbun: Convert user_cancel_method() variable to CMI system.

parent 1fd08e58
......@@ -138,7 +138,7 @@ function testDeleteNode() {
function testDeleteUser() {
config('statistics.settings')->set('access_log.enabled', 1)->save();
variable_set('user_cancel_method', 'user_cancel_delete');
config('user.settings')->set('cancel_method', 'user_cancel_delete')->save();
$this->drupalLogout($this->privileged_user);
$account = $this->drupalCreateUser(array('access content', 'cancel account'));
$this->drupalLogin($account);
......
......@@ -28,9 +28,9 @@ public function setUp() {
}
/**
* Tests upgrade of system variables.
* Tests upgrade of variables to config.
*/
public function testSystemVariableUpgrade() {
public function testVariableUpgrade() {
$this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
// Verify that variables were properly upgraded.
......@@ -75,6 +75,10 @@ public function testSystemVariableUpgrade() {
'page.front' => 'node',
);
$expected_config['user.settings'] = array(
'cancel_method' => 'user_cancel_reassign',
);
foreach ($expected_config as $file => $values) {
$config = config($file);
$this->verbose(print_r($config->get(), TRUE));
......
......@@ -91,6 +91,10 @@
'name' => 'site_slogan',
'value' => 's:31:"CMI makes Drupal 8 drush cex -y";',
))
->values(array(
'name' => 'user_cancel_method',
'value' => 's:20:"user_cancel_reassign"',
))
->execute();
db_update('variable')
......
......@@ -12,3 +12,4 @@ notify:
register_pending_approval: '1'
register: visitors
signatures: '0'
cancel_method: user_cancel_block
......@@ -35,7 +35,7 @@ public static function getInfo() {
* Attempt to cancel account without permission.
*/
function testUserCancelWithoutPermission() {
variable_set('user_cancel_method', 'user_cancel_reassign');
config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
// Create a user.
$account = $this->drupalCreateUser(array());
......@@ -105,7 +105,7 @@ function testUserCancelUid1() {
* Attempt invalid account cancellations.
*/
function testUserCancelInvalid() {
variable_set('user_cancel_method', 'user_cancel_reassign');
config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
// Create a user.
$account = $this->drupalCreateUser(array('cancel account'));
......@@ -147,7 +147,7 @@ function testUserCancelInvalid() {
* Disable account and keep all content.
*/
function testUserBlock() {
variable_set('user_cancel_method', 'user_cancel_block');
config('user.settings')->set('cancel_method', 'user_cancel_block')->save();
// Create a user.
$web_user = $this->drupalCreateUser(array('cancel account'));
......@@ -182,7 +182,7 @@ function testUserBlock() {
* Disable account and unpublish all content.
*/
function testUserBlockUnpublish() {
variable_set('user_cancel_method', 'user_cancel_block_unpublish');
config('user.settings')->set('cancel_method', 'user_cancel_block_unpublish')->save();
// Create a user.
$account = $this->drupalCreateUser(array('cancel account'));
......@@ -226,7 +226,7 @@ function testUserBlockUnpublish() {
* Delete account and anonymize all content.
*/
function testUserAnonymize() {
variable_set('user_cancel_method', 'user_cancel_reassign');
config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
// Create a user.
$account = $this->drupalCreateUser(array('cancel account'));
......@@ -277,7 +277,7 @@ function testUserAnonymize() {
* Delete account and remove all content.
*/
function testUserDelete() {
variable_set('user_cancel_method', 'user_cancel_delete');
config('user.settings')->set('cancel_method', 'user_cancel_delete')->save();
// Create a user.
$account = $this->drupalCreateUser(array('cancel account', 'post comments', 'skip comment approval'));
......@@ -339,7 +339,7 @@ function testUserDelete() {
* Create an administrative user and delete another user.
*/
function testUserCancelByAdmin() {
variable_set('user_cancel_method', 'user_cancel_reassign');
config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
// Create a regular user.
$account = $this->drupalCreateUser(array());
......@@ -364,7 +364,7 @@ function testUserCancelByAdmin() {
* Tests deletion of a user account without an e-mail address.
*/
function testUserWithoutEmailCancelByAdmin() {
variable_set('user_cancel_method', 'user_cancel_reassign');
config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
// Create a regular user.
$account = $this->drupalCreateUser(array());
......@@ -392,7 +392,7 @@ function testUserWithoutEmailCancelByAdmin() {
* Create an administrative user and mass-delete other users.
*/
function testMassUserCancelByAdmin() {
variable_set('user_cancel_method', 'user_cancel_reassign');
config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
// Enable account cancellation notification.
variable_set('user_mail_status_canceled_notify', TRUE);
......
......@@ -332,6 +332,7 @@ function user_admin_settings($form, &$form_state) {
$form['registration_cancellation']['user_cancel_method'] = array(
'#type' => 'item',
'#title' => t('When cancelling a user account'),
'#default_value' => $config->get('cancel_method'),
'#description' => t('Users with the %select-cancel-method or %administer-users <a href="@permissions-url">permissions</a> can override this default method.', array('%select-cancel-method' => t('Select method for cancelling account'), '%administer-users' => t('Administer users'), '@permissions-url' => url('admin/people/permissions'))),
);
$form['registration_cancellation']['user_cancel_method'] += user_cancel_methods();
......@@ -665,6 +666,7 @@ function user_admin_settings_submit($form, &$form_state) {
->set('register', $form_state['values']['user_register'])
->set('verify_mail', $form_state['values']['user_email_verification'])
->set('signatures', $form_state['values']['user_signatures'])
->set('cancel_method', $form_state['values']['user_cancel_method'])
->set('notify.status_activated', $form_state['values']['user_mail_status_activated_notify'])
->set('notify.status_blocked', $form_state['values']['user_mail_status_blocked_notify'])
->set('notify.status_canceled', $form_state['values']['user_mail_status_canceled_notify'])
......
......@@ -491,6 +491,7 @@ function user_update_8004() {
'user_admin_role' => 'admin_role',
'user_register' => 'register',
'user_signatures' => 'signatures',
'user_cancel_method' => 'cancel_method',
'user_mail_status_activated_notify' => 'notify.status_activated',
'user_mail_status_blocked_notify' => 'notify.status_blocked',
'user_mail_status_cancelled_notify' => 'notify.status_cancelled',
......@@ -503,12 +504,26 @@ function user_update_8004() {
'1' => 'visitors',
'2' => 'visitors_admin_approval',
);
$config = config('user.settings');
$user_register = $config->get('register');
$user_cancel_method = $config->get('cancel_method');
if (is_numeric($user_register) && isset($map[$user_register])) {
$config->set('register', $map[$user_register])->save();
}
// Convert user.settings:cancel_method numeric value to text value.
$cancel_map = array(
'0' => 'user_cancel_block',
'1' => 'user_cancel_block_unpublish',
'2' => 'user_cancel_block_reassign',
'3' => 'user_cancel_block_delete',
);
if (is_numeric($user_cancel_method) && isset($cancel_map[$user_cancel_method])) {
$config->set('cancel_method', $$cancel_map[$user_cancel_method])->save();
}
}
/**
......
......@@ -230,7 +230,6 @@ function user_cancel_confirm_form($form, &$form_state, $account) {
$form['_account'] = array('#type' => 'value', '#value' => $account);
// Display account cancellation method selection, if allowed.
$default_method = variable_get('user_cancel_method', 'user_cancel_block');
$admin_access = user_access('administer users');
$can_select_method = $admin_access || user_access('select account cancellation method');
$form['user_cancel_method'] = array(
......@@ -365,14 +364,13 @@ function user_cancel_methods() {
drupal_alter('user_cancel_methods', $methods);
// Turn all methods into real form elements.
$default_method = variable_get('user_cancel_method', 'user_cancel_block');
foreach ($methods as $name => $method) {
$form[$name] = array(
'#type' => 'radio',
'#title' => $method['title'],
'#description' => (isset($method['description']) ? $method['description'] : NULL),
'#return_value' => $name,
'#default_value' => $default_method,
'#default_value' => config('user.settings')->get('cancel_method'),
'#parents' => array('user_cancel_method'),
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment