From fb68b278bfe5db56b3e806b0c79dedc8684bd1c2 Mon Sep 17 00:00:00 2001
From: Lorenz Schori <lo@znerol.ch>
Date: Sun, 4 Nov 2012 15:52:18 +0100
Subject: [PATCH 2/2] Issue #1831450 by znerol: Convert
 taxonomy_maintain_index_table variables to use
 configuration system

---
 core/modules/field/field.api.php                   |    4 ++--
 core/modules/taxonomy/config/taxonomy.settings.yml |    1 +
 core/modules/taxonomy/taxonomy.install             |    1 +
 core/modules/taxonomy/taxonomy.module              |   10 +++++-----
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php
index 22a9ed7..386a002 100644
--- a/core/modules/field/field.api.php
+++ b/core/modules/field/field.api.php
@@ -455,7 +455,7 @@ function hook_field_presave($entity_type, $entity, $field, $instance, $langcode,
  * @see hook_field_delete()
  */
 function hook_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
-  if (variable_get('taxonomy_maintain_index_table', TRUE) && $field['storage']['type'] == 'field_sql_storage' && $entity_type == 'node' && $entity->status) {
+  if (config('taxonomy.settings')->get('maintain_index_table') && $field['storage']['type'] == 'field_sql_storage' && $entity_type == 'node' && $entity->status) {
     $query = db_insert('taxonomy_index')->fields(array('nid', 'tid', 'sticky', 'created', ));
     foreach ($items as $item) {
       $query->values(array(
@@ -496,7 +496,7 @@ function hook_field_insert($entity_type, $entity, $field, $instance, $langcode,
  * @see hook_field_delete()
  */
 function hook_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) {
-  if (variable_get('taxonomy_maintain_index_table', TRUE) && $field['storage']['type'] == 'field_sql_storage' && $entity_type == 'node') {
+  if (config('taxonomy.settings')->get('maintain_index_table') && $field['storage']['type'] == 'field_sql_storage' && $entity_type == 'node') {
     $first_call = &drupal_static(__FUNCTION__, array());
 
     // We don't maintain data for old revisions, so clear all previous values
diff --git a/core/modules/taxonomy/config/taxonomy.settings.yml b/core/modules/taxonomy/config/taxonomy.settings.yml
index cd43cc6..2c0b5ab 100644
--- a/core/modules/taxonomy/config/taxonomy.settings.yml
+++ b/core/modules/taxonomy/config/taxonomy.settings.yml
@@ -1,2 +1,3 @@
 override_selector: false
 terms_per_page_count: 100
+maintain_index_table: true
diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install
index 998f2fb..f959d65 100644
--- a/core/modules/taxonomy/taxonomy.install
+++ b/core/modules/taxonomy/taxonomy.install
@@ -354,6 +354,7 @@ function taxonomy_update_8004() {
   update_variables_to_config('taxonomy.settings', array(
     'taxonomy_override_selector' => 'override_selector',
     'taxonomy_terms_per_page_admin' => 'terms_per_page_count',
+    'taxonomy_maintain_index_table' => 'maintain_index_table',
   ));
 }
 
diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module
index 75573a9..894fec1 100644
--- a/core/modules/taxonomy/taxonomy.module
+++ b/core/modules/taxonomy/taxonomy.module
@@ -185,7 +185,7 @@ function taxonomy_field_extra_fields() {
  *   An array of nids matching the query.
  */
 function taxonomy_select_nodes($tid, $pager = TRUE, $limit = FALSE, $order = array('t.sticky' => 'DESC', 't.created' => 'DESC')) {
-  if (!variable_get('taxonomy_maintain_index_table', TRUE)) {
+  if (!config('taxonomy.settings')->get('maintain_index_table')) {
     return array();
   }
   $query = db_select('taxonomy_index', 't');
@@ -1388,7 +1388,7 @@ function taxonomy_rdf_mapping() {
  * published nodes and common sort criteria such as sticky and created.
  * This is used as a lookup table by taxonomy_select_nodes(). When using other
  * field storage engines or alternative methods of denormalizing this data
- * you should set the variable 'taxonomy_maintain_index_table' to FALSE
+ * you should set the config setting 'maintain_index_table' to false
  * to avoid unnecessary writes in SQL.
  */
 
@@ -1430,7 +1430,7 @@ function taxonomy_build_node_index($node) {
   // We maintain a denormalized table of term/node relationships, containing
   // only data for current, published nodes.
   $status = NULL;
-  if (variable_get('taxonomy_maintain_index_table', TRUE)) {
+  if (config('taxonomy.settings')->get('maintain_index_table')) {
     // If a node property is not set in the node object when node_save() is
     // called, the old value from $node->original is used.
     if (!empty($node->original)) {
@@ -1510,7 +1510,7 @@ function taxonomy_node_predelete(Node $node) {
  *   The node entity.
  */
 function taxonomy_delete_node_index(Node $node) {
-  if (variable_get('taxonomy_maintain_index_table', TRUE)) {
+  if (config('taxonomy.settings')->get('maintain_index_table')) {
     db_delete('taxonomy_index')->condition('nid', $node->nid)->execute();
   }
 }
@@ -1519,7 +1519,7 @@ function taxonomy_delete_node_index(Node $node) {
  * Implements hook_taxonomy_term_delete().
  */
 function taxonomy_taxonomy_term_delete(Term $term) {
-  if (variable_get('taxonomy_maintain_index_table', TRUE)) {
+  if (config('taxonomy.settings')->get('maintain_index_table')) {
     // Clean up the {taxonomy_index} table when terms are deleted.
     db_delete('taxonomy_index')->condition('tid', $term->tid)->execute();
   }
-- 
1.7.10.4

