forked from luutruong/XF2_Api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.php
124 lines (101 loc) · 3.83 KB
/
Setup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace Truonglv\Api;
use XF\Db\Schema\Alter;
use XF\Db\Schema\Create;
use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;
use Truonglv\Api\DevHelper\SetupTrait;
use XF\AddOn\StepRunnerUninstallTrait;
class Setup extends AbstractSetup
{
use SetupTrait;
use StepRunnerInstallTrait;
use StepRunnerUpgradeTrait;
use StepRunnerUninstallTrait;
public function installStep1()
{
$this->doCreateTables($this->getTables());
$this->doAlterTables($this->getAlters());
}
public function uninstallStep1()
{
$this->doDropTables($this->getTables());
}
public function upgrade2000000Step1()
{
$this->doAlterTables($this->getAlters1());
}
/**
* @return array
*/
protected function getTables1()
{
$tables = [];
$tables['xf_tapi_log'] = function (Create $table) {
$table->addColumn('log_id', 'int')
->autoIncrement();
$table->addColumn('user_id', 'int')->setDefault(0);
$table->addColumn('app_version', 'varchar', 50);
$table->addColumn('end_point', 'text');
$table->addColumn('method', 'varchar', 12);
$table->addColumn('payload', 'mediumblob');
$table->addColumn('response_code', 'int')->setDefault(0);
$table->addColumn('response', 'mediumblob');
$table->addColumn('log_date', 'int')->setDefault(0);
$table->addKey('log_date');
};
$tables['xf_tapi_subscription'] = function (Create $table) {
$table->addColumn('subscription_id', 'int')
->autoIncrement();
$table->addColumn('user_id', 'int');
$table->addColumn('username', 'varchar', 50);
$table->addColumn('app_version', 'varchar', 50);
$table->addColumn('device_token', 'varbinary', 150);
$table->addColumn('is_device_test', 'tinyint')->setDefault(0);
$table->addColumn('provider', 'varchar', 25);
$table->addColumn('provider_key', 'varchar', 100);
$table->addColumn('subscribed_date', 'int')
->setDefault(0);
$table->addUniqueKey(['user_id', 'device_token']);
$table->addKey(['provider', 'provider_key']);
$table->addKey(['subscribed_date']);
};
$tables['xf_tapi_alert_queue'] = function (Create $table) {
$table->addColumn('content_type', 'varchar', 25);
$table->addColumn('content_id', 'int');
$table->addColumn('payload', 'blob')->nullable();
$table->addColumn('queue_date', 'int')->setDefault(0);
$table->addPrimaryKey(['content_type', 'content_id']);
$table->addKey(['queue_date']);
};
$tables['xf_tapi_access_token'] = function (Create $table) {
$table->addColumn('token', 'varbinary', 32);
$table->addColumn('user_id', 'int');
$table->addColumn('created_date', 'int')->setDefault(0);
$table->addColumn('expire_date', 'int')->setDefault(0);
$table->addPrimaryKey('token');
$table->addKey(['expire_date']);
};
return $tables;
}
/**
* @return array
*/
protected function getAlters1()
{
$alters = [];
$alters['xf_tapi_subscription'] = [
'provider_key' => function (Alter $table) {
$table->changeColumn('provider_key', 'varchar', 200);
},
'device_token' => function (Alter $table) {
$table->changeColumn('device_token', 'varchar', 200);
},
'device_type' => function (Alter $table) {
$table->addColumn('device_type', 'varchar', 25)->setDefault('');
},
];
return $alters;
}
}