summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2013-07-28 19:53:24 -0400
committerDavid Rothstein <drothstein@gmail.com>2013-07-28 19:53:24 -0400
commit7c67fb6784e302eae70cc5fa79036b62769a8308 (patch)
tree5a93f1e7a54b196ffc26bb5cda8888625854ab3d /modules
parentdc7f0cdbe24517d127379900899de4a5b31ebd70 (diff)
downloadbrdo-7c67fb6784e302eae70cc5fa79036b62769a8308.tar.gz
brdo-7c67fb6784e302eae70cc5fa79036b62769a8308.tar.bz2
Issue #1034828 by Steven Jones, Bladedu, brunodbo | Rob C: Fixed 'No active batch' error after user cancelling own account.
Diffstat (limited to 'modules')
-rw-r--r--modules/user/user.module27
-rw-r--r--modules/user/user.test16
2 files changed, 32 insertions, 11 deletions
diff --git a/modules/user/user.module b/modules/user/user.module
index 06233fcdf..1b4f86988 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -2419,6 +2419,14 @@ function user_cancel($edit, $uid, $method) {
array('_user_cancel', array($edit, $account, $method)),
),
);
+
+ // After cancelling account, ensure that user is logged out.
+ if ($account->uid == $user->uid) {
+ // Batch API stores data in the session, so use the finished operation to
+ // manipulate the current user's session id.
+ $batch['finished'] = '_user_cancel_session_regenerate';
+ }
+
batch_set($batch);
// Batch processing is either handled via Form API or has to be invoked
@@ -2461,10 +2469,12 @@ function _user_cancel($edit, $account, $method) {
break;
}
- // After cancelling account, ensure that user is logged out.
+ // After cancelling account, ensure that user is logged out. We can't destroy
+ // their session though, as we might have information in it, and we can't
+ // regenerate it because batch API uses the session ID, we will regenerate it
+ // in _user_cancel_session_regenerate().
if ($account->uid == $user->uid) {
- // Destroy the current session, and reset $user to the anonymous user.
- session_destroy();
+ $user = drupal_anonymous_user();
}
// Clear the cache for anonymous users.
@@ -2472,6 +2482,17 @@ function _user_cancel($edit, $account, $method) {
}
/**
+ * Finished batch processing callback for cancelling a user account.
+ *
+ * @see user_cancel()
+ */
+function _user_cancel_session_regenerate() {
+ // Regenerate the users session instead of calling session_destroy() as we
+ // want to preserve any messages that might have been set.
+ drupal_session_regenerate();
+}
+
+/**
* Delete a user.
*
* @param $uid
diff --git a/modules/user/user.test b/modules/user/user.test
index 68e642923..3e533abf8 100644
--- a/modules/user/user.test
+++ b/modules/user/user.test
@@ -661,8 +661,8 @@ class UserCancelTestCase extends DrupalWebTestCase {
$account = user_load($account->uid, TRUE);
$this->assertTrue($account->status == 0, 'User has been blocked.');
- // Confirm user is logged out.
- $this->assertNoText($account->name, 'Logged out.');
+ // Confirm that the confirmation message made it through to the end user.
+ $this->assertRaw(t('%name has been disabled.', array('%name' => $account->name)), "Confirmation message displayed to user.");
}
/**
@@ -705,8 +705,8 @@ class UserCancelTestCase extends DrupalWebTestCase {
$test_node = node_load($node->nid, $node->vid, TRUE);
$this->assertTrue($test_node->status == 0, 'Node revision of the user has been unpublished.');
- // Confirm user is logged out.
- $this->assertNoText($account->name, 'Logged out.');
+ // Confirm that the confirmation message made it through to the end user.
+ $this->assertRaw(t('%name has been disabled.', array('%name' => $account->name)), "Confirmation message displayed to user.");
}
/**
@@ -756,8 +756,8 @@ class UserCancelTestCase extends DrupalWebTestCase {
$test_node = node_load($revision_node->nid, NULL, TRUE);
$this->assertTrue(($test_node->uid != 0 && $test_node->status == 1), "Current revision of the user's node was not attributed to anonymous user.");
- // Confirm that user is logged out.
- $this->assertNoText($account->name, 'Logged out.');
+ // Confirm that the confirmation message made it through to the end user.
+ $this->assertRaw(t('%name has been deleted.', array('%name' => $account->name)), "Confirmation message displayed to user.");
}
/**
@@ -818,8 +818,8 @@ class UserCancelTestCase extends DrupalWebTestCase {
$this->assertTrue(node_load($revision_node->nid, NULL, TRUE), "Current revision of the user's node was not deleted.");
$this->assertFalse(comment_load($comment->cid), 'Comment of the user has been deleted.');
- // Confirm that user is logged out.
- $this->assertNoText($account->name, 'Logged out.');
+ // Confirm that the confirmation message made it through to the end user.
+ $this->assertRaw(t('%name has been deleted.', array('%name' => $account->name)), "Confirmation message displayed to user.");
}
/**