4d03e5f5f92ca2100d01ea952cf46b766644c37e
[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_module = "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     $query->addField('n', 'language');
33     return $query;
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function prepareRow(Row $row) {
40     $query = $this->select('upload', 'u')
41       ->fields('u', ['fid', 'description', 'list'])
42       ->condition('u.nid', $row->getSourceProperty('nid'))
43       ->orderBy('u.weight');
44     $query->innerJoin('node', 'n', static::JOIN);
45     $row->setSourceProperty('upload', $query->execute()->fetchAll());
46     return parent::prepareRow($row);
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function fields() {
53     return [
54       'fid' => $this->t('The file Id.'),
55       'nid' => $this->t('The node Id.'),
56       'vid' => $this->t('The version Id.'),
57       'type' => $this->t('The node type'),
58       'language' => $this->t('The node language.'),
59       'description' => $this->t('The file description.'),
60       'list' => $this->t('Whether the list should be visible on the node page.'),
61       'weight' => $this->t('The file weight.'),
62     ];
63   }
64
65   /**
66    * {@inheritdoc}
67    */
68   public function getIds() {
69     $ids['vid']['type'] = 'integer';
70     $ids['vid']['alias'] = 'u';
71     return $ids;
72   }
73
74 }