Security update for Core, with self-updated composer
[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  * )
16  */
17 class VariableMultiRow extends DrupalSqlBase {
18
19   /**
20    * {@inheritdoc}
21    */
22   public function query() {
23     return $this->select('variable', 'v')
24       ->fields('v', ['name', 'value'])
25       // Cast scalars to array so we can consistently use an IN condition.
26       ->condition('name', (array) $this->configuration['variables'], 'IN');
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public function fields() {
33     return [
34       'name' => $this->t('Name'),
35       'value' => $this->t('Value'),
36     ];
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function prepareRow(Row $row) {
43     if ($value = $row->getSourceProperty('value')) {
44       $row->setSourceProperty('value', unserialize($value));
45     }
46     return parent::prepareRow($row);
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function getIds() {
53     $ids['name']['type'] = 'string';
54     return $ids;
55   }
56
57 }