Version 1
[yaffs-website] / web / core / modules / file / src / Plugin / migrate / source / d6 / Upload.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 upload source from database.
10  *
11  * @MigrateSource(
12  *   id = "d6_upload",
13  *   source_provider = "upload"
14  * )
15  */
16 class Upload extends DrupalSqlBase {
17
18   /**
19    * The join options between the node and the upload table.
20    */
21   const JOIN = 'n.nid = u.nid AND n.vid = u.vid';
22
23   /**
24    * {@inheritdoc}
25    */
26   public function query() {
27     $query = $this->select('upload', 'u')
28       ->distinct()
29       ->fields('u', ['nid', 'vid']);
30     $query->innerJoin('node', 'n', static::JOIN);
31     $query->addField('n', 'type');
32     return $query;
33   }
34
35   /**
36    * {@inheritdoc}
37    */
38   public function prepareRow(Row $row) {
39     $query = $this->select('upload', 'u')
40       ->fields('u', ['fid', 'description', 'list'])
41       ->condition('u.nid', $row->getSourceProperty('nid'))
42       ->orderBy('u.weight');
43     $query->innerJoin('node', 'n', static::JOIN);
44     $row->setSourceProperty('upload', $query->execute()->fetchAll());
45     return parent::prepareRow($row);
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function fields() {
52     return [
53       'fid' => $this->t('The file Id.'),
54       'nid' => $this->t('The node Id.'),
55       'vid' => $this->t('The version Id.'),
56       'type' => $this->t('The node type'),
57       'description' => $this->t('The file description.'),
58       'list' => $this->t('Whether the list should be visible on the node page.'),
59       'weight' => $this->t('The file weight.'),
60     ];
61   }
62
63   /**
64    * {@inheritdoc}
65    */
66   public function getIds() {
67     $ids['vid']['type'] = 'integer';
68     $ids['vid']['alias'] = 'u';
69     return $ids;
70   }
71
72 }