You are here

function page_title_update_6200 in Page Title 6.2

Same name and namespace in other branches
  1. 8.2 page_title.install \page_title_update_6200()
  2. 7.2 page_title.install \page_title_update_6200()
  3. 7 page_title.install \page_title_update_6200()

Implementation of hook_update_n().

File

./page_title.install, line 37
The install file for Page Title allows the module to install (and uninstall) itself. This is required as this module uses its own table.

Code

function page_title_update_6200() {
  $ret = array();
  if (db_column_exists('page_title', 'id')) {
    return $ret;
  }
  elseif (db_table_exists('page_title_temp') || db_table_exists('page_title_old')) {
    drupal_set_message(t('Page Title cannot be updated until page_title_temp and/or page_title_old have been removed. Please manually remove these tables (if safe to do so), return to <a href="@update-php">update.php</a> and run the remaining updates.', array(
      '@update-php' => base_path() . 'update.php?op=selection',
    )), 'warning', FALSE);
    return array(
      '#abort' => array(
        'success' => FALSE,
        'query' => t('It seems page_title_temp or page_title_old tables are already present in your database, possibly from a previous update. Please remove these tables from your database.'),
      ),
    );
  }
  db_create_table($ret, 'page_title_temp', array(
    'fields' => array(
      'type' => array(
        'type' => 'varchar',
        'length' => 15,
        'not null' => TRUE,
        'default' => 'node',
      ),
      'id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'page_title' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'type',
      'id',
    ),
  ));
  $ret[] = update_sql('INSERT INTO {page_title_temp} (id, page_title) SELECT nid, page_title FROM {page_title}');
  db_rename_table($ret, 'page_title', 'page_title_old');
  db_rename_table($ret, 'page_title_temp', 'page_title');
  $display_settings = variable_get('page_title_display', array());
  foreach ($display_settings as $type) {
    if ($type) {
      variable_set('page_title_type_' . $type . '_showfield', 1);
    }
  }
  variable_del('page_title_display');
  return $ret;
}