8952ffdf82bc65fb00c1460edfe463ffa5489fcf
[yaffs-website] / web / core / modules / user / src / Plugin / migrate / source / d6 / UserPictureFile.php
1 <?php
2
3 namespace Drupal\user\Plugin\migrate\source\d6;
4
5 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
6 use Drupal\migrate\Row;
7
8 /**
9  * Drupal 6 user picture source from database.
10  *
11  * @MigrateSource(
12  *   id = "d6_user_picture_file"
13  * )
14  */
15 class UserPictureFile extends DrupalSqlBase {
16
17   /**
18    * The file directory path.
19    *
20    * @var string
21    */
22   protected $filePath;
23
24   /**
25    * The temporary file path.
26    *
27    * @var string
28    */
29   protected $tempFilePath;
30
31   /**
32    * {@inheritdoc}
33    */
34   public function query() {
35     $query = $this->select('users', 'u')
36       ->condition('u.picture', '', '<>')
37       ->fields('u', ['uid', 'picture']);
38     return $query;
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public function initializeIterator() {
45     $site_path = isset($this->configuration['site_path']) ? $this->configuration['site_path'] : 'sites/default';
46     $this->filePath = $this->variableGet('file_directory_path', $site_path . '/files') . '/';
47     $this->tempFilePath = $this->variableGet('file_directory_temp', '/tmp') . '/';
48     return parent::initializeIterator();
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function prepareRow(Row $row) {
55     $row->setSourceProperty('filename', basename($row->getSourceProperty('picture')));
56     $row->setSourceProperty('file_directory_path', $this->filePath);
57     $row->setSourceProperty('temp_directory_path', $this->tempFilePath);
58     return parent::prepareRow($row);
59   }
60
61   /**
62    * {@inheritdoc}
63    */
64   public function fields() {
65     return [
66       'picture' => "Path to the user's uploaded picture.",
67       'filename' => 'The picture filename.',
68     ];
69   }
70   /**
71    * {@inheritdoc}
72    */
73   public function getIds() {
74     $ids['uid']['type'] = 'integer';
75     return $ids;
76   }
77
78 }