You are here

function subscriptions_content_update_7001 in Subscriptions 7

Update the '!variables' in the stored templates to their corresponding new Drupal 7 '[tokens]'.

File

./subscriptions_content.install, line 52
Subscriptions Content module installation.

Code

function subscriptions_content_update_7001() {
  if (!db_table_exists('mail_edit')) {
    return;
  }
  $tokens = array(
    '!nid' => '[node:nid]',
    '!title' => '[node:title]',
    '!teaser' => '[node:summary]',
    '!body' => '[node:body]',
    '!full_node' => '[node:body]',
    '!node_type' => '[node:content-type:name]',
    '!revision_name' => '[user:name]',
    '!revision_log' => '[node:log]',
    '!url' => '[node:url]',
    '!term_name' => '[term:name]',
    '!is_published' => '[subs:is-published]',
    // (Unpublished nodes are sent to users with the administer nodes permission only.)
    '!bodies' => "[subs:nodes:join:\n]",
    '!comments' => "[subs:comments:join:\n]",
    '!comment_name' => '[comment:author:name]',
    '!comment_realname' => '[comment:author:name]',
    '!comment_uid' => '[comment:author:uid]',
    '!comment_title' => '[comment:title]',
    '!comment_text' => '[comment:body]',
    '!comment_cid' => '[comment:cid]',
    '!comment_nid' => '[comment:node:nid]',
    '!comment_url' => '[comment:url]',
    '!comment_is_new' => '[subs:is-new]',
    '!comment_is_published' => '[subs:is-published]',
  );
  $query = db_select('mail_edit', 'me', array(
    'fetch' => PDO::FETCH_ASSOC,
  ));
  $query
    ->join('mail_edit_registry', 'mer', 'mer.id = me.id');
  $result = $query
    ->fields('me')
    ->condition('mer.module', array(
    'subscriptions_content',
    'subscriptions_taxonomy',
  ), 'IN')
    ->execute();
  foreach ($result as $row) {
    $id = $row['id'];
    $langcode = $row['language'];
    unset($row['id']);
    unset($row['language']);
    $row['subject'] = strtr($row['subject'], $tokens);
    $row['body'] = strtr($row['body'], $tokens);
    db_update('mail_edit')
      ->fields($row)
      ->condition('id', $id)
      ->condition('language', $langcode)
      ->execute();
  }
}