function subscriptions_update_7002 in Subscriptions 7
Update the '!variables' in the stored templates to their corresponding new Drupal 7 '[tokens]'.
File
- ./
subscriptions.install, line 281 - Subscriptions module installation.
Code
function subscriptions_update_7002() {
if (!db_table_exists('mail_edit')) {
return;
}
$tokens = array(
'!site' => '[site:name]',
'!recipient_uid' => '[current-user:uid]',
'!recipient_name' => '[current-user:name]',
'!recipient_page' => '[current-user:url]',
'!name' => '[current-user:name]',
'!sender_uid' => '[user:uid]',
'!sender_name' => '[user:name]',
'!sender_page' => '[user:url]',
'!sender_contact_page' => '[### !sender_contact_page ###]',
'!sender_has_contact_page' => '[### !sender_has_contact_page ###]',
'!is_new' => '[subs:is-new]',
'!is_updated' => '[subs:is-updated]',
'!is_old' => '[subs:is-old]',
'!comments' => '[subs:comments]',
'!has_new_comments' => '[subs:comments:count]',
'!subs_type' => '[subs:type]',
'!manage_url' => '[subs:manage-url]',
'!unsubscribe_url' => '[subs:unsubscribe-url]',
'!has_files' => '[### !has_files ###]',
'!files' => '[### !files ###]',
);
$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', 'subscriptions_content')
->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();
}
}