Last active
May 25, 2016 17:33
-
-
Save wluisi/7eb80fa07ffdafeb68d517cf570fea4d to your computer and use it in GitHub Desktop.
Node Blog Featured Image D8 Migration Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Contains \Drupal\my_module\Plugin\migrate\source\NodeBlogFeaturedImage. | |
*/ | |
namespace Drupal\my_module\Plugin\migrate\source; | |
use Drupal\file\Plugin\migrate\source\d6\File; | |
use Drupal\Core\Database\Query\Condition; | |
use Drupal\migrate\Row; | |
/** | |
* Blog Featured Image | |
* | |
* @MigrateSource( | |
* id = "my_module_blog_featured_image" | |
* ) | |
*/ | |
class NodeBlogFeaturedImage extends File { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function query() { | |
$query = $this->select('files', 'f'); | |
// Join data from 'content_type_blog', which is d6's way of storing field data. | |
$query->join('content_type_blog', 'ctb', 'ctb.field_blog_feature_img_fid = f.fid'); | |
// Join data from 'node' table | |
$query->join('node', 'n', 'n.nid = ctb.nid'); | |
$query->fields('f', ['fid', 'uid', 'filename', 'filepath', 'filemime', 'status', 'timestamp']) | |
->distinct() | |
->condition('n.type', 'blog') | |
->orderBy('n.changed', 'DESC'); | |
return $query; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment