Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
13 / 13 |
Variable | |
100.00% |
1 / 1 |
|
100.00% |
7 / 7 |
7 | |
100.00% |
13 / 13 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
initializeIterator | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
values | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
count | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
fields | |
100.00% |
1 / 1 |
1 | |
100.00% |
0 / 0 |
|||
query | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
getIds | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\migrate_drupal\Plugin\migrate\source\Variable. | |
*/ | |
namespace Drupal\migrate_drupal\Plugin\migrate\source; | |
use Drupal\Core\Entity\EntityManagerInterface; | |
use Drupal\Core\State\StateInterface; | |
use Drupal\migrate\Entity\MigrationInterface; | |
/** | |
* Drupal variable source from database. | |
* | |
* This source class always returns a single row and as such is not a good | |
* example for any normal source class returning multiple rows. | |
* | |
* @MigrateSource( | |
* id = "variable" | |
* ) | |
*/ | |
class Variable extends DrupalSqlBase { | |
/** | |
* The variable names to fetch. | |
* | |
* @var array | |
*/ | |
protected $variables; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager) { | |
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager); | |
$this->variables = $this->configuration['variables']; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function initializeIterator() { | |
return new \ArrayIterator(array($this->values())); | |
} | |
/** | |
* Return the values of the variables specified in the plugin configuration. | |
* | |
* @return array | |
* An associative array where the keys are the variables specified in the | |
* plugin configuration and the values are the values found in the source. | |
* Only those values are returned that are actually in the database. | |
*/ | |
protected function values() { | |
// Create an ID field so we can record migration in the map table. | |
// Arbitrarily, use the first variable name. | |
$values['id'] = reset($this->variables); | |
return $values + array_map('unserialize', $this->prepareQuery()->execute()->fetchAllKeyed()); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function count() { | |
return intval($this->query()->countQuery()->execute()->fetchField() > 0); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function fields() { | |
return array_combine($this->variables, $this->variables); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function query() { | |
return $this->getDatabase() | |
->select('variable', 'v') | |
->fields('v', array('name', 'value')) | |
->condition('name', $this->variables, 'IN'); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getIds() { | |
$ids['id']['type'] = 'string'; | |
return $ids; | |
} | |
} |