-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.php
117 lines (98 loc) · 2.45 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
<?php
/**
* This file is a part of free add-on "Forum Rules Accept".
* Developed by HLModerators.
*
* License - MIT.
*/
namespace HLModerators\ForumRulesAccept;
use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUninstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;
use XF\Db\Schema\Alter;
class Setup extends AbstractSetup
{
use StepRunnerInstallTrait;
use StepRunnerUpgradeTrait;
use StepRunnerUninstallTrait;
const TABLES = ['xf_forum', 'xf_rm_category'];
#region Install steps
/**
* Adds the columns to required tables (if exists).
*/
public function installStep1(): void
{
foreach (self::TABLES as $tableName)
{
$this->addRulesColumn($tableName);
}
}
#endregion
#region Upgrade steps
/**
* Sets the default column value for correct working if add-on is
* disabled.
*/
public function upgrade1000011Step1(): void
{
$this->alterTable('xf_forum', function (Alter $table)
{
$table->changeColumn('hlmod_rules_url')
->setDefault('');
});
}
/**
* Adds the column to XFRM table (if exists).
*/
public function upgrade1000210Step1(): void
{
$this->addRulesColumn('xf_rm_category');
}
#endregion
#region Uninstall steps
/**
* Drops the column from all tables.
*/
public function uninstallStep1(): void
{
foreach (self::TABLES as $tableName)
{
$this->dropRulesColumn($tableName);
}
}
#endregion
/**
* Adds the column for rules URL saving in specified table.
*
* @param string $tableName
*/
public function addRulesColumn(string $tableName): void
{
if (!$this->tableExists($tableName))
{
return;
}
$this->alterTable($tableName, function (Alter $table)
{
$table->addColumn('hlmod_rules_url', 'varchar', 255)
->setDefault('');
});
}
/**
* Drops the column for rules URL saving in specified table.
*
* @param string $tableName
*/
public function dropRulesColumn(string $tableName): void
{
if (!$this->tableExists($tableName))
{
return;
}
$this->alterTable($tableName, function (Alter $table)
{
$table->dropColumns(['hlmod_rules_url']);
});
}
}