Esempio n. 1
0
/**
 * Act on user account cancellations.
 *
 * The user account is being canceled. Depending on the account cancellation
 * method, the module should either do nothing, unpublish content, anonymize
 * content, or delete content and data belonging to the canceled user account.
 *
 * Expensive operations should be added to the global batch with batch_set().
 *
 * @param $edit
 *   The array of form values submitted by the user.
 * @param $account
 *   The user object on which the operation is being performed.
 * @param $method
 *   The account cancellation method.
 *
 * @see user_cancel_methods()
 * @see hook_user_cancel_methods_alter()
 * @see user_cancel()
 */
function hook_user_cancel($edit, $account, $method)
{
    switch ($method) {
        case 'user_cancel_block_unpublish':
            // Unpublish nodes (current revisions).
            module_load_include('inc', 'node', 'node.admin');
            $nodes = db_select('node', 'n')->fields('n', array('nid'))->condition('uid', $account->uid)->execute()->fetchCol();
            node_mass_update($nodes, array('status' => 0));
            break;
        case 'user_cancel_reassign':
            // Anonymize nodes (current revisions).
            module_load_include('inc', 'node', 'node.admin');
            $nodes = db_select('node', 'n')->fields('n', array('nid'))->condition('uid', $account->uid)->execute()->fetchCol();
            node_mass_update($nodes, array('uid' => 0));
            // Anonymize old revisions.
            db_update('node_revision')->fields(array('uid' => 0))->condition('uid', $account->uid)->execute();
            // Clean history.
            db_delete('history')->condition('uid', $account->uid)->execute();
            break;
        case 'user_cancel_delete':
            // Delete nodes (current revisions).
            $nodes = db_select('node', 'n')->fields('n', array('nid'))->condition('uid', $account->uid)->execute()->fetchCol();
            foreach ($nodes as $nid) {
                node_delete($nid);
            }
            // Delete old revisions.
            db_delete('node_revision')->condition('uid', $account->uid)->execute();
            // Clean history.
            db_delete('history')->condition('uid', $account->uid)->execute();
            break;
    }
}
Esempio n. 2
0
/**
 * Act on user account cancellations.
 *
 * This hook is invoked from user_cancel() before a user account is canceled.
 * Depending on the account cancellation method, the module should either do
 * nothing, unpublish content, or anonymize content. See user_cancel_methods()
 * for the list of default account cancellation methods provided by User module.
 * Modules may add further methods via hook_user_cancel_methods_alter().
 *
 * This hook is NOT invoked for the 'user_cancel_delete' account cancellation
 * method. To react to that method, implement hook_ENTITY_TYPE_predelete() or
 * hook_ENTITY_TYPE_delete() for user entities instead.
 *
 * Expensive operations should be added to the global account cancellation batch
 * by using batch_set().
 *
 * @param array $edit
 *   The array of form values submitted by the user.
 * @param \Drupal\Core\Session\AccountInterface $account
 *   The user object on which the operation is being performed.
 * @param string $method
 *   The account cancellation method.
 *
 * @see user_cancel_methods()
 * @see hook_user_cancel_methods_alter()
 */
function hook_user_cancel($edit, $account, $method)
{
    switch ($method) {
        case 'user_cancel_block_unpublish':
            // Unpublish nodes (current revisions).
            module_load_include('inc', 'node', 'node.admin');
            $nodes = \Drupal::entityQuery('node')->condition('uid', $user->id())->execute();
            node_mass_update($nodes, array('status' => 0), NULL, TRUE);
            break;
        case 'user_cancel_reassign':
            // Anonymize nodes (current revisions).
            module_load_include('inc', 'node', 'node.admin');
            $nodes = \Drupal::entityQuery('node')->condition('uid', $user->id())->execute();
            node_mass_update($nodes, array('uid' => 0), NULL, TRUE);
            // Anonymize old revisions.
            db_update('node_field_revision')->fields(array('uid' => 0))->condition('uid', $account->id())->execute();
            break;
    }
}