1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use yii\db\Migration; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class m190926_110717_hit_counter__table |
7
|
|
|
*/ |
8
|
|
|
class m190926_110717_hit_counter__table extends Migration |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* {@inheritdoc} |
12
|
|
|
*/ |
13
|
|
|
public function safeUp() |
14
|
|
|
{ |
15
|
|
|
$tableOptions = null; |
16
|
|
|
if ('mysql' === $this->db->driverName) { |
17
|
|
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
$this->createTable('{{%hit_counter}}', [ |
21
|
|
|
'id' => $this->primaryKey()->unsigned(), |
22
|
|
|
'counter_id' => $this->string()->notNull(), |
23
|
|
|
'cookie_mark'=> $this->char(32)->null(), |
24
|
|
|
'js_cookei_enabled' => $this->boolean()->notNull()->defaultValue(0), |
25
|
|
|
'js_java_enabled' => $this->boolean()->notNull()->defaultValue(0), |
26
|
|
|
'js_timezone_offset' => $this->integer()->null(), |
27
|
|
|
'js_timezone' => $this->string()->null(), |
28
|
|
|
'js_connection' => $this->string()->null(), |
29
|
|
|
'js_current_url' => $this->text()->null(), |
30
|
|
|
'js_referer_url' => $this->text()->null(), |
31
|
|
|
'js_screen_width' => $this->integer()->null(), |
32
|
|
|
'js_screen_height' => $this->integer()->null(), |
33
|
|
|
'js_color_depth' => $this->integer()->null(), |
34
|
|
|
'js_browser_language' => $this->string()->null(), |
35
|
|
|
'js_history_length' => $this->integer()->null(), |
36
|
|
|
'js_is_toutch_device' => $this->boolean()->notNull()->defaultValue(0), |
37
|
|
|
'js_processor_ram' => $this->integer()->null(), |
38
|
|
|
|
39
|
|
|
'serv_ip' => $this->char(20)->null(), |
40
|
|
|
'serv_user_agent' => $this->text()->null(), |
41
|
|
|
'serv_referer_url' => $this->text()->null(), |
42
|
|
|
'serv_server_name' => $this->string()->null(), |
43
|
|
|
'serv_auth_user_id' => $this->integer()->unsigned()->null(), |
44
|
|
|
'serv_port' => $this->integer()->unsigned()->null(), |
45
|
|
|
'serv_cookies' => 'JSON', |
46
|
|
|
|
47
|
|
|
'serv_os' => $this->string()->null(), |
48
|
|
|
'serv_client' => $this->string()->null(), |
49
|
|
|
'serv_device' => $this->string()->null(), |
50
|
|
|
'serv_brand' => $this->string()->null(), |
51
|
|
|
'serv_model' => $this->string()->null(), |
52
|
|
|
'serv_bot' => $this->string()->null(), |
53
|
|
|
'serv_host_by_ip' => $this->string()->null(), |
54
|
|
|
'serv_is_proxy_or_vpn' => $this->boolean()->notNull()->defaultValue(0), |
55
|
|
|
|
56
|
|
|
'created_at' => $this->dateTime()->notNull(), |
57
|
|
|
], $tableOptions); |
58
|
|
|
|
59
|
|
|
$this->createIndex('{{%idx-hit_counter-cookie_mark}}', '{{%hit_counter}}', 'cookie_mark'); |
60
|
|
|
$this->createIndex('{{%idx-hit_counter-serv_ip}}', '{{%hit_counter}}', 'serv_ip'); |
61
|
|
|
$this->createIndex('{{%idx-hit_counter-serv_auth_user_id}}', '{{%hit_counter}}', 'serv_auth_user_id'); |
62
|
|
|
$this->createIndex('{{%idx-hit_counter-created_at}}', '{{%hit_counter}}', 'created_at'); |
63
|
|
|
|
64
|
|
|
$this->addForeignKey( |
65
|
|
|
'{{%fk-hit_counter-serv_auth_user_id}}', |
66
|
|
|
'{{%hit_counter}}', |
67
|
|
|
'serv_auth_user_id', |
68
|
|
|
'{{%user}}', |
69
|
|
|
'id', |
70
|
|
|
'RESTRICT', |
71
|
|
|
'CASCADE' |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$this->addCommentOnColumn('{{%hit_counter}}', 'serv_auth_user_id', 'User id if exists'); |
75
|
|
|
$this->addCommentOnColumn('{{%hit_counter}}', 'serv_ip', 'User ip'); |
76
|
|
|
$this->addCommentOnColumn('{{%hit_counter}}', 'counter_id', 'Counter id generated in widget and passed by query param in inage src'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
|
|
public function safeDown() |
83
|
|
|
{ |
84
|
|
|
$this->dropTable('{{%hit_counter}}'); |
85
|
|
|
echo "m190926_110717_hit_counter__table dropped.\n"; |
86
|
|
|
// echo "m190926_110717_hit_counter__table cannot be reverted.\n"; |
87
|
|
|
|
88
|
|
|
// return false; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/* |
92
|
|
|
// Use up()/down() to run migration code without a transaction. |
93
|
|
|
public function up() |
94
|
|
|
{ |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function down() |
99
|
|
|
{ |
100
|
|
|
echo "m190926_110717_hit_counter__table cannot be reverted.\n"; |
101
|
|
|
|
102
|
|
|
return false; |
103
|
|
|
} |
104
|
|
|
*/ |
105
|
|
|
} |
106
|
|
|
|