fix #8131 - chinese translations master
authorAlan <alan@roojs.com>
Thu, 18 Apr 2024 04:19:57 +0000 (12:19 +0800)
committerAlan <alan@roojs.com>
Thu, 18 Apr 2024 04:19:57 +0000 (12:19 +0800)
Import/Timezone.php [new file with mode: 0644]

diff --git a/Import/Timezone.php b/Import/Timezone.php
new file mode 100644 (file)
index 0000000..5c0f4b9
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+
+
+
+require_once 'Pman.php';
+
+class Pman_Core_Import_Timezone extends Pman 
+{
+    static $cli_desc = "Import timezone region name and area name to core_enum"; 
+    
+    static $cli_opts = array();
+
+    function getAuth()
+    {
+        $ff = HTML_FlexyFramework::get();
+        
+        if (!$ff->cli) {
+            die("cli only");
+        }
+    }
+    
+    function get($part = '', $opts=array())
+    {
+        $ce = DB_DataObject::factory('core_enum');
+        $ce->query("
+            SELECT
+                *, TIME_FORMAT(TIMEDIFF(NOW(), CONVERT_TZ(NOW(), Name, 'UTC')), '%H:%i') as timeOffset
+            FROM
+                mysql.time_zone_name
+            WHERE
+                Name LIKE '%/%'
+                AND
+                Name NOT LIKE '%/%/%'
+                AND
+                Name NOT LIKE 'right%'
+                AND
+                Name NOT LIKE 'posix%'
+                AND
+                Name NOT LIKE 'Etc%'
+            ORDER BY
+                SUBSTRING_INDEX(Name, '/', 1) ASC,
+                timeoffset ASC,
+                Name ASC
+        ");
+
+        $values = array();
+
+        $regions = array();
+        $areas = array();
+
+        while($ce->fetch()) {
+            $ar = explode('/', $ce->Name);
+            $region = $ar[0];
+            $area = str_replace('_', ' ', $ar[1]);
+
+            if(!in_array($region, $regions)) {
+                $regions[] = $region;
+                $values[] = "('Timezone.Region', '" . $region . "', 1, 0, 0, '" . $region . "', 0)";
+            }
+
+            if(!in_array($area, $areas)) {
+                $areas[] = $area;
+                $values[] = "('Timezone.Area', '" . $area . "', 1, 0, 0, '" . $area . "', 0)";
+            }
+        }
+
+        $sql = "
+            INSERT INTO
+                core_enum (etype, name, active, seqid, seqmax, display_name, is_system_enum)
+            VALUES
+                " . implode(", \n", $values) . "
+        ";
+
+        $ce = DB_DataObject::factory('core_enum');
+        $ce->query($sql);
+        
+        $this->jok('DONE');
+    }
+}
\ No newline at end of file