Commit c4e1242e authored by Angie Byron's avatar Angie Byron
Browse files

#412518 by catch, bangpound, and yched: Convert taxonomy_node_* to field API...

#412518 by catch, bangpound, and yched: Convert taxonomy_node_* to field API (with upgrade path). Say buh-bye to old, crusty code.
parent f5b02199
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@
 * - $topic->message: If the topic has been moved, this contains an
 *   explanation and a link.
 * - $topic->zebra: 'even' or 'odd' string used for row class.
 * - $topic->num_comments: The number of replies on this topic.
 * - $topic->comment_count: The number of replies on this topic.
 * - $topic->new_replies: A flag to indicate whether there are unread comments.
 * - $topic->new_url: If there are unread replies, this is a link to them.
 * - $topic->new_text: Text containing the translated, properly pluralized count.
@@ -53,7 +53,7 @@
      <td colspan="3"><?php print $topic->message; ?></td>
    <?php else: ?>
      <td class="replies">
        <?php print $topic->num_comments; ?>
        <?php print $topic->comment_count; ?>
        <?php if ($topic->new_replies): ?>
          <br />
          <a href="<?php print $topic->new_url; ?>"><?php print $topic->new_text; ?></a>
+1 −1
Original line number Diff line number Diff line
@@ -5,8 +5,8 @@
 * @file
 * Administrative page callbacks for the forum module.
 */

function forum_form_main($type, $edit = array()) {
  $edit = (array) $edit;
  if ((isset($_POST['op']) && $_POST['op'] == t('Delete')) || !empty($_POST['confirm'])) {
    return drupal_get_form('forum_confirm_delete', $edit['tid']);
  }
+146 −6
Original line number Diff line number Diff line
@@ -22,9 +22,7 @@ function forum_install() {

function forum_enable() {
  if ($vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', 0))) {
    // Existing install. Add back forum node type, if the forums
    // vocabulary still exists. Keep all other node types intact there.
    $vocabulary->nodes['forum'] = 1;
    // Save the vocabulary to create the default field instance.
    taxonomy_vocabulary_save($vocabulary);
  }
  else {
@@ -33,17 +31,26 @@ function forum_enable() {
    // forms.
    $edit = array(
      'name' => t('Forums'),
      'multiple' => 0,
      'required' => 0,
      'machine_name' => 'forums',
      'description' => t('Forum navigation vocabulary'),
      'hierarchy' => 1,
      'relations' => 0,
      'module' => 'forum',
      'weight' => -10,
      'nodes' => array('forum' => 1),
    );
    $vocabulary = (object) $edit;
    taxonomy_vocabulary_save($vocabulary);

    $instance = array(
      'field_name' => 'taxonomy_' . $vocabulary->machine_name,
      'label' => $vocabulary->name,
      'bundle' => 'forum',
      'widget' => array(
        'type' => 'options_select',
      ),
    );
    field_create_instance($instance);

    variable_set('forum_nav_vocabulary', $vocabulary->vid);
  }
}
@@ -109,6 +116,68 @@ function forum_schema() {
    ),
  );

  $schema['forum_index'] = array(
    'description' => 'Maintains denormalized information about node/term relationships.',
    'fields' => array(
      'nid' => array(
        'description' => 'The {node}.nid this record tracks.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'title' => array(
        'description' => 'The title of this node, always treated as non-markup plain text.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'tid' => array(
         'description' => 'The term ID.',
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
         'default' => 0,
      ),
      'sticky' => array(
        'description' => 'Boolean indicating whether the node is sticky.',
        'type' => 'int',
        'not null' => FALSE,
        'default' => 0,
        'size' => 'tiny',
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the node was created.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default'=> 0,
      ),
      'last_comment_timestamp' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',
      ),
      'comment_count' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The total number of comments on this node.',
      ),
    ),
    'indexes' => array(
      'forum_topics' => array('tid', 'sticky', 'last_comment_timestamp'),
    ),
    'foreign keys' => array(
      'node' => 'nid',
      'taxonomy_term_data' => 'tid',
    ),
  );


  return $schema;
}

@@ -119,3 +188,74 @@ function forum_update_7000() {
  db_drop_index('forum', 'nid');
  db_add_index('forum', 'forum_topic', array('nid', 'tid'));
}

/**
 * Create new {forum_index} table.
 */
function forum_update_7001() {
  $forum_index = array(
    'description' => 'Maintains denormalized information about node/term relationships.',
    'fields' => array(
      'nid' => array(
        'description' => 'The {node}.nid this record tracks.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'title' => array(
        'description' => 'The title of this node, always treated as non-markup plain text.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'tid' => array(
         'description' => 'The term ID.',
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
         'default' => 0,
      ),
      'sticky' => array(
        'description' => 'Boolean indicating whether the node is sticky.',
        'type' => 'int',
        'not null' => FALSE,
        'default' => 0,
        'size' => 'tiny',
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the node was created.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default'=> 0,
      ),
      'last_comment_timestamp' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',
      ),
      'comment_count' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The total number of comments on this node.',
      ),
    ),
    'indexes' => array(
      'forum_topics' => array('tid', 'sticky', 'last_comment_timestamp'),
    ),
    'foreign keys' => array(
      'node' => 'nid',
      'taxonomy_term_data' => 'tid',
    ),
  );
  db_create_table($ret, 'forum_index', $forum_index);

  db_query('INSERT INTO {forum_index} (SELECT n.nid, n.title, f.tid, n.sticky, n.created, ncs.last_comment_timestamp, ncs.comment_count FROM {node} n INNER JOIN {forum} f on n.vid = f.vid INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid)');

  return $ret;
}
+257 −191

File changed.

Preview size limit exceeded, changes collapsed.

+3 −4
Original line number Diff line number Diff line
@@ -131,8 +131,7 @@ class ForumTestCase extends DrupalWebTestCase {
    $edit = array(
      'name' => $title,
      'description' => $description,
      'machine_name' => drupal_strtolower($this->randomName()),
      'help' => '',
      'machine_name' => drupal_strtolower(drupal_substr($this->randomName(), 3, 9)),
    );

    // Edit the vocabulary.
@@ -251,7 +250,7 @@ class ForumTestCase extends DrupalWebTestCase {
    $edit = array(
      'title' => $title,
      "body[$langcode][0][value]" => $body,
      'taxonomy[1]' => $tid
      "taxonomy_forums[$langcode][value]" => $tid,
    );

    // TODO The taxonomy select value is set by drupal code when the tid is part
@@ -341,7 +340,7 @@ class ForumTestCase extends DrupalWebTestCase {
      $langcode = FIELD_LANGUAGE_NONE;
      $edit["body[$langcode][0][value]"] = $this->randomName(256);
      // Assume the topic is initially associated with $forum.
      $edit['taxonomy[1]'] = $this->root_forum['tid'];
      $edit["taxonomy_forums[$langcode][value]"] = $this->root_forum['tid'];
      $edit['shadow'] = TRUE;
      $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
      $this->assertRaw(t('Forum topic %title has been updated.', array('%title' => $edit['title'])), t('Forum node was edited'));
Loading