You are here

function quotes_update_9 in Quotes 5

Implementation of hook_update_N.

File

./quotes.install, line 372
Handles installation and updates for the quotes module.

Code

function quotes_update_9() {
  global $db_type;
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {quotes_blocks} ADD COLUMN show_citation INTEGER NOT NULL DEFAULT 0");
      $ret[] = update_sql("ALTER TABLE {quotes_blocks} ADD COLUMN max_length INTEGER NOT NULL DEFAULT 0");
      $ret[] = update_sql("ALTER TABLE {quotes_blocks} ADD COLUMN view_weight INTEGER NOT NULL DEFAULT 0");
      $ret[] = update_sql("ALTER TABLE {quotes_blocks} ADD COLUMN view_text VARCHAR(64)");
      $ret[] = update_sql("ALTER TABLE {quotes_blocks} ADD COLUMN more_text VARCHAR(64)");
      break;
    case 'pgsql':
      db_add_column($ret, 'quotes_blocks', 'show_citation', 'INTEGER', array(
        'not null' => TRUE,
        'default' => '0',
      ));
      db_add_column($ret, 'quotes_blocks', 'max_length', 'INTEGER', array(
        'not null' => TRUE,
        'default' => '0',
      ));
      db_add_column($ret, 'quotes_blocks', 'view_weight', 'INTEGER', array(
        'not null' => TRUE,
        'default' => '1',
      ));
      db_add_column($ret, 'quotes_blocks', 'view_text', 'VARCHAR(64)');
      db_add_column($ret, 'quotes_blocks', 'more_text', 'VARCHAR(64)');
  }

  // Incorrectly set per block.
  $max_len = variable_get('quotes_block_max_length', 0);

  // Set globally in admin page.
  $view_text = variable_get('quotes_block_view_text', t('View'));
  $view_weight = variable_get('quotes_block_view_weight', 1);
  $show_citation = variable_get('quotes_block_citation', TRUE);
  $ret[] = update_sql("UPDATE {quotes_blocks} SET view_text='" . $view_text . "', view_weight=" . $view_weight . ", show_citation=" . $show_citation . ", max_length=" . $max_len . " WHERE 1=1");

  // "more" text is per block already, but in a variable.
  $result = db_query('SELECT bid FROM {quotes_blocks}');
  while ($block = db_fetch_array($result)) {
    $more_text = variable_get('quotes_more_' . $block['bid'], NULL);
    $ret[] = update_sql("UPDATE {quotes_blocks} SET more_text='" . $more_text . "' WHERE bid=" . $block['bid']);
  }

  // Don't delete variables in case the update fails.
  return $ret;
}