http://api.drupal.org/api/function/node_user_cancel/7

loads node.admin.inc and calls node_mass_update()

nothing guarantees that user_cancel() will be called from a browser session, so it's quite possible the batch can fail. This is a similar issue to #89181: Use queue API for node and comment, user, node multiple deletes.

Comments

catch’s picture

Title: node_mass_delete() can't rely on a browser session » node_mass_update() can't rely on a browser session
Damien Tournoud’s picture

I opened #832572: Add a standard worker queue as a push forward to provide a way for modules to easily register long-running bulk operations.

David_Rothstein’s picture

Is this partly at least a documentation issue? Currently, user_cancel() already explains that it sets a batch but does not process it, meaning the caller can do so in a way that does not actually depend on a browser session. For example, this code successfully deletes user 2 when I run it from PHP on the command line:

define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_override_server_variables();
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
user_cancel(array(), 2, 'user_cancel_block_unpublish');
$batch =& batch_get();
$batch['progressive'] = FALSE;
batch_process();

It's true that for a massively long delete operation this could theoretically hit the PHP timeout limit, and to fix that something like #832572: Add a standard worker queue would be required, but for now we could also just document how to run this via a non-progressive batch, and mention that this can take a long time so if you are running it outside of the user interface, don't.... unless you have a sufficiently high PHP timeout limit.