API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21fo...

The code shown in that page still uses Drupal 6 placeholders for the query string. I am referring to this line, where %d is used as placeholder.

$result = db_query_range("SELECT nid FROM {node} WHERE nid > %d ORDER BY nid ASC", $context['sandbox']['current_node'], 0, $limit);

The next line even calls a function (db_fetch_object()) that doesn't exist anymore in Drupal 8.

while ($row = db_fetch_array($result)) {
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kiamlaluno created an issue. See original summary.

apaderno’s picture

Title: callback_batch_operation() code still uses a Drupal 6 query placeholder and a Drupal 6 function » callback_batch_operation() code still contains Drupal 6 code

I am changing the title, since the arguments for db_query_range() are in the wrong order: They should be as in db_query_range($query, $from, $count, array $args = array(), array $options = array()), but the code is putting $from and $count after the query placeholder array.

apaderno’s picture

Status: Active » Needs review
FileSize
871 bytes

I am attaching the patch I am suggesting.

apaderno’s picture

The patch is also required for Drupal 7, for the same errors in the code.

jhodgdon’s picture

Status: Needs review » Needs work

This looks good for Drupal 7 (and we should create a child issue for Drupal 7). However, in Drupal 8 db_query_range() is deprecated, so we should probably rewrite the code so it doesn't use it?

Vinay15’s picture

Assigned: Unassigned » Vinay15
Vinay15’s picture

Status: Needs work » Needs review
FileSize
888 bytes
708 bytes

I have removed db_query_range() and tried to update the patch in #3.

jhodgdon’s picture

This looks right to me, thanks!

While we are at it, should we also fix a few lines above:

$context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchField();
}

db_query() is also deprecated.

Vinay15’s picture

I have updated both deprecated functions db_query() and db_query_range() in this patch.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks good now, thanks!

  • xjm committed 2486ccd on 8.2.x
    Issue #2729171 by Vinay15, kiamlaluno, jhodgdon:...

  • xjm committed f6df84c on 8.1.x
    Issue #2729171 by Vinay15, kiamlaluno, jhodgdon:...
xjm’s picture

Version: 8.2.x-dev » 8.1.x-dev
Status: Reviewed & tested by the community » Fixed

Good catch!

Committed to 8.2.x and cherry-picked to 8.1.x. Thanks!

xjm’s picture

Corollary: The batch API has not received a significant update since Drupal 6. :P

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.