Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / migrate_drupal / src / Plugin / migrate / source / VariableMultiRow.php
1 <?php
2
3 namespace Drupal\migrate_drupal\Plugin\migrate\source;
4
5 use Drupal\migrate\Row;
6
7 /**
8  * Multiple variables source from database.
9  *
10  * Unlike the variable source plugin, this one returns one row per
11  * variable.
12  *
13  * @MigrateSource(
14  *   id = "variable_multirow",
15  *   source_module = "system",
16  * )
17  */
18 class VariableMultiRow extends DrupalSqlBase {
19
20   /**
21    * {@inheritdoc}
22    */
23   public function query() {
24     return $this->select('variable', 'v')
25       ->fields('v', ['name', 'value'])
26       // Cast scalars to array so we can consistently use an IN condition.
27       ->condition('name', (array) $this->configuration['variables'], 'IN');
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   public function fields() {
34     return [
35       'name' => $this->t('Name'),
36       'value' => $this->t('Value'),
37     ];
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function prepareRow(Row $row) {
44     if ($value = $row->getSourceProperty('value')) {
45       $row->setSourceProperty('value', unserialize($value));
46     }
47     return parent::prepareRow($row);
48   }
49
50   /**
51    * {@inheritdoc}
52    */
53   public function getIds() {
54     $ids['name']['type'] = 'string';
55     return $ids;
56   }
57
58 }