You are here

function faq_update_2 in Frequently Asked Questions 7

Same name and namespace in other branches
  1. 5.2 faq.install \faq_update_2()
  2. 6 faq.install \faq_update_2()
  3. 7.2 faq.install \faq_update_2()

Create 'faq_questions' table in order to upgrade from older installations.

File

./faq.install, line 223
FAQ module install file.

Code

function faq_update_2() {
  $schema['faq_questions'] = array(
    'description' => 'A table containing the long question text of each faq node revision.',
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The primary identifier for a node.',
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The primary identifier for a node revision.',
      ),
      'question' => array(
        'type' => 'text',
        'size' => 'normal',
        'not null' => TRUE,
        'description' => 'The faq long question text.',
      ),
    ),
    'primary key' => array(
      'nid',
      'vid',
    ),
  );
  db_create_table('faq_questions', $schema['faq_questions']);

  // Pre-populate the questions table from the existing nodes.
  $select = db_select('node', 'n');
  $select
    ->innerJoin('node_revisions', 'r', 'n.nid = %alias.nid');
  $select
    ->fields('r', array(
    'nid',
    'vid',
    'title',
  ))
    ->condition('n.type', 'faq');
  db_insert('faq_questions')
    ->fields(array(
    'nid',
    'vid',
    'question',
  ))
    ->from($select)
    ->execute();
  return t('FAQ Questions table created.');
}