/**
  * Implements AcsfEventHandler::handle().
  */
 public function handle()
 {
     drush_print(dt('Entered @class', array('@class' => get_class($this))));
     $tables = array();
     // Invalidate search indexes. If the search module has never been enabled,
     // then it's not enabled now and this block is skipped.
     if (module_exists('search')) {
         // Call this function to ensure that the necessary search hooks get
         // called.
         search_reindex();
         // Calling search_reindex globally (with no parameters) invokes hooks, but
         // does not truncate the following tables:
         $tables[] = 'search_dataset';
         $tables[] = 'search_index';
         $tables[] = 'search_node_links';
         $tables[] = 'search_total';
     }
     $tables[] = 'accesslog';
     $tables[] = 'node_counter';
     $tables[] = 'batch';
     $tables[] = 'queue';
     $tables[] = 'semaphore';
     $tables[] = 'sessions';
     $tables[] = 'themebuilder_session';
     $this->truncateTables($tables);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($form['confirm']) {
         search_reindex();
         drupal_set_message($this->t('The index will be rebuilt.'));
         $form_state->setRedirectUrl($this->getCancelUrl());
     }
 }
示例#3
0
 /**
  * Implements \Drupal\Core\Form\FormInterface::submitForm().
  */
 public function submitForm(array &$form, array &$form_state)
 {
     if ($form['confirm']) {
         search_reindex();
         drupal_set_message($this->t('The index will be rebuilt.'));
         $form_state['redirect_route'] = $this->getCancelRoute();
     }
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public static function preDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::preDelete($storage, $entities);
     // Assure that all nodes deleted are removed from the search index.
     if (\Drupal::moduleHandler()->moduleExists('search')) {
         foreach ($entities as $entity) {
             search_reindex($entity->nid->value, 'node_search');
         }
     }
 }
 /**
  * Tests the indexing throttle and search results with multilingual nodes.
  */
 function testMultilingualSearch()
 {
     // Index only 2 nodes per cron run. We cannot do this setting in the UI,
     // because it doesn't go this low.
     \Drupal::config('search.settings')->set('index.cron_limit', 2)->save();
     // Get a new search plugin, to make sure it has this setting.
     $this->plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
     // Update the index. This does the initial processing.
     $this->plugin->updateIndex();
     // Run the shutdown function. Testing is a unique case where indexing
     // and searching has to happen in the same request, so running the shutdown
     // function manually is needed to finish the indexing process.
     search_update_totals();
     $this->assertIndexCounts(6, 8, 'after updating partially');
     // Now index the rest of the nodes.
     // Make sure index throttle is high enough, via the UI.
     $this->drupalPostForm('admin/config/search/pages', array('cron_limit' => 20), t('Save configuration'));
     $this->assertEqual(20, \Drupal::config('search.settings')->get('index.cron_limit', 100), 'Config setting was saved correctly');
     // Get a new search plugin, to make sure it has this setting.
     $this->plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
     $this->plugin->updateIndex();
     search_update_totals();
     $this->assertIndexCounts(0, 8, 'after updating fully');
     // Test search results.
     // This should find two results for the second and third node.
     $this->plugin->setSearch('English OR Hungarian', array(), array());
     $search_result = $this->plugin->execute();
     $this->assertEqual(count($search_result), 2, 'Found two results.');
     // Nodes are saved directly after each other and have the same created time
     // so testing for the order is not possible.
     $results = array($search_result[0]['title'], $search_result[1]['title']);
     $this->assertTrue(in_array('Third node this is the Hungarian title', $results), 'The search finds the correct Hungarian title.');
     $this->assertTrue(in_array('Second node this is the English title', $results), 'The search finds the correct English title.');
     // Now filter for Hungarian results only.
     $this->plugin->setSearch('English OR Hungarian', array('f' => array('language:hu')), array());
     $search_result = $this->plugin->execute();
     $this->assertEqual(count($search_result), 1, 'The search found only one result');
     $this->assertEqual($search_result[0]['title'], 'Third node this is the Hungarian title', 'The search finds the correct Hungarian title.');
     // Test for search with common key word across multiple languages.
     $this->plugin->setSearch('node', array(), array());
     $search_result = $this->plugin->execute();
     $this->assertEqual(count($search_result), 6, 'The search found total six results');
     // Test with language filters and common key word.
     $this->plugin->setSearch('node', array('f' => array('language:hu')), array());
     $search_result = $this->plugin->execute();
     $this->assertEqual(count($search_result), 2, 'The search found 2 results');
     // Test to check for the language of result items.
     foreach ($search_result as $result) {
         $this->assertEqual($result['langcode'], 'hu', 'The search found the correct Hungarian result');
     }
     // Mark one of the nodes for reindexing, using the API function, and
     // verify indexing status.
     search_reindex($this->searchable_nodes[0]->id(), 'node_search');
     $this->assertIndexCounts(1, 8, 'after marking one node to reindex via API function');
     // Update the index and verify the totals again.
     $this->plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
     $this->plugin->updateIndex();
     search_update_totals();
     $this->assertIndexCounts(0, 8, 'after indexing again');
     // Mark one node for reindexing by saving it, and verify indexing status.
     $this->searchable_nodes[1]->save();
     $this->assertIndexCounts(1, 8, 'after marking one node to reindex via save');
     // The request time is always the same throughout test runs. Update the
     // request time to a previous time, to simulate it having been marked
     // previously.
     $current = REQUEST_TIME;
     $old = $current - 10;
     db_update('search_dataset')->fields(array('reindex' => $old))->condition('reindex', $current, '>=')->execute();
     // Save the node again. Verify that the request time on it is not updated.
     $this->searchable_nodes[1]->save();
     $result = db_select('search_dataset', 'd')->fields('d', array('reindex'))->condition('type', 'node_search')->condition('sid', $this->searchable_nodes[1]->id())->execute()->fetchField();
     $this->assertEqual($result, $old, 'Reindex time was not updated if node was already marked');
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     $search_settings = $this->configFactory->get('search.settings');
     // If these settings change, the index needs to be rebuilt.
     if ($search_settings->get('index.minimum_word_size') != $form_state['values']['minimum_word_size'] || $search_settings->get('index.overlap_cjk') != $form_state['values']['overlap_cjk']) {
         $search_settings->set('index.minimum_word_size', $form_state['values']['minimum_word_size']);
         $search_settings->set('index.overlap_cjk', $form_state['values']['overlap_cjk']);
         drupal_set_message($this->t('The index will be rebuilt.'));
         search_reindex();
     }
     $search_settings->set('index.cron_limit', $form_state['values']['cron_limit'])->set('logging', $form_state['values']['logging'])->save();
     drupal_set_message($this->t('The configuration options have been saved.'));
 }