You are here

protected function MediaMigrationDatabaseTrait::getUserPictureOnlyFidsQuery in Media Migration 8

Returns the subquery for the user picture-only file IDs.

Parameters

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

Return value

\Drupal\Core\Database\Query\SelectInterface The query to get the FIDs of files that are used only as a user picture.

2 calls to MediaMigrationDatabaseTrait::getUserPictureOnlyFidsQuery()
MediaMigrationDatabaseTrait::getFileEntityBaseQuery in src/Plugin/migrate/source/d7/MediaMigrationDatabaseTrait.php
Returns a base query for file entity types.
MediaMigrationDatabaseTrait::getFilePlainBaseQuery in src/Plugin/migrate/source/d7/MediaMigrationDatabaseTrait.php
Returns a base query for plain files.

File

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

Class

MediaMigrationDatabaseTrait
MediaMigrationDatabaseTrait.

Namespace

Drupal\media_migration\Plugin\migrate\source\d7

Code

protected function getUserPictureOnlyFidsQuery(Connection $connection) {
  $query = $connection
    ->select('users', 'u');
  $query
    ->leftJoin('file_usage', 'fu', 'fu.fid = u.picture');
  $query
    ->where('u.picture > 0');
  $query
    ->fields('fu', [
    'fid',
  ]);
  $query
    ->groupBy('fu.fid');
  $concat_expression = $connection instanceof PostgreSqlConnection ? "STRING_AGG(DISTINCT fu.type, ',')" : "GROUP_CONCAT(DISTINCT fu.type)";
  $query
    ->having("{$concat_expression} = :allowed_value_user_only OR {$concat_expression} = :allowed_value_user_webform_only OR {$concat_expression} = :allowed_value_webform_user_only", [
    ':allowed_value_user_only' => 'user',
    ':allowed_value_user_webform_only' => 'user,webform',
    ':allowed_value_webform_user_only' => 'webform,user',
  ]);
  return $query;
}