You are here

function simplenews_update_6005 in Simplenews 6

Same name and namespace in other branches
  1. 6.2 simplenews.install \simplenews_update_6005()

Add language field to subscription table and set language of existing subscribers.

File

./simplenews.install, line 529
Simplenews installation.

Code

function simplenews_update_6005() {
  $ret = array();
  db_add_field($ret, 'simplenews_subscriptions', 'language', array(
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
    'description' => 'Subscriber preferred language.',
  ));

  // Set preferred language for all current none anonymous subscribers.
  $result = db_query('SELECT s.snid, u.language FROM {simplenews_subscriptions} s INNER JOIN {users} u ON u.uid = s.uid WHERE s.uid > %d', 0);
  while ($subscriber = db_fetch_object($result)) {
    $ret[] = update_sql("UPDATE {simplenews_subscriptions} SET language = '%s' WHERE snid = %d", $subscriber->language, $subscriber->snid);
  }
  return $ret;
}