0efae5d6b3d5f71ae34601d81837fc96507c4847
[yaffs-website] / web / core / modules / user / src / Plugin / migrate / process / d6 / UserUpdate7002.php
1 <?php
2
3 namespace Drupal\user\Plugin\migrate\process\d6;
4
5 use Drupal\migrate\MigrateExecutableInterface;
6 use Drupal\migrate\ProcessPluginBase;
7 use Drupal\migrate\Row;
8 use Drupal\Core\Config\Config;
9 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11
12 /**
13  * Converts user time zones from time zone offsets to time zone names.
14  *
15  * @MigrateProcessPlugin(
16  *   id = "user_update_7002"
17  * )
18  */
19 class UserUpdate7002 extends ProcessPluginBase implements ContainerFactoryPluginInterface {
20
21   /**
22    * System timezones.
23    *
24    * @var array
25    */
26   protected static $timezones;
27
28   /**
29    * Contains the system.theme configuration object.
30    *
31    * @var \Drupal\Core\Config\Config
32    */
33   protected $dateConfig;
34
35   /**
36    * {@inheritdoc}
37    */
38   public function __construct(array $configuration, $plugin_id, array $plugin_definition, Config $date_config) {
39     parent::__construct($configuration, $plugin_id, $plugin_definition);
40     $this->dateConfig = $date_config;
41     if (!isset(static::$timezones)) {
42       static::$timezones = system_time_zones();
43     }
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
50     return new static(
51       $configuration,
52       $plugin_id,
53       $plugin_definition,
54       $container->get('config.factory')->get('system.date')
55     );
56   }
57   /**
58    * {@inheritdoc}
59    */
60   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
61     $timezone = NULL;
62
63     if ($row->hasSourceProperty('timezone_name')) {
64       if (isset(static::$timezones[$row->getSourceProperty('timezone_name')])) {
65         $timezone = $row->getSourceProperty('timezone_name');
66       }
67     }
68     if (!$timezone && $row->hasSourceProperty('event_timezone')) {
69       if (isset(static::$timezones[$row->getSourceProperty('event_timezone')])) {
70         $timezone = $row->getSourceProperty('event_timezone');
71       }
72     }
73
74     if ($timezone === NULL) {
75       $timezone = $this->dateConfig->get('timezone.default');
76     }
77     return $timezone;
78   }
79
80 }