I’m looking for a way to delete about 1300 taxonomy terms (of 5250 in total) and their association with nodes. I firstly thought to delete the content of these tables:
- taxonomy_index
- taxonomy_term_data
- taxonomy_ter_field_data
- taxonomy_term_hierarchy
- node__field_tags
- node_revision__field_tag
Is this sufficient?
Is there a better way to do it, without Drush, which I cannot install?
EDIT :
I’m trying to do it programmaticaly, but I have an error
Error: Call to undefined function field_attach_delete() in delete_taxonomy_terms() (line 42 of /var/www/html/d8/delete_tags.php).
Trying to add call to module_load_include() but still get the same error. I put the file at the root of my Drupal installation (../mydrupal/delete_tags.php).
<?php error_reporting(E_ALL); date_default_timezone_set('Europe/Paris'); define('DRUPAL_DIR', $_SERVER["DOCUMENT_ROOT"]); //__DIR__ ); //.'/../drupal'); use DrupalCoreDrupalKernel; use SymfonyComponentHttpFoundationRequest; $autoloader = require_once 'autoload.php'; $kernel = new DrupalKernel('prod', $autoloader); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response); /** * Deletes taxonomy terms. * * @param array $tids * Array of taxonomy term IDs. */ $tids = [830]; delete_taxonomy_terms($tids); function delete_taxonomy_terms($tids) { module_load_include("inc", "field", "field.attach"); db_delete('taxonomy_term_data') ->condition('tid', $tids, 'IN') ->execute(); db_delete('taxonomy_term_hierarchy') ->condition('tid', $tids, 'IN') ->execute(); $terms = taxonomy_term_load_multiple($tids); foreach ($terms as $term) { field_attach_delete('taxonomy_term', $term); module_invoke_all('taxonomy_term_delete', $term); module_invoke_all('entity_delete', $term, 'taxonomy_term'); } // Reset static cache after all terms deleted. taxonomy_terms_static_reset(); }