You are here

protected function MediaMigrationDatabaseTrait::getFileEntityBaseQuery in Media Migration 8

Returns a base query for file entity types.

Parameters

\Drupal\Core\Database\Connection|null $connection: Database connection of the source Drupal 7 instance.

bool $distinct: Base query should use distinct.

Return value

\Drupal\Core\Database\Query\SelectInterface The base query.

1 call to MediaMigrationDatabaseTrait::getFileEntityBaseQuery()
FileEntityConfigSourceBase::query in src/Plugin/migrate/source/d7/FileEntityConfigSourceBase.php

File

src/Plugin/migrate/source/d7/MediaMigrationDatabaseTrait.php, line 57

Class

MediaMigrationDatabaseTrait
MediaMigrationDatabaseTrait.

Namespace

Drupal\media_migration\Plugin\migrate\source\d7

Code

protected function getFileEntityBaseQuery($connection = NULL, bool $distinct = TRUE) {
  $db = $connection ?? $this
    ->getDatabase();
  assert($db instanceof Connection);
  $options = [
    'fetch' => \PDO::FETCH_ASSOC,
  ];
  $query = $db
    ->select('file_managed', 'fm', $options);
  if ($distinct) {
    $query
      ->distinct();
  }
  $query
    ->fields('fm', [
    'type',
  ])
    ->condition('fm.status', TRUE)
    ->condition('fm.uri', 'temporary://%', 'NOT LIKE')
    ->condition('fm.type', 'undefined', '<>');
  $query
    ->addExpression($this
    ->getSchemeExpression($db), 'scheme');

  // Omit all files that are used solely for a user picture: they do not
  // belong in Drupal's media library.
  $query
    ->condition('fm.fid', $this
    ->getUserPictureOnlyFidsQuery($db), 'NOT IN');
  $query
    ->condition('fm.fid', $this
    ->getWebformOrUserPictureOnlyFidsQuery($db), 'NOT IN');
  return $query;
}