You are here

function webform_update_7401 in Webform 7.4

Rewrite token replacement system to use D7 tokens.

If needed, please download and install the Token module from drupal.org. Otherwise some tokens will not be rendered.

File

./webform.install, line 1247
Webform module install/schema hooks.

Code

function webform_update_7401(&$sandbox) {

  // Define replacements.
  $patterns = array(
    '%username',
    '%useremail',
    '%uid',
    '%date',
    '%ip_address',
    '%site',
    '%nid',
    '%title',
    '%email_values',
    '%submission_url',
    '%sid',
    '%server[REQUEST_URI]',
    // Used to convert nested arrays of %value and %email.
    '][',
  );
  $replacements = array(
    '[current-user:name]',
    '[current-user:mail]',
    '[current-user:uid]',
    '[submission:date:long]',
    '[current-user:ip-address]',
    '[site:name]',
    '[node:nid]',
    '[node:title]',
    '[submission:values]',
    '[submission:url]',
    '[submission:sid]',
    '[current-page:url]',
    // Replace "][" with ":" for %value and %email.
    ':',
  );
  $dpatterns = array(
    '/%get\\[([^\\]]+)\\]/m',
    '/%email\\[([^% \\n\\r\\t]+)?\\]/m',
    '/%value\\[([^% \\n\\r\\t]+)?\\]/m',
    '/%profile\\[([^\\]]+)\\]/m',
  );
  $dreplacements = array(
    '[current-page:query:$1]',
    '[submission:values:$1]',
    '[submission:values:$1:nolabel]',
    '[current-user:$1]',
  );
  $limit = webform_variable_get('webform_update_batch_size');
  $processed_count = _webform_update_7401_batch($sandbox, $patterns, $replacements, $dpatterns, $dreplacements, $limit);

  // If less than limit was processed, the update process is finished.
  if ($processed_count < $limit || $sandbox['progress'] == $sandbox['max']) {
    $finished = TRUE;
  }

  // If there's no max value then there's nothing to update and we're finished.
  if (empty($sandbox['max']) || isset($finished)) {
    $message = t('Your existing webforms have been upgraded to use the global Drupal 7 token system.');
    if (!module_exists('token')) {
      $message .= ' <strong>' . t('Please download and install the <a href="http://drupal.org/project/token" target="_blank">Token module</a>. Otherwise some tokens will not be rendered.') . '</strong>';
    }
    return $message;
  }
  else {

    // Indicate our current progress to the batch update system.
    $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
  }
}