You are here

function _webform2pdf_update_7401_batch in Webform2PDF 7.4

Utility function to update all the locations that use tokens.

1 call to _webform2pdf_update_7401_batch()
webform2pdf_update_7401 in ./webform2pdf.install
Rewrite token replacement system to use D7 tokens.

File

./webform2pdf.install, line 406
Webform2pdf module install/schema hooks.

Code

function _webform2pdf_update_7401_batch(&$sandbox, $patterns, $replacements, $dpatterns, $dreplacements, $limit) {

  // Set up the initial batch process.
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['last_nid_processed'] = -1;
    $sandbox['max'] = db_select('webform2pdf')
      ->countQuery()
      ->execute()
      ->fetchField();
    $w2pdf_default = variable_get('webform2pdf_default', array());
    $p_body = $w2pdf_default['p_body']['value'];
    $p_body = str_replace($patterns, $replacements, $p_body);
    $p_body = preg_replace($dpatterns, $dreplacements, $p_body);
    $w2pdf_default['p_body']['value'] = $p_body;
    variable_set('webform2pdf_default', $w2pdf_default);
  }
  $webform2pdf_settings = db_select('webform2pdf', 'w2p')
    ->fields('w2p')
    ->condition('nid', $sandbox['last_nid_processed'], '>')
    ->orderBy('nid', 'ASC')
    ->range(0, $limit)
    ->execute()
    ->fetchAllAssoc('nid', PDO::FETCH_ASSOC);
  foreach ($webform2pdf_settings as $nid => $webform2pdf_setting) {

    // Update the webform record itself.
    $data = unserialize($webform2pdf_setting['data']);
    $data['p_body'] = str_replace($patterns, $replacements, $data['p_body']);
    $data['p_body'] = preg_replace($dpatterns, $dreplacements, $data['p_body']);
    $webform2pdf_setting['data'] = $data;
    drupal_write_record('webform2pdf', $webform2pdf_setting, array(
      'nid',
    ));

    // Update the last processed NID.
    $sandbox['last_nid_processed'] = $nid;
    $sandbox['progress']++;
  }
  return count($webform2pdf_settings);
}