Version 1
[yaffs-website] / web / core / modules / file / src / Plugin / migrate / source / d6 / File.php
1 <?php
2
3 namespace Drupal\file\Plugin\migrate\source\d6;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
7
8 /**
9  * Drupal 6 file source from database.
10  *
11  * @MigrateSource(
12  *   id = "d6_file"
13  * )
14  */
15 class File 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    * Flag for private or public file storage.
33    *
34    * @var bool
35    */
36   protected $isPublic;
37
38   /**
39    * {@inheritdoc}
40    */
41   public function query() {
42     return $this->select('files', 'f')
43       ->fields('f')
44       ->orderBy('timestamp')
45       // If two or more files have the same timestamp, they'll end up in a
46       // non-deterministic order. Ordering by fid (or any other unique field)
47       // will prevent this.
48       ->orderBy('f.fid');
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   protected function initializeIterator() {
55     $site_path = isset($this->configuration['site_path']) ? $this->configuration['site_path'] : 'sites/default';
56     $this->filePath = $this->variableGet('file_directory_path', $site_path . '/files') . '/';
57     $this->tempFilePath = $this->variableGet('file_directory_temp', '/tmp') . '/';
58
59     // FILE_DOWNLOADS_PUBLIC == 1 and FILE_DOWNLOADS_PRIVATE == 2.
60     $this->isPublic = $this->variableGet('file_downloads', 1) == 1;
61     return parent::initializeIterator();
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   public function prepareRow(Row $row) {
68     $row->setSourceProperty('file_directory_path', $this->filePath);
69     $row->setSourceProperty('temp_directory_path', $this->tempFilePath);
70     $row->setSourceProperty('is_public', $this->isPublic);
71     return parent::prepareRow($row);
72   }
73
74   /**
75    * {@inheritdoc}
76    */
77   public function fields() {
78     return [
79       'fid' => $this->t('File ID'),
80       'uid' => $this->t('The {users}.uid who added the file. If set to 0, this file was added by an anonymous user.'),
81       'filename' => $this->t('File name'),
82       'filepath' => $this->t('File path'),
83       'filemime' => $this->t('File MIME Type'),
84       'status' => $this->t('The published status of a file.'),
85       'timestamp' => $this->t('The time that the file was added.'),
86       'file_directory_path' => $this->t('The Drupal files path.'),
87       'is_public' => $this->t('TRUE if the files directory is public otherwise FALSE.'),
88     ];
89   }
90   /**
91    * {@inheritdoc}
92    */
93   public function getIds() {
94     $ids['fid']['type'] = 'integer';
95     return $ids;
96   }
97
98 }