-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetup.php
More file actions
152 lines (136 loc) · 4.08 KB
/
Setup.php
File metadata and controls
152 lines (136 loc) · 4.08 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/*
* This file is part of a XenForo add-on.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Jrahmy\Moderation;
use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUninstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;
use XF\Db\Schema\Alter;
/**
* Handles installation, upgrades, and uninstallation of the add-on.
*/
class Setup extends AbstractSetup
{
use StepRunnerInstallTrait;
use StepRunnerUpgradeTrait;
use StepRunnerUninstallTrait;
/**
* Alters schema of core tables.
*/
public function installStep1()
{
$sm = $this->schemaManager();
$sm->alterTable('xf_conversation_message', function (Alter $table) {
$table->addColumn('j_warning_id', 'int')->setDefault(0);
$table
->addColumn('j_warning_message', 'varchar', 255)
->setDefault('');
});
$sm->alterTable('xf_report_comment', function (Alter $table) {
$table->addColumn('j_ip_id', 'int')->setDefault(0);
$table
->addColumn('reaction_score', 'int')
->unsigned(false)
->setDefault(0);
$table->addColumn('reactions', 'blob')->nullable();
$table->addColumn('reaction_users', 'blob')->nullable();
});
}
/**
* Applies default permissions for a fresh install.
*/
public function installStep2()
{
$this->applyDefaultPermissions();
}
/**
* Applies schema changes for conversation warnings.
*/
public function upgrade1000511Step1()
{
$sm = $this->schemaManager();
$sm->alterTable('xf_conversation_message', function (Alter $table) {
$table->addColumn('j_warning_id', 'int')->setDefault(0);
$table
->addColumn('j_warning_message', 'varchar', 255)
->setDefault('');
});
}
/**
* Applies schema changes for report comment features.
*/
public function upgrade1000511Step2()
{
$sm = $this->schemaManager();
$sm->alterTable('xf_report_comment', function (Alter $table) {
$table->addColumn('j_ip_id', 'int')->setDefault(0);
$table
->addColumn('reaction_score', 'int')
->unsigned(false)
->setDefault(0);
$table->addColumn('reactions', 'blob')->nullable();
$table->addColumn('reaction_users', 'blob');
});
}
/**
* Allows the `reaction_users` column to be nullable.
*/
public function upgrade100911Step1()
{
$sm = $this->schemaManager();
$sm->alterTable('xf_report_comment', function (Alter $table) {
$table->changeColumn('reaction_users')->nullable();
});
}
/**
* @param int $previousVersion
* @param array $stateChanges
*/
public function postUpgrade($previousVersion, array &$stateChanges)
{
if ($this->applyDefaultPermissions($previousVersion)) {
$this->app
->jobManager()
->enqueueUnique(
'permissionRebuild',
'XF:PermissionRebuild',
[],
false
);
}
}
/**
* Reverts schema changes of core tables.
*/
public function uninstallStep1()
{
$sm = $this->schemaManager();
$sm->alterTable('xf_conversation_message', function (Alter $table) {
$table->dropColumns(['j_warning_id', 'j_warning_message']);
});
}
/**
* @param int|null $previousVersion
*
* @return bool
*/
protected function applyDefaultPermissions($previousVersion = null)
{
$applied = false;
if (!$previousVersion || $previousVersion < 1000211) {
$this->applyGlobalPermission(
'conversation',
'warn',
'forum',
'warn'
);
$applied = true;
}
return $applied;
}
}