-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetup.php
More file actions
125 lines (115 loc) · 3.44 KB
/
Setup.php
File metadata and controls
125 lines (115 loc) · 3.44 KB
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
125
<?php
namespace ThemeHouse\UserNameChange;
use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUninstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;
use XF\Db\Schema\Alter;
use XF\Db\Schema\Create;
/**
* Class Setup
* @package ThemeHouse\UserNameChange
*/
class Setup extends AbstractSetup
{
use StepRunnerInstallTrait;
use StepRunnerUpgradeTrait;
use StepRunnerUninstallTrait;
/**
*
*/
public function installStep1()
{
$this->schemaManager()->createTable('xf_th_unc_username_change', function (Create $table) {
$table->addColumn('change_id', 'int')->nullable()->autoIncrement();
$table->addColumn('user_id', 'int')->setDefault(0);
$table->addColumn('change_user_id', 'int')->setDefault(0);
$table->addColumn('new_username', 'varchar', 200)->nullable();
$table->addColumn('old_username', 'varchar', 200);
$table->addColumn('change_date', 'int')->setDefault(0);
});
}
/**
*
*/
public function installStep2()
{
$this->schemaManager()->alterTable('xf_user', function (Alter $table) {
$table->addColumn('th_unc_change_count', 'int')->setDefault(0);
$table->addColumn('th_unc_last_name_change', 'int')->setDefault(0);
$table->addColumn('th_unco_force_name_change', 'bool')->setDefault(0);
});
}
/**
*
*/
public function installStep3()
{
$this->schemaManager()->alterTable('xf_user_privacy', function (Alter $table) {
$table->addColumn('th_unc_change_history', 'enum')->values([
'everyone',
'members',
'followed',
'none'
])->setDefault('everyone');
});
}
/**
* @throws \XF\Db\Exception
*/
public function installStep4()
{
if ($this->schemaManager()->tableExists('xf_th_userimprovements_username_changes')) {
\XF::db()->query('
INSERT INTO
xf_th_unc_username_change
SELECT
null,
user_id,
user_id,
IFNULL((
SELECT
old_username
FROM
xf_th_userimprovements_username_changes subq
WHERE
subq.user_id = changep.user_id
and subq.change_date > changep.change_date
HAVING
MIN(change_date)
), user.username),
old_username,
change_date
FROM
xf_th_userimprovements_username_changes changep
LEFT JOIN
xf_user user USING(user_id)
');
}
}
/**
*
*/
public function uninstallStep1()
{
$this->schemaManager()->dropTable('xf_th_unc_username_change');
}
/**
*
*/
public function uninstallStep2()
{
$this->schemaManager()->alterTable('xf_user', function (Alter $table) {
$table->dropColumns(['th_unc_change_count', 'th_unc_last_name_change']);
});
}
/**
*
*/
public function uninstallStep3()
{
$this->schemaManager()->alterTable('xf_user_privacy', function (Alter $table) {
$table->dropColumns(['th_unc_change_history']);
});
}
}