function menu_entity_index_update_8103 in Menu Entity Index 8
Adds extra indexes to menu_entity_index table.
File
- ./
menu_entity_index.install, line 195 - Hooks related to (un-)installation of Menu Entity Index module.
Code
function menu_entity_index_update_8103() {
$table = 'menu_entity_index';
$indexes = [
'target_id' => [
'target_id',
],
'target_type' => [
'target_type',
],
'target_langcode' => [
'target_langcode',
],
];
$schema = Database::getConnection()
->schema();
if (!$schema) {
return;
}
if (!$schema
->tableExists($table)) {
return;
}
$table_schema = [
'fields' => [
'target_type' => [
'description' => 'The entity type of the target entity.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
],
'target_id' => [
'description' => 'The entity id of the target entity.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
'target_langcode' => [
'description' => 'The language code of the target entity.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
],
],
'indexes' => [
'target_id' => [
'target_id',
],
'target_type' => [
'target_type',
],
'target_langcode' => [
'target_langcode',
],
],
];
foreach ($indexes as $index_name => $fields) {
if (!$schema
->indexExists($table, $index_name)) {
$schema
->addIndex($table, $index_name, $fields, $table_schema);
}
}
}