getTables example


  protected function generateScript(Connection $connection, array $schema_only = [], int $insert_count = 1000) {
    $tables = '';

    $schema_only_patterns = [];
    foreach ($schema_only as $match) {
      $schema_only_patterns[] = '/^' . $match . '$/';
    }

    foreach ($this->getTables($connection) as $table) {
      $schema = $this->getTableSchema($connection$table);
      // Check for schema only.       if (empty($schema_only_patterns) || preg_replace($schema_only_patterns, '', $table)) {
        $data = $this->getTableData($connection$table);
      }
      else {
        $data = [];
      }
      $tables .= $this->getTableScript($table$schema$data$insert_count);
    }
    $script = $this->getTemplate();
    
    // Remove all fields from the SELECT except the base id.     $fields = &$subquery->getFields();
    foreach (array_keys($fields) as $field_name) {
      // The base id for this subquery is stored in our definition.       if ($field_name != $this->definition['field']) {
        unset($fields[$field_name]);
      }
    }

    // Make every alias in the subquery safe within the outer query by     // appending a namespace to it, '_inner' by default.     $tables = &$subquery->getTables();
    foreach (array_keys($tables) as $table_name) {
      $tables[$table_name]['alias'] .= $this->subquery_namespace;
      // Namespace the join on every table.       if (isset($tables[$table_name]['condition'])) {
        $tables[$table_name]['condition'] = $this->conditionNamespace($tables[$table_name]['condition']);
      }
    }
    // Namespace fields.     foreach (array_keys($fields) as $field_name) {
      $fields[$field_name]['table'] .= $this->subquery_namespace;
      $fields[$field_name]['alias'] .= $this->subquery_namespace;
    }

    $join = $this->manager->createInstance('join_test', $configuration);
    $this->assertInstanceOf(JoinTestPlugin::class$join);

    $rand_int = rand(0, 1000);
    $join->setJoinValue($rand_int);

    $query = Database::getConnection()->select('views_test_data');
    $table = ['alias' => 'users_field_data'];
    $join->buildJoin($query$table$view->query);

    $tables = $query->getTables();
    $join_info = $tables['users_field_data'];
    $this->assertStringContainsString("views_test_data.uid = $rand_int", $join_info['condition'], 'Make sure that the custom join plugin can extend the join base and alter the result.');
  }

  /** * Tests the join plugin base. */
  public function testBasePlugin() {

    // Setup a simple join and test the result sql.     $view = Views::getView('test_view');
    
/** * Tests that countQuery removes 'all_fields' statements and ordering clauses. */
  public function testCountQueryRemovals() {
    $query = $this->connection->select('test');
    $query->fields('test');
    $query->orderBy('name');
    $count = $query->countQuery();

    // Check that the 'all_fields' statement is handled properly.     $tables = $query->getTables();
    $this->assertEquals(1, $tables['test']['all_fields'], 'Query correctly sets \'all_fields\' statement.');
    $tables = $count->getTables();
    $this->assertFalse(isset($tables['test']['all_fields']), 'Count query correctly unsets \'all_fields\' statement.');

    // Check that the ordering clause is handled properly.     $orderby = $query->getOrderBy();
    // The orderby string is different for PostgreSQL.     // @see Drupal\pgsql\Driver\Database\pgsql\Select::orderBy()     $db_type = Database::getConnection()->databaseType();
    $this->assertEquals($db_type == 'pgsql' ? 'ASC NULLS FIRST' : 'ASC', $orderby['name'], 'Query correctly sets ordering clause.');
    $orderby = $count->getOrderBy();
    
  $media_entities_to_hide = [1, 3];

  // In this example, we're only interested in applying our media access   // restrictions to SELECT queries. hook_media_access() can be used to apply   // access control to 'update' and 'delete' operations.   if (!($query instanceof SelectInterface)) {
    return;
  }

  // The tables in the query. This can include media entity tables and other   // tables. Tables might be joined more than once, with aliases.   $query_tables = $query->getTables();

  // The tables belonging to media entity storage.   $table_mapping = \Drupal::entityTypeManager()->getStorage('media')->getTableMapping();
  $media_tables = $table_mapping->getTableNames();

  // For each table in the query, if it's a media entity storage table, add a   // condition to filter out records belonging to a media entity that we wish   // to hide.   foreach ($query_tables as $alias => $info) {
    // Skip over subqueries.     if ($info['table'] instanceof SelectInterface) {
      
    foreach (Node::loadMultiple() as $node) {
      $node->delete();
    }
    \Drupal::service('module_installer')->uninstall(['content_translation', 'language']);

    $view = Views::getView('taxonomy_term');
    $view->initDisplay();
    $view->setArguments([$term->id()]);
    $view->build();
    /** @var \Drupal\Core\Database\Query\Select $query */
    $query = $view->build_info['query'];
    $tables = $query->getTables();

    // Ensure that the join to node_field_data is not added by default.     $this->assertEquals(['node_field_data', 'taxonomy_index']array_keys($tables));
    // Ensure that the filter to the language column is not there by default.     $condition = $query->conditions();
    // We only want to check the no. of conditions in the query.     unset($condition['#conjunction']);
    $this->assertCount(1, $condition);

    // Clear permissions for anonymous users to check access for default views.     Role::load(RoleInterface::ANONYMOUS_ID)->revokePermission('access content')->save();

    
/** * {@inheritdoc} */
  public function DgetGroupBy() {
    return $this->query->getGroupBy();
  }

  /** * {@inheritdoc} */
  public function DgetTables() {
    return $this->query->getTables();
  }

  /** * {@inheritdoc} */
  public function DgetUnion() {
    return $this->query->getUnion();
  }

  /** * {@inheritdoc} */
return $build;
  }

  /** * Adds the configured rankings to the search query. * * @param $query * A query object that has been extended with the Search DB Extender. */
  protected function addNodeRankings(SelectExtender $query) {
    if ($ranking = $this->getRankings()) {
      $tables = &$query->getTables();
      foreach ($ranking as $rank => $values) {
        if (isset($this->configuration['rankings'][$rank]) && !empty($this->configuration['rankings'][$rank])) {
          $node_rank = $this->configuration['rankings'][$rank];
          // If the table defined in the ranking isn't already joined, then add it.           if (isset($values['join']) && !isset($tables[$values['join']['alias']])) {
            $query->addJoin($values['join']['type']$values['join']['table']$values['join']['alias']$values['join']['on']);
          }
          $arguments = $values['arguments'] ?? [];
          $query->addScore($values['score']$arguments$node_rank);
        }
      }
    }

  public function DgetTables();

  /** * Returns a reference to the union queries for this query. * * This includes queries for UNION, UNION ALL, and UNION DISTINCT. * * Because this method returns by reference, alter hooks may edit the tables * array directly to make their changes. If just adding union queries, * however, the use of the union() method is preferred. * * Note that this method must be called by reference as well: * * @code * $fields =& $query->getUnion(); * @endcode * * @return array * A reference to the union query array structure. */

  protected function getSqlField($field$langcode) {
    if (!isset($this->tables)) {
      $this->tables = $this->getTables($this->sqlQuery);
    }
    $base_property = "base_table.$field";
    if (isset($this->sqlFields[$base_property])) {
      return $base_property;
    }
    else {
      return $this->tables->addField($field, 'LEFT', $langcode);
    }
  }

  /** * Determines whether the query requires GROUP BY and ORDER BY MIN/MAX. * * @return bool */

  protected function assertQueriesTermAccessTag(ViewExecutable $view, bool $hasTag): void {
    $main_query = $view->build_info['query'];
    $count_query = $view->build_info['count_query'];

    foreach ([$main_query$count_query] as $query) {
      $tables = $query->getTables();
      foreach ($tables as $join_table) {
        if (is_object($join_table['table'])) {
          $this->assertSame($join_table['table']->hasTag('taxonomy_term_access')$hasTag);
        }
      }
    }
  }

}


    return $result;
  }

  /** * {@inheritdoc} */
  public function entityQueryAlter(SelectInterface $query) {
    parent::entityQueryAlter($query);

    $tables = $query->getTables();
    $data_table = 'comment_field_data';
    if (!isset($tables['comment_field_data']['alias'])) {
      // If no conditions join against the comment data table, it should be       // joined manually to allow node access processing.       $query->innerJoin($data_table, NULL, "[base_table].[cid] = [$data_table].[cid] AND [$data_table].[default_langcode] = 1");
    }

    // Historically, comments were always linked to 'node' entities, but that is     // no longer the case, as the 'node' module might not even be enabled.     // Comments can now be linked to any entity and they can also be referenced     // by other entities, so we won't have a single table to join to. That
/** * {@inheritdoc} */
  public function DgetGroupBy() {
    return $this->group;
  }

  /** * {@inheritdoc} */
  public function DgetTables() {
    return $this->tables;
  }

  /** * {@inheritdoc} */
  public function DgetUnion() {
    return $this->union;
  }

  /** * {@inheritdoc} */
return $menu;
    }

    private function createTables(array $types, bool $destructive): void
    {
        $con = $this->modelManager->getConnection();
        $currentSchema = $con->getSchemaManager()->createSchema();
        $schema = clone $currentSchema;

        // Mark all content type to be deleted, hopefully they will be redefined in the next step         foreach ($schema->getTables() as $table) {
            if (strpos($table->getName(), 's_custom_') === 0) {
                $schema->dropTable($table->getName());
            }
        }

        // Create all tables         foreach ($types as $type) {
            $myTable = $schema->createTable($type->getTableName());
            $myTable->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]);
            $myTable->setPrimaryKey(['id']);

            

        $platform = $this->connection->getDatabasePlatform();
        if (!$platform instanceof AbstractPlatform) {
            throw new \RuntimeException('Database platform can not be detected');
        }

        return $platform;
    }

    private function cleanup(Schema $schema): void
    {
        foreach ($schema->getTables() as $table) {
            if ($table->getComment() === self::COMMENT) {
                $schema->dropTable($table->getName());

                continue;
            }

            foreach ($table->getForeignKeys() as $foreignKey) {
                if (\str_starts_with($foreignKey->getName(), 'fk_ce_')) {
                    $table->removeForeignKey($foreignKey->getName());
                }
            }

            
Home | Imprint | This part of the site doesn't use cookies.