You are here

public function File::query in Drupal 8

Same name in this branch
  1. 8 core/modules/file/src/Plugin/migrate/source/d6/File.php \Drupal\file\Plugin\migrate\source\d6\File::query()
  2. 8 core/modules/file/src/Plugin/migrate/source/d7/File.php \Drupal\file\Plugin\migrate\source\d7\File::query()
Same name and namespace in other branches
  1. 9 core/modules/file/src/Plugin/migrate/source/d7/File.php \Drupal\file\Plugin\migrate\source\d7\File::query()
  2. 10 core/modules/file/src/Plugin/migrate/source/d7/File.php \Drupal\file\Plugin\migrate\source\d7\File::query()

Return value

\Drupal\Core\Database\Query\SelectInterface

Overrides SqlBase::query

File

core/modules/file/src/Plugin/migrate/source/d7/File.php, line 43

Class

File
Drupal 7 file source from database.

Namespace

Drupal\file\Plugin\migrate\source\d7

Code

public function query() {
  $query = $this
    ->select('file_managed', 'f')
    ->fields('f')
    ->condition('uri', 'temporary://%', 'NOT LIKE')
    ->orderBy('f.timestamp');

  // Filter by scheme(s), if configured.
  if (isset($this->configuration['scheme'])) {
    $schemes = [];

    // Remove 'temporary' scheme.
    $valid_schemes = array_diff((array) $this->configuration['scheme'], [
      'temporary',
    ]);

    // Accept either a single scheme, or a list.
    foreach ((array) $valid_schemes as $scheme) {
      $schemes[] = rtrim($scheme) . '://';
    }
    $schemes = array_map([
      $this
        ->getDatabase(),
      'escapeLike',
    ], $schemes);

    // Add conditions, uri LIKE 'public://%' OR uri LIKE 'private://%'.
    $conditions = new Condition('OR');
    foreach ($schemes as $scheme) {
      $conditions
        ->condition('uri', $scheme . '%', 'LIKE');
    }
    $query
      ->condition($conditions);
  }
  return $query;
}