3 namespace Drupal\file\Plugin\migrate\source\d6;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
9 * Drupal 6 file source from database.
15 class File extends DrupalSqlBase {
18 * The file directory path.
25 * The temporary file path.
29 protected $tempFilePath;
32 * Flag for private or public file storage.
41 public function query() {
42 return $this->select('files', '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)
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') . '/';
59 // FILE_DOWNLOADS_PUBLIC == 1 and FILE_DOWNLOADS_PRIVATE == 2.
60 $this->isPublic = $this->variableGet('file_downloads', 1) == 1;
61 return parent::initializeIterator();
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);
77 public function fields() {
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.'),
93 public function getIds() {
94 $ids['fid']['type'] = 'integer';