/**
  * Tests the views data generation.
  */
 public function testViewsData()
 {
     // Test that the field is not exposed to views, since contact_message
     // entities have no storage.
     $table_name = ContentEntityDatabaseStorage::_fieldTableName($this->field_storage);
     $data = $this->container->get('views.views_data')->get($table_name);
     $this->assertFalse($data, 'The field is not exposed to Views.');
 }
 /**
  * Initializes common information for a revision data table.
  *
  * @return array
  *   A partial schema array for the revision data table.
  */
 protected function initializeRevisionDataTable()
 {
     $entity_type_id = $this->entityType->id();
     $id_key = $this->entityType->getKey('id');
     $revision_key = $this->entityType->getKey('revision');
     $schema = array('description' => "The revision data table for {$entity_type_id} entities.", 'primary key' => array($revision_key, 'langcode'), 'indexes' => array(), 'foreign keys' => array($entity_type_id => array('table' => $this->storage->getBaseTable(), 'columns' => array($id_key => $id_key)), $entity_type_id . '__revision' => array('table' => $this->storage->getRevisionTable(), 'columns' => array($revision_key => $revision_key))));
     $this->addTableDefaults($schema);
     return $schema;
 }
 /**
  * {@inheritdoc}
  */
 public function getSchema()
 {
     $schema = parent::getSchema();
     // Marking the respective fields as NOT NULL makes the indexes more
     // performant.
     $schema['block_content']['fields']['info']['not null'] = TRUE;
     $schema['block_content']['unique keys'] += array('block_content__info' => array('info'));
     return $schema;
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function getSchema()
 {
     $schema = parent::getSchema();
     // Marking the respective fields as NOT NULL makes the indexes more
     // performant.
     $schema['aggregator_item']['fields']['timestamp']['not null'] = TRUE;
     $schema['aggregator_item']['indexes'] += array('aggregator_item__timestamp' => array('timestamp'));
     $schema['aggregator_item']['foreign keys'] += array('aggregator_item__aggregator_feed' => array('table' => 'aggregator_feed', 'columns' => array('fid' => 'fid')));
     return $schema;
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function getSchema()
 {
     $schema = parent::getSchema();
     // Marking the respective fields as NOT NULL makes the indexes more
     // performant.
     $schema['aggregator_feed']['fields']['url']['not null'] = TRUE;
     $schema['aggregator_feed']['fields']['queued']['not null'] = TRUE;
     $schema['aggregator_feed']['fields']['title']['not null'] = TRUE;
     $schema['aggregator_feed']['indexes'] += array('aggregator_feed__url' => array(array('url', 255)), 'aggregator_feed__queued' => array('queued'));
     $schema['aggregator_feed']['unique keys'] += array('aggregator_feed__title' => array('title'));
     return $schema;
 }
 /**
  * Tests groupby with filters.
  */
 public function testGroupByCountOnlyFilters()
 {
     // Check if GROUP BY and HAVING are included when a view
     // Doesn't display SUM, COUNT, MAX... functions in SELECT statement
     for ($x = 0; $x < 10; $x++) {
         $this->storage->create(array('name' => 'name1'))->save();
     }
     $view = Views::getView('test_group_by_in_filters');
     $this->executeView($view);
     $this->assertTrue(strpos($view->build_info['query'], 'GROUP BY'), 'Make sure that GROUP BY is in the query');
     $this->assertTrue(strpos($view->build_info['query'], 'HAVING'), 'Make sure that HAVING is in the query');
 }
Beispiel #7
0
 /**
  * {@inheritdoc}
  */
 public function getSchema()
 {
     $schema = parent::getSchema();
     // Marking the respective fields as NOT NULL makes the indexes more
     // performant.
     $schema['file_managed']['fields']['status']['not null'] = TRUE;
     $schema['file_managed']['fields']['changed']['not null'] = TRUE;
     $schema['file_managed']['fields']['uri']['not null'] = TRUE;
     // @todo There should be a 'binary' field type or setting.
     $schema['file_managed']['fields']['uri']['binary'] = TRUE;
     $schema['file_managed']['indexes'] += array('file__status' => array('status'), 'file__changed' => array('changed'));
     $schema['file_managed']['unique keys'] += array('file__uri' => array('uri'));
     return $schema;
 }
 /**
  * @covers ::doLoadMultiple
  * @covers ::buildCacheId
  * @covers ::getFromPersistentCache
  */
 public function testLoadMultiplePersistentCached()
 {
     $this->setUpModuleHandlerNoImplementations();
     $key = 'values:' . $this->entityTypeId . ':1';
     $id = 1;
     $entity = $this->getMockBuilder('\\Drupal\\Tests\\Core\\Entity\\ContentEntityDatabaseStorageTestEntityInterface')->getMockForAbstractClass();
     $entity->expects($this->any())->method('id')->will($this->returnValue($id));
     $this->entityType->expects($this->atLeastOnce())->method('isPersistentlyCacheable')->will($this->returnValue(TRUE));
     $this->entityType->expects($this->atLeastOnce())->method('id')->will($this->returnValue($this->entityTypeId));
     $this->entityType->expects($this->atLeastOnce())->method('getClass')->will($this->returnValue(get_class($entity)));
     $this->cache->expects($this->once())->method('getMultiple')->with(array($key))->will($this->returnValue(array($key => (object) array('data' => $entity))));
     $this->cache->expects($this->never())->method('set');
     $this->setUpEntityStorage();
     $entities = $this->entityStorage->loadMultiple(array($id));
     $this->assertEquals($entity, $entities[$id]);
 }
 /**
  * Tests the schema for revisionable, translatable entities.
  *
  * @covers ::__construct()
  * @covers ::getSchema()
  * @covers ::getTables()
  * @covers ::initializeDataTable()
  * @covers ::addTableDefaults()
  * @covers ::getEntityIndexName()
  * @covers ::initializeRevisionDataTable()
  * @covers ::processRevisionDataTable()
  */
 public function testGetSchemaRevisionableTranslatable()
 {
     $this->entityType = new ContentEntityType(array('id' => 'entity_test', 'entity_keys' => array('id' => 'id', 'revision' => 'revision_id')));
     $this->storage->expects($this->exactly(3))->method('getRevisionTable')->will($this->returnValue('entity_test_revision'));
     $this->storage->expects($this->once())->method('getDataTable')->will($this->returnValue('entity_test_field_data'));
     $this->storage->expects($this->once())->method('getRevisionDataTable')->will($this->returnValue('entity_test_revision_field_data'));
     $this->setUpStorageDefinition('revision_id', array('columns' => array('value' => array('type' => 'int'))));
     $this->setUpStorageDefinition('langcode', array('columns' => array('value' => array('type' => 'varchar'))));
     $this->setUpSchemaHandler();
     $table_mapping = new DefaultTableMapping($this->storageDefinitions);
     $table_mapping->setFieldNames('entity_test', array_keys($this->storageDefinitions));
     $table_mapping->setFieldNames('entity_test_revision', array_keys($this->storageDefinitions));
     $table_mapping->setFieldNames('entity_test_field_data', array_keys($this->storageDefinitions));
     $table_mapping->setFieldNames('entity_test_revision_field_data', array_keys($this->storageDefinitions));
     $this->storage->expects($this->once())->method('getTableMapping')->will($this->returnValue($table_mapping));
     $expected = array('entity_test' => array('description' => 'The base table for entity_test entities.', 'fields' => array('id' => array('description' => 'The id field.', 'type' => 'serial', 'not null' => TRUE), 'revision_id' => array('description' => 'The revision_id field.', 'type' => 'int'), 'langcode' => array('description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE)), 'primary key' => array('id'), 'unique keys' => array('entity_test__revision_id' => array('revision_id')), 'indexes' => array(), 'foreign keys' => array('entity_test__revision' => array('table' => 'entity_test_revision', 'columns' => array('revision_id' => 'revision_id')))), 'entity_test_revision' => array('description' => 'The revision table for entity_test entities.', 'fields' => array('id' => array('description' => 'The id field.', 'type' => 'int', 'not null' => TRUE), 'revision_id' => array('description' => 'The revision_id field.', 'type' => 'serial'), 'langcode' => array('description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE)), 'primary key' => array('revision_id'), 'unique keys' => array(), 'indexes' => array('entity_test__id' => array('id')), 'foreign keys' => array('entity_test__revisioned' => array('table' => 'entity_test', 'columns' => array('id' => 'id')))), 'entity_test_field_data' => array('description' => 'The data table for entity_test entities.', 'fields' => array('id' => array('description' => 'The id field.', 'type' => 'int', 'not null' => TRUE), 'revision_id' => array('description' => 'The revision_id field.', 'type' => 'int'), 'langcode' => array('description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE)), 'primary key' => array('id', 'langcode'), 'unique keys' => array(), 'indexes' => array('entity_test__revision_id' => array('revision_id')), 'foreign keys' => array('entity_test' => array('table' => 'entity_test', 'columns' => array('id' => 'id')))), 'entity_test_revision_field_data' => array('description' => 'The revision data table for entity_test entities.', 'fields' => array('id' => array('description' => 'The id field.', 'type' => 'int', 'not null' => TRUE), 'revision_id' => array('description' => 'The revision_id field.', 'type' => 'int'), 'langcode' => array('description' => 'The langcode field.', 'type' => 'varchar', 'not null' => TRUE)), 'primary key' => array('revision_id', 'langcode'), 'unique keys' => array(), 'indexes' => array(), 'foreign keys' => array('entity_test' => array('table' => 'entity_test', 'columns' => array('id' => 'id')), 'entity_test__revision' => array('table' => 'entity_test_revision', 'columns' => array('revision_id' => 'revision_id')))));
     $actual = $this->schemaHandler->getSchema();
     $this->assertEquals($expected, $actual);
 }
Beispiel #10
0
 /**
  * {@inheritdoc}
  */
 public function getSchema()
 {
     $schema = parent::getSchema();
     // Marking the respective fields as NOT NULL makes the indexes more
     // performant.
     $schema['node_field_data']['fields']['changed']['not null'] = TRUE;
     $schema['node_field_data']['fields']['created']['not null'] = TRUE;
     $schema['node_field_data']['fields']['default_langcode']['not null'] = TRUE;
     $schema['node_field_data']['fields']['promote']['not null'] = TRUE;
     $schema['node_field_data']['fields']['status']['not null'] = TRUE;
     $schema['node_field_data']['fields']['sticky']['not null'] = TRUE;
     $schema['node_field_data']['fields']['title']['not null'] = TRUE;
     $schema['node_field_revision']['fields']['default_langcode']['not null'] = TRUE;
     // @todo Revisit index definitions in https://drupal.org/node/2015277.
     $schema['node_revision']['indexes'] += array('node__langcode' => array('langcode'));
     $schema['node_revision']['foreign keys'] += array('node__revision_author' => array('table' => 'users', 'columns' => array('revision_uid' => 'uid')));
     $schema['node_field_data']['indexes'] += array('node__changed' => array('changed'), 'node__created' => array('created'), 'node__default_langcode' => array('default_langcode'), 'node__langcode' => array('langcode'), 'node__frontpage' => array('promote', 'status', 'sticky', 'created'), 'node__status_type' => array('status', 'type', 'nid'), 'node__title_type' => array('title', array('type', 4)));
     $schema['node_field_revision']['indexes'] += array('node__default_langcode' => array('default_langcode'), 'node__langcode' => array('langcode'));
     return $schema;
 }
 /**
  * Checks whether field languages are correctly stored for the given entity.
  *
  * @param \Drupal\Core\Entity\ContentEntityInterface $entity
  *   The entity fields are attached to.
  * @param string $message
  *   (optional) A message to display with the assertion.
  */
 protected function assertFieldStorageLangcode(ContentEntityInterface $entity, $message = '')
 {
     $status = TRUE;
     $entity_type = $entity->getEntityTypeId();
     $id = $entity->id();
     $langcode = $entity->getUntranslated()->language()->id;
     $fields = array($this->field_name, $this->untranslatable_field_name);
     foreach ($fields as $field_name) {
         $field_storage = FieldStorageConfig::loadByName($entity_type, $field_name);
         $tables = array(ContentEntityDatabaseStorage::_fieldTableName($field_storage), ContentEntityDatabaseStorage::_fieldRevisionTableName($field_storage));
         foreach ($tables as $table) {
             $record = \Drupal::database()->select($table, 'f')->fields('f')->condition('f.entity_id', $id)->condition('f.revision_id', $id)->execute()->fetchObject();
             if ($record->langcode != $langcode) {
                 $status = FALSE;
                 break;
             }
         }
     }
     return $this->assertTrue($status, $message);
 }
Beispiel #12
0
 /**
  * Unit testing the views data structure.
  *
  * We check data structure for both node and node revision tables.
  */
 function testViewsData()
 {
     $views_data = $this->container->get('views.views_data');
     $data = array();
     // Check the table and the joins of the first field.
     // Attached to node only.
     $field_storage = $this->fieldStorages[0];
     $current_table = ContentEntityDatabaseStorage::_fieldTableName($field_storage);
     $revision_table = ContentEntityDatabaseStorage::_fieldRevisionTableName($field_storage);
     $data[$current_table] = $views_data->get($current_table);
     $data[$revision_table] = $views_data->get($revision_table);
     $this->assertTrue(isset($data[$current_table]));
     $this->assertTrue(isset($data[$revision_table]));
     // The node field should join against node.
     $this->assertTrue(isset($data[$current_table]['table']['join']['node']));
     $this->assertTrue(isset($data[$revision_table]['table']['join']['node_revision']));
     $expected_join = array('left_field' => 'nid', 'field' => 'entity_id', 'extra' => array(array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE)));
     $this->assertEqual($expected_join, $data[$current_table]['table']['join']['node']);
     $expected_join = array('left_field' => 'vid', 'field' => 'revision_id', 'extra' => array(array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE)));
     $this->assertEqual($expected_join, $data[$revision_table]['table']['join']['node_revision']);
 }
 /**
  * Tests table name generation.
  */
 public function testTableNames()
 {
     // Note: we need to test entity types with long names. We therefore use
     // fields on imaginary entity types (works as long as we don't actually save
     // them), and just check the generated table names.
     // Short entity type and field name.
     $entity_type = 'short_entity_type';
     $field_name = 'short_field_name';
     $field_storage = entity_create('field_storage_config', array('entity_type' => $entity_type, 'name' => $field_name, 'type' => 'test_field'));
     $expected = 'short_entity_type__short_field_name';
     $this->assertEqual(ContentEntityDatabaseStorage::_fieldTableName($field_storage), $expected);
     $expected = 'short_entity_type_revision__short_field_name';
     $this->assertEqual(ContentEntityDatabaseStorage::_fieldRevisionTableName($field_storage), $expected);
     // Short entity type, long field name
     $entity_type = 'short_entity_type';
     $field_name = 'long_field_name_abcdefghijklmnopqrstuvwxyz';
     $field_storage = entity_create('field_storage_config', array('entity_type' => $entity_type, 'name' => $field_name, 'type' => 'test_field'));
     $expected = 'short_entity_type__' . substr(hash('sha256', $field_storage->uuid()), 0, 10);
     $this->assertEqual(ContentEntityDatabaseStorage::_fieldTableName($field_storage), $expected);
     $expected = 'short_entity_type_r__' . substr(hash('sha256', $field_storage->uuid()), 0, 10);
     $this->assertEqual(ContentEntityDatabaseStorage::_fieldRevisionTableName($field_storage), $expected);
     // Long entity type, short field name
     $entity_type = 'long_entity_type_abcdefghijklmnopqrstuvwxyz';
     $field_name = 'short_field_name';
     $field_storage = entity_create('field_storage_config', array('entity_type' => $entity_type, 'name' => $field_name, 'type' => 'test_field'));
     $expected = 'long_entity_type_abcdefghijklmnopq__' . substr(hash('sha256', $field_storage->uuid()), 0, 10);
     $this->assertEqual(ContentEntityDatabaseStorage::_fieldTableName($field_storage), $expected);
     $expected = 'long_entity_type_abcdefghijklmnopq_r__' . substr(hash('sha256', $field_storage->uuid()), 0, 10);
     $this->assertEqual(ContentEntityDatabaseStorage::_fieldRevisionTableName($field_storage), $expected);
     // Long entity type and field name.
     $entity_type = 'long_entity_type_abcdefghijklmnopqrstuvwxyz';
     $field_name = 'long_field_name_abcdefghijklmnopqrstuvwxyz';
     $field_storage = entity_create('field_storage_config', array('entity_type' => $entity_type, 'name' => $field_name, 'type' => 'test_field'));
     $expected = 'long_entity_type_abcdefghijklmnopq__' . substr(hash('sha256', $field_storage->uuid()), 0, 10);
     $this->assertEqual(ContentEntityDatabaseStorage::_fieldTableName($field_storage), $expected);
     $expected = 'long_entity_type_abcdefghijklmnopq_r__' . substr(hash('sha256', $field_storage->uuid()), 0, 10);
     $this->assertEqual(ContentEntityDatabaseStorage::_fieldRevisionTableName($field_storage), $expected);
     // Try creating a second field and check there are no clashes.
     $field_storage2 = entity_create('field_storage_config', array('entity_type' => $entity_type, 'name' => $field_name . '2', 'type' => 'test_field'));
     $this->assertNotEqual(ContentEntityDatabaseStorage::_fieldTableName($field_storage), ContentEntityDatabaseStorage::_fieldTableName($field_storage2));
     $this->assertNotEqual(ContentEntityDatabaseStorage::_fieldRevisionTableName($field_storage), ContentEntityDatabaseStorage::_fieldRevisionTableName($field_storage2));
     // Deleted field.
     $field_storage = entity_create('field_storage_config', array('entity_type' => 'some_entity_type', 'name' => 'some_field_name', 'type' => 'test_field', 'deleted' => TRUE));
     $expected = 'field_deleted_data_' . substr(hash('sha256', $field_storage->uuid()), 0, 10);
     $this->assertEqual(ContentEntityDatabaseStorage::_fieldTableName($field_storage, TRUE), $expected);
     $expected = 'field_deleted_revision_' . substr(hash('sha256', $field_storage->uuid()), 0, 10);
     $this->assertEqual(ContentEntityDatabaseStorage::_fieldRevisionTableName($field_storage, TRUE), $expected);
 }
Beispiel #14
0
 /**
  * {@inheritdoc}
  */
 public function getSchema()
 {
     $schema = parent::getSchema();
     // Marking the respective fields as NOT NULL makes the indexes more
     // performant.
     $schema['users']['fields']['access']['not null'] = TRUE;
     $schema['users']['fields']['created']['not null'] = TRUE;
     $schema['users']['fields']['name']['not null'] = TRUE;
     // The "users" table does not use serial identifiers.
     $schema['users']['fields']['uid']['type'] = 'int';
     $schema['users']['indexes'] += array('user__access' => array('access'), 'user__created' => array('created'), 'user__mail' => array('mail'));
     $schema['users']['unique keys'] += array('user__name' => array('name'));
     $schema['users_roles'] = array('description' => 'Maps users to roles.', 'fields' => array('uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => 'Primary Key: {users}.uid for user.'), 'rid' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'description' => 'Primary Key: ID for the role.')), 'primary key' => array('uid', 'rid'), 'indexes' => array('rid' => array('rid')), 'foreign keys' => array('user' => array('table' => 'users', 'columns' => array('uid' => 'uid'))));
     return $schema;
 }
Beispiel #15
0
 /**
  * Called to determine what to tell the clicksorter.
  */
 public function clickSort($order)
 {
     // No column selected, can't continue.
     if (empty($this->options['click_sort_column'])) {
         return;
     }
     $this->ensureMyTable();
     $field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->definition['entity_type']);
     $field_storage = $field_storage_definitions[$this->definition['field_name']];
     $column = ContentEntityDatabaseStorage::_fieldColumnName($field_storage, $this->options['click_sort_column']);
     if (!isset($this->aliases[$column])) {
         // Column is not in query; add a sort on it (without adding the column).
         $this->aliases[$column] = $this->tableAlias . '.' . $column;
     }
     $this->query->addOrderBy(NULL, NULL, $order, $this->aliases[$column]);
 }
Beispiel #16
0
 /**
  * Verify that deleting an instance leaves the field data items in
  * the database and that the appropriate Field API functions can
  * operate on the deleted data and instance.
  *
  * This tests how EntityFieldQuery interacts with field instance deletion and
  * could be moved to FieldCrudTestCase, but depends on this class's setUp().
  */
 function testDeleteFieldInstance()
 {
     $bundle = reset($this->bundles);
     $field_storage = reset($this->fieldStorages);
     $field_name = $field_storage->name;
     $factory = \Drupal::service('entity.query');
     // There are 10 entities of this bundle.
     $found = $factory->get('entity_test')->condition('type', $bundle)->execute();
     $this->assertEqual(count($found), 10, 'Correct number of entities found before deleting');
     // Delete the instance.
     $instance = FieldInstanceConfig::loadByName($this->entity_type, $bundle, $field_storage->name);
     $instance->delete();
     // The instance still exists, deleted.
     $instances = entity_load_multiple_by_properties('field_instance_config', array('field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE));
     $this->assertEqual(count($instances), 1, 'There is one deleted instance');
     $instance = $instances[$instance->uuid()];
     $this->assertEqual($instance->bundle, $bundle, 'The deleted instance is for the correct bundle');
     // Check that the actual stored content did not change during delete.
     $schema = ContentEntityDatabaseStorage::_fieldSqlSchema($field_storage);
     $table = ContentEntityDatabaseStorage::_fieldTableName($field_storage);
     $column = ContentEntityDatabaseStorage::_fieldColumnName($field_storage, 'value');
     $result = db_select($table, 't')->fields('t', array_keys($schema[$table]['fields']))->execute();
     foreach ($result as $row) {
         $this->assertEqual($this->entities[$row->entity_id]->{$field_storage->name}->value, $row->{$column});
     }
     // There are 0 entities of this bundle with non-deleted data.
     $found = $factory->get('entity_test')->condition('type', $bundle)->condition("{$field_name}.deleted", 0)->execute();
     $this->assertFalse($found, 'No entities found after deleting');
     // There are 10 entities of this bundle when deleted fields are allowed, and
     // their values are correct.
     $found = $factory->get('entity_test')->condition('type', $bundle)->condition("{$field_name}.deleted", 1)->sort('id')->execute();
     $this->assertEqual(count($found), 10, 'Correct number of entities found after deleting');
     $this->assertFalse(array_diff($found, array_keys($this->entities)));
 }
Beispiel #17
0
 /**
  * {@inheritdoc}
  */
 public function getSchema()
 {
     $schema = parent::getSchema();
     // Marking the respective fields as NOT NULL makes the indexes more
     // performant.
     $schema['taxonomy_term_data']['fields']['weight']['not null'] = TRUE;
     $schema['taxonomy_term_data']['fields']['name']['not null'] = TRUE;
     unset($schema['taxonomy_term_data']['indexes']['field__vid']);
     unset($schema['taxonomy_term_data']['indexes']['field__description__format']);
     $schema['taxonomy_term_data']['indexes'] += array('taxonomy_term__tree' => array('vid', 'weight', 'name'), 'taxonomy_term__vid_name' => array('vid', 'name'), 'taxonomy_term__name' => array('name'));
     $schema['taxonomy_term_hierarchy'] = array('description' => 'Stores the hierarchical relationship between terms.', 'fields' => array('tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => 'Primary Key: The {taxonomy_term_data}.tid of the term.'), 'parent' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => "Primary Key: The {taxonomy_term_data}.tid of the term's parent. 0 indicates no parent.")), 'indexes' => array('parent' => array('parent')), 'foreign keys' => array('taxonomy_term_data' => array('table' => 'taxonomy_term_data', 'columns' => array('tid' => 'tid'))), 'primary key' => array('tid', 'parent'));
     $schema['taxonomy_index'] = array('description' => 'Maintains denormalized information about node/term relationships.', 'fields' => array('nid' => array('description' => 'The {node}.nid this record tracks.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), 'tid' => array('description' => 'The term ID.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), 'sticky' => array('description' => 'Boolean indicating whether the node is sticky.', 'type' => 'int', 'not null' => FALSE, 'default' => 0, 'size' => 'tiny'), 'created' => array('description' => 'The Unix timestamp when the node was created.', 'type' => 'int', 'not null' => TRUE, 'default' => 0)), 'primary key' => array('nid', 'tid'), 'indexes' => array('term_node' => array('tid', 'sticky', 'created')), 'foreign keys' => array('tracked_node' => array('table' => 'node', 'columns' => array('nid' => 'nid')), 'term' => array('table' => 'taxonomy_term_data', 'columns' => array('tid' => 'tid'))));
     return $schema;
 }
Beispiel #18
0
 /**
  * Join field table if necessary.
  *
  * @param $field_name
  *   Name of the field.
  * @return string
  * @throws \Drupal\Core\Entity\Query\QueryException
  */
 protected function ensureFieldTable($index_prefix, &$field, $type, $langcode, $base_table, $entity_id_field, $field_id_field)
 {
     $field_name = $field->getName();
     if (!isset($this->fieldTables[$index_prefix . $field_name])) {
         $table = $this->sqlQuery->getMetaData('age') == EntityStorageInterface::FIELD_LOAD_CURRENT ? ContentEntityDatabaseStorage::_fieldTableName($field) : ContentEntityDatabaseStorage::_fieldRevisionTableName($field);
         if ($field->getCardinality() != 1) {
             $this->sqlQuery->addMetaData('simple_query', FALSE);
         }
         $entity_type = $this->sqlQuery->getMetaData('entity_type');
         $this->fieldTables[$index_prefix . $field_name] = $this->addJoin($type, $table, "%alias.{$field_id_field} = {$base_table}.{$entity_id_field}", $langcode);
     }
     return $this->fieldTables[$index_prefix . $field_name];
 }
Beispiel #19
0
 /**
  * {@inheritdoc}
  */
 public function getSchema()
 {
     $schema = parent::getSchema();
     // Marking the respective fields as NOT NULL makes the indexes more
     // performant.
     $schema['comment_field_data']['fields']['created']['not null'] = TRUE;
     $schema['comment_field_data']['fields']['thread']['not null'] = TRUE;
     unset($schema['comment_field_data']['indexes']['comment_field__pid__target_id']);
     unset($schema['comment_field_data']['indexes']['comment_field__entity_id__target_id']);
     $schema['comment_field_data']['indexes'] += array('comment__status_pid' => array('pid', 'status'), 'comment__num_new' => array('entity_id', 'entity_type', 'comment_type', 'status', 'created', 'cid', 'thread'), 'comment__entity_langcode' => array('entity_id', 'entity_type', 'comment_type', 'default_langcode'), 'comment__created' => array('created'));
     $schema['comment_field_data']['foreign keys'] += array('comment__author' => array('table' => 'users', 'columns' => array('uid' => 'uid')));
     return $schema;
 }