hierarchical_taxonomy_importer.install in Hierarchical Taxonomy Import 8
This file will contain install and uninstall hooks for hierarchical_taxonomy_importer module.
File
hierarchical_taxonomy_importer.installView source
<?php
/**
* @file
* This file will contain install and uninstall hooks for hierarchical_taxonomy_importer module.
*/
/**
* {@inherit_doc}.
*/
function hierarchical_taxonomy_importer_schema() {
// Levels Information Table.
$schema['hti_term_levels'] = [
'description' => t('This table captures the levels and offsets to keep track of an existing term.'),
'fields' => [
'tid' => [
'type' => 'int',
'length' => 10,
'not null' => TRUE,
'unsigned' => TRUE,
],
'name' => [
'type' => 'varchar',
'length' => '160',
'not null' => TRUE,
],
'level' => [
'type' => 'int',
'not null' => TRUE,
],
'row' => [
'type' => 'int',
'not null' => TRUE,
],
'parent' => [
'type' => 'int',
'not null' => TRUE,
],
],
'primary key' => [
'tid',
],
'foreign keys' => [
'hti_term_levels_ibfk' => [
'table' => 'taxonomy_term_data',
'columns' => [
'tid' => 'tid',
],
],
],
];
return $schema;
}
/**
* {@inherit_doc}
*
* As Foreign keys are not directly supported with Database API, hence adding
* Foreign key constraint manually.
*/
function hierarchical_taxonomy_importer_install() {
// Query to alter mapping table and add a constraint.
$query = "ALTER TABLE {hti_term_levels} ADD CONSTRAINT " . " FOREIGN KEY(tid)" . " REFERENCES " . " {taxonomy_term_data}(tid)" . " ON DELETE CASCADE";
try {
\Drupal\Core\Database\Database::getConnection()
->query($query);
} catch (\Exception $ex) {
print $ex
->getMessage();
exit;
}
}
Functions
Name | Description |
---|---|
hierarchical_taxonomy_importer_install | {@inherit_doc} |
hierarchical_taxonomy_importer_schema | {@inherit_doc}. |