You are here

function apachesolr_node_type_update in Apache Solr Search 8

Same name and namespace in other branches
  1. 7 apachesolr.module \apachesolr_node_type_update()

Implements hook_node_type_update().

Performance issue with Mysql To know why PDO in drupal does not support UPDATE and JOIN at once. @todo Support backwards compatibility

See also

http://drupal.org/node/592522

http://api.drupal.org/api/drupal/includes--database--database.inc/functi...

File

./apachesolr.module, line 758
Integration with the Apache Solr search application.

Code

function apachesolr_node_type_update($info) {
  if (!empty($info->old_type) && $info->old_type != $info->type) {

    // We cannot be sure we are going before or after node module.
    $table = apachesolr_get_indexer_table('node');
    switch (db_driver()) {
      case 'mysql':
        $table = db_escape_table($table);
        $query = "UPDATE {{$table}} asn\n          INNER JOIN {node} n ON asn.entity_id = n.nid SET asn.changed = :changed\n          WHERE (n.type = :type OR n.type = :old_type)";
        $result = db_query($query, array(
          ':changed' => REQUEST_TIME,
          ':type' => $info->type,
          ':old_type' => $info->old_type,
        ));
        break;
      default:
        $nids = db_select('node')
          ->fields('node', array(
          'nid',
        ))
          ->where("type = :new OR type = :old", array(
          ':new' => $info->type,
          ':old' => $info->old_type,
        ));
        $update = db_update($table)
          ->condition('entity_id', $nids, 'IN')
          ->fields(array(
          'changed' => REQUEST_TIME,
        ))
          ->execute();
    }
    db_update('apachesolr_index_bundles')
      ->condition('bundle', $info->old_type)
      ->condition('entity_type', 'node')
      ->fields(array(
      'bundle' => $info->type,
    ))
      ->execute();
    apachesolr_environments_clear_cache();
  }
}