You are here

function simplenews_update_6000 in Simplenews 6

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

Data conversion of block delta. Field type conversions: newsletter priority. Field name change in simplenews_subscriptions table.

File

./simplenews.install, line 321
Simplenews installation.

Code

function simplenews_update_6000() {
  $ret = array();

  // Convert the block delta: remove 'newsletter-' prefix from the delta.
  $result = db_query("SELECT module, delta FROM {blocks} WHERE module = 'simplenews' AND delta LIKE 'newsletter-%'");
  while ($data = db_fetch_object($result)) {
    $delta = strtr($data->delta, array(
      'newsletter-' => '',
    ));
    $ret[] = update_sql("UPDATE {blocks} SET delta = '%s' WHERE module = 'simplenews' AND delta = 'newsletter-%s'", $delta, $delta);
  }
  $result = db_query("SELECT module, delta FROM {blocks_roles} WHERE module = 'simplenews' AND delta LIKE 'newsletter-%'");
  while ($data = db_fetch_object($result)) {
    $delta = strtr($data->delta, array(
      'newsletter-' => '',
    ));
    $ret[] = update_sql("UPDATE {blocks_roles} SET delta = '%s' WHERE module = 'simplenews' AND delta = 'newsletter-%s'", $delta, $delta);
  }

  // Convert newsletter priority: change field type int to string
  db_change_field($ret, 'simplenews_newsletters', 'priority', 'priority', array(
    'type' => 'varchar',
    'length' => 8,
    'not null' => TRUE,
    'default' => '',
  ));

  // Convert subscription field name: change a_status to activated
  db_change_field($ret, 'simplenews_subscriptions', 'a_status', 'activated', array(
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => 0,
  ));

  // Convert subscription field name: change s_status to is_send
  db_change_field($ret, 'simplenews_subscriptions', 's_status', 'is_send', array(
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}