PHP hook_update_N()的Drupal Batch API

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP hook_update_N()的Drupal Batch API相关的知识,希望对你有一定的参考价值。

<?php
  // However, for more complex operations that may take a long time,
  // you may hook into Batch API as in the following example.
  $ret = array();

  // Update 3 users at a time to have an exclamation point after their names.
  // (They're really happy that we can do batch API in this hook!)
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['current_uid'] = 0;
    // We'll -1 to disregard the uid 0...
    $sandbox['max'] = db_result(db_query('SELECT COUNT(DISTINCT uid) FROM {users}')) - 1;
  }

  $users = db_query_range("SELECT uid, name FROM {users} WHERE uid > %d ORDER BY uid ASC", $sandbox['current_uid'], 0, 3);
  while ($user = db_fetch_object($users)) {
    $user->name .= '!';
    $ret[] = update_sql("UPDATE {users} SET name = '$user->name' WHERE uid = $user->uid");

    $sandbox['progress']++;
    $sandbox['current_uid'] = $user->uid;
  }

  $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);

  return $ret;
?>

以上是关于PHP hook_update_N()的Drupal Batch API的主要内容,如果未能解决你的问题,请参考以下文章

用于hooku updateu N()的Drupal批处理API

如何在Drupal 7中使用entity_save函数插入数据?

android 中有两个列表视图的活动

Drupal 远程代码执行漏洞(CVE-2018-7602)

Drupal 7 列出当前用户所属的有机组

如何在视图过滤器中使用标记 - Drupal 7