3 namespace Drupal\migrate_drupal\Plugin\migrate\source\d7;
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Drupal\Core\State\StateInterface;
7 use Drupal\migrate\Plugin\MigrationInterface;
8 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
11 * Gets Drupal variable_store source from database.
14 * id = "d7_variable_translation",
15 * source_module = "i18n_variable",
18 class VariableTranslation extends DrupalSqlBase {
20 * The variable names to fetch.
29 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager) {
30 parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
31 $this->variables = $this->configuration['variables'];
37 protected function initializeIterator() {
38 return new \ArrayIterator($this->values());
42 * Return the values of the variables specified in the plugin configuration.
45 * An associative array where the keys are the variables specified in the
46 * plugin configuration and the values are the values found in the source.
47 * A key/value pair is added for the language code. Only those values are
48 * returned that are actually in the database.
50 protected function values() {
52 $result = $this->prepareQuery()->execute()->FetchAllAssoc('realm_key');
53 foreach ($result as $variable_store) {
54 $values[]['language'] = $variable_store['realm_key'];
56 $result = $this->prepareQuery()->execute()->FetchAll();
57 foreach ($result as $variable_store) {
58 foreach ($values as $key => $value) {
59 if ($values[$key]['language'] === $variable_store['realm_key']) {
60 if ($variable_store['serialized']) {
61 $values[$key][$variable_store['name']] = unserialize($variable_store['value']);
65 $values[$key][$variable_store['name']] = $variable_store['value'];
77 public function count($refresh = FALSE) {
78 return $this->initializeIterator()->count();
84 public function fields() {
85 return array_combine($this->variables, $this->variables);
91 public function getIds() {
92 $ids['language']['type'] = 'string';
99 public function query() {
100 return $this->select('variable_store', 'vs')
102 ->condition('realm', 'language')
103 ->condition('name', (array) $this->configuration['variables'], 'IN');