PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.8.4
Independent Analytics – WordPress Analytics Plugin v2.8.4
2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / IAWP / Migrations / Migration_23.php
independent-analytics / IAWP / Migrations Last commit date
Migration.php 1 year ago Migration_10.php 2 years ago Migration_11.php 2 years ago Migration_12.php 1 year ago Migration_13.php 2 years ago Migration_14.php 2 years ago Migration_15.php 2 years ago Migration_16.php 2 years ago Migration_17.php 1 year ago Migration_18.php 2 years ago Migration_19.php 2 years ago Migration_1_0.php 2 years ago Migration_1_6.php 2 years ago Migration_1_8.php 2 years ago Migration_1_9.php 2 years ago Migration_2.php 2 years ago Migration_20.php 2 years ago Migration_21.php 2 years ago Migration_22.php 2 years ago Migration_23.php 2 years ago Migration_24.php 2 years ago Migration_25.php 2 years ago Migration_26.php 2 years ago Migration_27.php 2 years ago Migration_28.php 2 years ago Migration_29.php 2 years ago Migration_3.php 2 years ago Migration_30.php 2 years ago Migration_31.php 2 years ago Migration_32.php 2 years ago Migration_33.php 2 years ago Migration_34.php 1 year ago Migration_35.php 1 year ago Migration_36.php 1 year ago Migration_4.php 2 years ago Migration_5.php 2 years ago Migration_6.php 2 years ago Migration_7.php 1 year ago Migration_8.php 2 years ago Migration_9.php 2 years ago Migration_Job.php 2 years ago Migrations.php 1 year ago Step_Migration.php 1 year ago
Migration_23.php
114 lines
1 <?php
2
3 namespace IAWP\Migrations;
4
5 use IAWP\Query;
6 /** @internal */
7 class Migration_23 extends \IAWP\Migrations\Step_Migration
8 {
9 /**
10 * @return int
11 */
12 protected function database_version() : int
13 {
14 return 23;
15 }
16 /**
17 * @return array
18 */
19 protected function queries() : array
20 {
21 return [$this->maybe_drop_device_types_table(), $this->create_device_types_table(), $this->maybe_drop_device_oss_table(), $this->create_device_oss_table(), $this->maybe_drop_device_browsers_table(), $this->create_device_browsers_table(), $this->add_columns_to_sessions(), $this->populate_device_types(), $this->populate_device_oss(), $this->populate_device_browsers(), $this->link_sessions_with_types(), $this->link_sessions_with_oss(), $this->link_sessions_with_browsers(), $this->drop_device_id_column_from_sessions(), $this->drop_original_devices_table()];
22 }
23 private function maybe_drop_device_types_table() : string
24 {
25 $device_types_table = Query::get_table_name(Query::DEVICE_TYPES);
26 return "\n DROP TABLE IF EXISTS {$device_types_table}\n ";
27 }
28 private function create_device_types_table() : string
29 {
30 global $wpdb;
31 $charset_collate = $wpdb->get_charset_collate();
32 $device_types_table = Query::get_table_name(Query::DEVICE_TYPES);
33 return "\n CREATE TABLE {$device_types_table} (\n device_type_id bigint(20) UNSIGNED AUTO_INCREMENT,\n device_type varchar(64) NOT NULL UNIQUE,\n PRIMARY KEY (device_type_id)\n ) {$charset_collate}\n ";
34 }
35 private function maybe_drop_device_oss_table() : string
36 {
37 $device_oss_table = Query::get_table_name(Query::DEVICE_OSS);
38 return "\n DROP TABLE IF EXISTS {$device_oss_table}\n ";
39 }
40 private function create_device_oss_table() : string
41 {
42 global $wpdb;
43 $charset_collate = $wpdb->get_charset_collate();
44 $device_oss_table = Query::get_table_name(Query::DEVICE_OSS);
45 return "\n CREATE TABLE {$device_oss_table} (\n device_os_id bigint(20) UNSIGNED AUTO_INCREMENT,\n device_os varchar(64) NOT NULL UNIQUE,\n PRIMARY KEY (device_os_id)\n ) {$charset_collate}\n ";
46 }
47 private function maybe_drop_device_browsers_table() : string
48 {
49 $device_browsers_table = Query::get_table_name(Query::DEVICE_BROWSERS);
50 return "\n DROP TABLE IF EXISTS {$device_browsers_table}\n ";
51 }
52 private function create_device_browsers_table() : string
53 {
54 global $wpdb;
55 $charset_collate = $wpdb->get_charset_collate();
56 $device_browsers_table = Query::get_table_name(Query::DEVICE_BROWSERS);
57 return "\n CREATE TABLE {$device_browsers_table} (\n device_browser_id bigint(20) UNSIGNED AUTO_INCREMENT,\n device_browser varchar(64) NOT NULL UNIQUE,\n PRIMARY KEY (device_browser_id)\n ) {$charset_collate}\n ";
58 }
59 private function add_columns_to_sessions() : string
60 {
61 $sessions_table = Query::get_table_name(Query::SESSIONS);
62 return "\n ALTER TABLE {$sessions_table}\n ADD COLUMN device_type_id BIGINT(20) UNSIGNED,\n ADD COLUMN device_os_id BIGINT(20) UNSIGNED,\n ADD COLUMN device_browser_id BIGINT(20) UNSIGNED,\n ADD INDEX (device_type_id),\n ADD INDEX (device_os_id),\n ADD INDEX (device_browser_id);\n ";
63 }
64 private function populate_device_types() : string
65 {
66 $devices_table = Query::get_table_name(Query::DEVICES);
67 $device_types_table = Query::get_table_name(Query::DEVICE_TYPES);
68 return "\n INSERT INTO {$device_types_table} (device_type)\n SELECT DISTINCT type\n FROM {$devices_table} WHERE type IS NOT NULL\n ";
69 }
70 private function populate_device_oss() : string
71 {
72 $devices_table = Query::get_table_name(Query::DEVICES);
73 $device_oss_table = Query::get_table_name(Query::DEVICE_OSS);
74 return "\n INSERT INTO {$device_oss_table} (device_os)\n SELECT DISTINCT os\n FROM {$devices_table} WHERE os IS NOT NULL\n ";
75 }
76 private function populate_device_browsers()
77 {
78 $devices_table = Query::get_table_name(Query::DEVICES);
79 $device_browsers_table = Query::get_table_name(Query::DEVICE_BROWSERS);
80 return "\n INSERT INTO {$device_browsers_table} (device_browser)\n SELECT DISTINCT browser\n FROM {$devices_table} WHERE browser IS NOT NULL\n ";
81 }
82 private function link_sessions_with_types() : string
83 {
84 $sessions_table = Query::get_table_name(Query::SESSIONS);
85 $devices_table = Query::get_table_name(Query::DEVICES);
86 $device_types_table = Query::get_table_name(Query::DEVICE_TYPES);
87 return "\n UPDATE {$sessions_table} AS sessions\n JOIN {$devices_table} AS devices ON sessions.device_id = devices.device_id\n JOIN {$device_types_table} AS device_types ON devices.type = device_types.device_type\n SET sessions.device_type_id = device_types.device_type_id;\n ";
88 }
89 private function link_sessions_with_oss() : string
90 {
91 $sessions_table = Query::get_table_name(Query::SESSIONS);
92 $devices_table = Query::get_table_name(Query::DEVICES);
93 $device_oss_table = Query::get_table_name(Query::DEVICE_OSS);
94 return "\n UPDATE {$sessions_table} AS sessions\n JOIN {$devices_table} AS devices ON sessions.device_id = devices.device_id\n JOIN {$device_oss_table} AS device_oss ON devices.os = device_oss.device_os\n SET sessions.device_os_id = device_oss.device_os_id;\n ";
95 }
96 private function link_sessions_with_browsers() : string
97 {
98 $sessions_table = Query::get_table_name(Query::SESSIONS);
99 $devices_table = Query::get_table_name(Query::DEVICES);
100 $device_browsers_table = Query::get_table_name(Query::DEVICE_BROWSERS);
101 return "\n UPDATE {$sessions_table} AS sessions\n JOIN {$devices_table} AS devices ON sessions.device_id = devices.device_id\n JOIN {$device_browsers_table} AS device_browsers ON devices.browser = device_browsers.device_browser\n SET sessions.device_browser_id = device_browsers.device_browser_id;\n ";
102 }
103 private function drop_device_id_column_from_sessions() : string
104 {
105 $sessions_table = Query::get_table_name(Query::SESSIONS);
106 return "\n ALTER TABLE {$sessions_table} DROP COLUMN device_id;\n ";
107 }
108 private function drop_original_devices_table() : string
109 {
110 $devices_table = Query::get_table_name(Query::DEVICES);
111 return "\n DROP TABLE IF EXISTS {$devices_table};\n ";
112 }
113 }
114