Skip to content

Commit

Permalink
Taxonomy patch: Add primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
ericras committed Oct 30, 2018
1 parent 01a7e4b commit 96de392
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ Once that is complete, open a Pull Request against develop in unlcms/UNL-CMS.

- Add nl2br() on Plain Text processor. See http://drupal.org/node/1152216#comment-7174876

* modules/taxonomy

- Add a primary key to the {taxonomy_index} table. https://www.drupal.org/files/issues/drupal-n610076-75.patch

## Hacks of Contrib modules:

* autoban
Expand Down
22 changes: 21 additions & 1 deletion modules/taxonomy/taxonomy.install
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ function taxonomy_schema() {
'default'=> 0,
),
),
'primary key' => array('nid', 'tid'),
'indexes' => array(
'term_node' => array('tid', 'sticky', 'created'),
'nid' => array('nid'),
),
'foreign keys' => array(
'tracked_node' => array(
Expand Down Expand Up @@ -934,6 +934,26 @@ function taxonomy_update_7011(&$sandbox) {
}
}

/**
* Add primary key and drop nid key.
*/
function taxonomy_update_7012() {
db_add_field('taxonomy_index', 'tempid', array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Tempid.',
), array(
'unique keys' => array(
'tempid' => array('tempid')
),
)
);
db_query('DELETE t1 FROM {taxonomy_index} as t1 join {taxonomy_index} as t2 WHERE t1.nid = t2.nid AND t1.tid = t2.tid and t1.tempid > t2.tempid');
db_drop_field('taxonomy_index', 'tempid');
db_drop_index('taxonomy_index', 'nid');
db_add_primary_key('taxonomy_index', array('nid', 'tid'));
}

/**
* @} End of "addtogroup updates-7.x-extra".
*/
12 changes: 4 additions & 8 deletions modules/taxonomy/taxonomy.module
Original file line number Diff line number Diff line change
Expand Up @@ -1969,16 +1969,12 @@ function taxonomy_build_node_index($node) {
}
// Insert index entries for all the node's terms.
if (!empty($tid_all)) {
$query = db_insert('taxonomy_index')->fields(array('nid', 'tid', 'sticky', 'created'));
foreach ($tid_all as $tid) {
$query->values(array(
'nid' => $node->nid,
'tid' => $tid,
'sticky' => $sticky,
'created' => $node->created,
));
db_merge('taxonomy_index')
->key(array('nid' => $node->nid, 'tid' => $tid))
->fields(array('sticky' => $sticky, 'created' => $node->created))
->execute();
}
$query->execute();
}
}
}
Expand Down
66 changes: 66 additions & 0 deletions patches/drupal-n610076-75.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
diff --git a/modules/taxonomy/taxonomy.install b/modules/taxonomy/taxonomy.install
index ebd0084..53cc680 100644
--- a/modules/taxonomy/taxonomy.install
+++ b/modules/taxonomy/taxonomy.install
@@ -204,9 +204,9 @@ function taxonomy_schema() {
'default'=> 0,
),
),
+ 'primary key' => array('nid', 'tid'),
'indexes' => array(
'term_node' => array('tid', 'sticky', 'created'),
- 'nid' => array('nid'),
),
'foreign keys' => array(
'tracked_node' => array(
@@ -934,5 +934,25 @@ function taxonomy_update_7011(&$sandbox) {
}

/**
+ * Add primary key and drop nid key.
+ */
+function taxonomy_update_7012() {
+ db_add_field('taxonomy_index', 'tempid', array(
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ 'description' => 'Tempid.',
+ ), array(
+ 'unique keys' => array(
+ 'tempid' => array('tempid')
+ ),
+ )
+ );
+ db_query('DELETE t1 FROM {taxonomy_index} as t1 join {taxonomy_index} as t2 WHERE t1.nid = t2.nid AND t1.tid = t2.tid and t1.tempid > t2.tempid');
+ db_drop_field('taxonomy_index', 'tempid');
+ db_drop_index('taxonomy_index', 'nid');
+ db_add_primary_key('taxonomy_index', array('nid', 'tid'));
+}
+
+/**
* @} End of "addtogroup updates-7.x-extra".
*/
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 554d6d2..b3e5564 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -1969,16 +1969,12 @@ function taxonomy_build_node_index($node) {
}
// Insert index entries for all the node's terms.
if (!empty($tid_all)) {
- $query = db_insert('taxonomy_index')->fields(array('nid', 'tid', 'sticky', 'created'));
foreach ($tid_all as $tid) {
- $query->values(array(
- 'nid' => $node->nid,
- 'tid' => $tid,
- 'sticky' => $sticky,
- 'created' => $node->created,
- ));
+ db_merge('taxonomy_index')
+ ->key(array('nid' => $node->nid, 'tid' => $tid))
+ ->fields(array('sticky' => $sticky, 'created' => $node->created))
+ ->execute();
}
- $query->execute();
}
}
}

0 comments on commit 96de392

Please sign in to comment.