fix #8131 - chinese translations
[Pman.Core] / Import / Timezone.php
1 <?php
2
3
4
5 require_once 'Pman.php';
6
7 class Pman_Core_Import_Timezone extends Pman 
8 {
9     static $cli_desc = "Import timezone region name and area name to core_enum"; 
10     
11     static $cli_opts = array();
12
13     function getAuth()
14     {
15         $ff = HTML_FlexyFramework::get();
16         
17         if (!$ff->cli) {
18             die("cli only");
19         }
20     }
21     
22     function get($part = '', $opts=array())
23     {
24         $ce = DB_DataObject::factory('core_enum');
25         $ce->query("
26             SELECT
27                 *, TIME_FORMAT(TIMEDIFF(NOW(), CONVERT_TZ(NOW(), Name, 'UTC')), '%H:%i') as timeOffset
28             FROM
29                 mysql.time_zone_name
30             WHERE
31                 Name LIKE '%/%'
32                 AND
33                 Name NOT LIKE '%/%/%'
34                 AND
35                 Name NOT LIKE 'right%'
36                 AND
37                 Name NOT LIKE 'posix%'
38                 AND
39                 Name NOT LIKE 'Etc%'
40             ORDER BY
41                 SUBSTRING_INDEX(Name, '/', 1) ASC,
42                 timeoffset ASC,
43                 Name ASC
44         ");
45
46         $values = array();
47
48         $regions = array();
49         $areas = array();
50
51         while($ce->fetch()) {
52             $ar = explode('/', $ce->Name);
53             $region = $ar[0];
54             $area = str_replace('_', ' ', $ar[1]);
55
56             if(!in_array($region, $regions)) {
57                 $regions[] = $region;
58                 $values[] = "('Timezone.Region', '" . $region . "', 1, 0, 0, '" . $region . "', 0)";
59             }
60
61             if(!in_array($area, $areas)) {
62                 $areas[] = $area;
63                 $values[] = "('Timezone.Area', '" . $area . "', 1, 0, 0, '" . $area . "', 0)";
64             }
65         }
66
67         $sql = "
68             INSERT INTO
69                 core_enum (etype, name, active, seqid, seqmax, display_name, is_system_enum)
70             VALUES
71                 " . implode(", \n", $values) . "
72         ";
73
74         $ce = DB_DataObject::factory('core_enum');
75         $ce->query($sql);
76         
77         $this->jok('DONE');
78     }
79 }