diff --git a/src/Entity/Index.php b/src/Entity/Index.php index 9d741f1..3bdb931 100644 --- a/src/Entity/Index.php +++ b/src/Entity/Index.php @@ -1421,6 +1421,17 @@ class Index extends ConfigEntityBase implements IndexInterface { } } + $processors = $this->getOption('processors', array()); + foreach ($dependencies['module'] as $module) { + foreach ($this->getProcessors(FALSE) as $key => $processor) { + if ($processor->getPluginDefinition()['provider'] == $module) { + unset($processors[$key]); + $changed = TRUE; + } + } + } + $this->setOption('processors', $processors); + return $changed; } diff --git a/src/Tests/DependencyRemovalTest.php b/src/Tests/DependencyRemovalTest.php new file mode 100644 index 0000000..5cf1dbd --- /dev/null +++ b/src/Tests/DependencyRemovalTest.php @@ -0,0 +1,146 @@ +drupalCreateUser(array( + 'administer search_api', + 'administer content types', + 'access administration pages', + 'administer modules', + )); + $this->drupalLogin($admin_user); + + // Create a server and index. + $this->getTestServer(); + $index = $this->getTestIndex(); + $this->indexId = $index->id(); + } + + /** + * Tests the reaction of an index when a processor's module is removed. + * + * When a module that provides a processor is uninstalled, it should not + * delete the indexes that processor is enabled on. This would cause a chain + * removal of facets and views as well. Instead, the processor should just be + * disabled and no longer be found on the processors tab. + */ + public function testProcessorRemoval() { + // Enable the dummy processor on the index. + $this->drupalGet($this->getIndexPath('processors')); + $this->assertText($this->t('Dummy processor')); + $this->drupalPostForm(NULL, array('status[dummy_processor]' => 1), $this->t('Save')); + $this->assertResponse(200); + $this->assertText($this->t('The indexing workflow was successfully edited.')); + + // Uninstall the module. + $this->drupalGet('admin/modules/uninstall'); + $this->drupalPostForm(NULL, array('uninstall[search_api_test_processor]' => 1), $this->t('Uninstall')); + // Make sure the index is not deleted when uninstalling the module. + $this->assertNoText($this->t('The listed configuration will be deleted.')); + $this->assertText($this->t('The listed configuration will be updated.')); + + $this->drupalPostForm(NULL, array(), $this->t('Uninstall')); + $this->assertText($this->t('The selected modules have been uninstalled.')); + + // Make sure the index is still actually present. + $this->drupalGet('admin/config/search/search-api'); + $this->assertText('WebTest Index'); + + // Make sure the processor is no longer found on the processors tab. + $this->drupalGet($this->getIndexPath('processors')); + $this->assertResponse(200); + $this->assertNoText('Dummy processor'); + } + + /** + * Tests the reaction of an index when a content type is removed. + * + * When a content type that is indexed is removed, the index shouldn't be + * removed as well. + */ + public function testContentTypeRemoval() { + // Add two articles and a page. + $this->drupalCreateNode(array('type' => 'article')); + $this->drupalCreateNode(array('type' => 'article')); + $page = $this->drupalCreateNode(array('type' => 'page')); + + // Make sure the content is indexed. + $this->drupalGet($this->getIndexPath()); + $this->assertText('3/3 indexed'); + + // Try to delete content type. + $this->drupalGet('admin/structure/types/manage/page/delete'); + $this->assertText('Page is used by 1 piece of content on your site.'); + + // Delete the only created page. + $page->delete(); + + // Delete the content type. + $this->drupalGet('admin/structure/types/manage/page/delete'); + $this->drupalPostForm(NULL, array(), $this->t('Delete')); + $this->assertText('The content type Page has been deleted'); + + // Make sure the index is still actually present. + $this->drupalGet('admin/config/search/search-api'); + $this->assertText('WebTest Index'); + + // Make sure the content is indexed. + $this->drupalGet($this->getIndexPath()); + $this->assertText('2/2 indexed'); + } + + /** + * Returns the system path for the test index. + * + * @param string|null $tab + * (optional) If set, the path suffix for a specific index tab. + * + * @return string + * A system path. + */ + protected function getIndexPath($tab = NULL) { + $path = 'admin/config/search/search-api/index/' . $this->indexId; + if ($tab) { + $path .= "/$tab"; + } + return $path; + } + +} diff --git a/tests/search_api_test_processor/config/schema/search_api_test_processor.schema.yml b/tests/search_api_test_processor/config/schema/search_api_test_processor.schema.yml new file mode 100644 index 0000000..2de69c5 --- /dev/null +++ b/tests/search_api_test_processor/config/schema/search_api_test_processor.schema.yml @@ -0,0 +1,10 @@ +search_api.processor.plugin.dummy_processor: + type: mapping + label: 'Dummy processor configuration' + mapping: + fields: + type: sequence + label: 'The selected fields' + sequence: + type: string + label: 'Selected field' diff --git a/tests/search_api_test_processor/search_api_test_processor.info.yml b/tests/search_api_test_processor/search_api_test_processor.info.yml new file mode 100644 index 0000000..de85f76 --- /dev/null +++ b/tests/search_api_test_processor/search_api_test_processor.info.yml @@ -0,0 +1,8 @@ +name: 'Search API Custom processor Test' +type: module +description: 'Support module for Search API tests' +package: Search +dependencies: + - search_api:search_api +core: 8.x +hidden: true diff --git a/tests/search_api_test_processor/src/Plugin/search_api/processor/DummyProcessor.php b/tests/search_api_test_processor/src/Plugin/search_api/processor/DummyProcessor.php new file mode 100644 index 0000000..537e6c7 --- /dev/null +++ b/tests/search_api_test_processor/src/Plugin/search_api/processor/DummyProcessor.php @@ -0,0 +1,35 @@ +