You are here

protected function FileDealerBase::getFileFieldData in Media Migration 8

Get the name of the file fields from the source database.

Parameters

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

bool $field_names_only: Whether only the name of the file fields should be returned. Defaults to TRUE.

Return value

array The array of the available file fields.

2 calls to FileDealerBase::getFileFieldData()
Fallback::prepareMediaSourceFieldInstanceRow in src/Plugin/media_migration/file/Fallback.php
FileDealerBase::getFileData in src/FileDealerBase.php
Returns display and description properties of the specified file.

File

src/FileDealerBase.php, line 31

Class

FileDealerBase
Base implementation of file dealer plugins.

Namespace

Drupal\media_migration

Code

protected function getFileFieldData(Connection $connection, bool $field_names_only = TRUE) : array {
  $field_query = $connection
    ->select('field_config', 'fs')
    ->fields('fs', [
    'field_name',
  ])
    ->condition('fs.type', 'file')
    ->condition('fs.active', 1)
    ->condition('fs.deleted', 0)
    ->condition('fs.storage_active', 1)
    ->condition('fi.deleted', 0);
  $field_query
    ->join('field_config_instance', 'fi', 'fs.id = fi.field_id');
  if ($field_names_only) {
    return array_keys($field_query
      ->execute()
      ->fetchAllAssoc('field_name'));
  }
  $field_query
    ->addField('fs', 'data', 'field_storage_data');
  $field_query
    ->addField('fi', 'data', 'field_instance_data');
  $fields_data = [];
  foreach ($field_query
    ->execute()
    ->fetchAll(\PDO::FETCH_ASSOC) as $item) {
    foreach ([
      'field_storage_data',
      'field_instance_data',
    ] as $data_key) {
      $item[$data_key] = unserialize($item[$data_key]);
    }
    $fields_data[] = $item;
  }
  return $fields_data;
}