UserPictureFile.php in Drupal 8
File
core/modules/user/src/Plugin/migrate/source/d6/UserPictureFile.php
View source
<?php
namespace Drupal\user\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
use Drupal\migrate\Row;
class UserPictureFile extends DrupalSqlBase {
protected $filePath;
protected $tempFilePath;
public function query() {
$query = $this
->select('users', 'u')
->condition('u.picture', '', '<>')
->fields('u', [
'uid',
'picture',
]);
return $query;
}
public function initializeIterator() {
$site_path = isset($this->configuration['site_path']) ? $this->configuration['site_path'] : 'sites/default';
$this->filePath = $this
->variableGet('file_directory_path', $site_path . '/files') . '/';
$this->tempFilePath = $this
->variableGet('file_directory_temp', '/tmp') . '/';
return parent::initializeIterator();
}
public function prepareRow(Row $row) {
$row
->setSourceProperty('filename', basename($row
->getSourceProperty('picture')));
$row
->setSourceProperty('file_directory_path', $this->filePath);
$row
->setSourceProperty('temp_directory_path', $this->tempFilePath);
return parent::prepareRow($row);
}
public function fields() {
return [
'picture' => "Path to the user's uploaded picture.",
'filename' => 'The picture filename.',
];
}
public function getIds() {
$ids['uid']['type'] = 'integer';
return $ids;
}
}