Unverified Commit b999b138 authored by alexpott's avatar alexpott

Issue #3183226 by Matroskeen, oldspot, quietone: Specify table alias for File...

Issue #3183226 by Matroskeen, oldspot, quietone: Specify table alias for File migration source plugin getIds method

(cherry picked from commit 118b1c33)
parent c2e9bd2f
......@@ -42,8 +42,8 @@ class File extends DrupalSqlBase {
public function query() {
return $this->select('files', 'f')
->fields('f')
->condition('filepath', '/tmp%', 'NOT LIKE')
->orderBy('timestamp')
->condition('f.filepath', '/tmp%', 'NOT LIKE')
->orderBy('f.timestamp')
// If two or more files have the same timestamp, they'll end up in a
// non-deterministic order. Ordering by fid (or any other unique field)
// will prevent this.
......@@ -95,6 +95,7 @@ public function fields() {
*/
public function getIds() {
$ids['fid']['type'] = 'integer';
$ids['fid']['alias'] = 'f';
return $ids;
}
......
......@@ -42,7 +42,7 @@ class File extends DrupalSqlBase {
public function query() {
$query = $this->select('file_managed', 'f')
->fields('f')
->condition('uri', 'temporary://%', 'NOT LIKE')
->condition('f.uri', 'temporary://%', 'NOT LIKE')
->orderBy('f.timestamp');
// Filter by scheme(s), if configured.
......@@ -59,7 +59,7 @@ public function query() {
// Add conditions, uri LIKE 'public://%' OR uri LIKE 'private://%'.
$conditions = $this->getDatabase()->condition('OR');
foreach ($schemes as $scheme) {
$conditions->condition('uri', $scheme . '%', 'LIKE');
$conditions->condition('f.uri', $scheme . '%', 'LIKE');
}
$query->condition($conditions);
}
......@@ -112,6 +112,7 @@ public function fields() {
*/
public function getIds() {
$ids['fid']['type'] = 'integer';
$ids['fid']['alias'] = 'f';
return $ids;
}
......
name: 'File test getIds'
type: module
description: 'Provides file source plugin restricted to used files.'
package: Testing
version: VERSION
dependencies:
- drupal:file
id: d7_file_used
migration_tags:
- Drupal 7
- Content
source:
plugin: d7_file_used
scheme: public
constants:
source_base_path: ''
process:
fid: fid
filename: filename
source_full_path:
-
plugin: concat
delimiter: /
source:
- constants/source_base_path
- filepath
-
plugin: urlencode
uri:
plugin: file_copy
source:
- '@source_full_path'
- uri
filemime: filemime
status: status
created: timestamp
changed: timestamp
uid: uid
destination:
plugin: entity:file
<?php
namespace Drupal\file_test_get_ids\Plugin\migrate\source\d7;
use Drupal\file\Plugin\migrate\source\d7\File;
/**
* Drupal 7 file source from database restricted to used files.
*
* @MigrateSource(
* id = "d7_file_used",
* source_module = "file"
* )
*/
class FileUsed extends File {
/**
* {@inheritdoc}
*/
public function query() {
$query = parent::query();
// Join on file_usage table to only migrate used files.
$query->innerJoin('file_usage', 'fu', 'f.fid = fu.fid');
return $query;
}
}
<?php
namespace Drupal\Tests\file\Kernel\Migrate\d7;
/**
* Tests the migration of used files.
*
* @group file
*/
class MigrateFileGetIdsTest extends MigrateFileTest {
/**
* {@inheritdoc}
*/
protected static $modules = ['file', 'file_test_get_ids'];
/**
* {@inheritdoc}
*/
protected function getFileMigrationInfo() {
$migration_info = parent::getFileMigrationInfo();
$migration_info['plugin_id'] = 'd7_file_used';
return $migration_info;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment