forked from ThemeHouse-XF/XF2-AvatarGallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.php
149 lines (132 loc) · 4.03 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
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
<?php
namespace ThemeHouse\AvatarGallery;
use ThemeHouse\AvatarGallery\Entity\AvatarCategory;
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;
use XF\Entity\Phrase;
/**
* Class Setup
* @package ThemeHouse\AvatarGallery
*/
class Setup extends AbstractSetup
{
use StepRunnerInstallTrait;
use StepRunnerUpgradeTrait;
use StepRunnerUninstallTrait;
/**
*
*/
public function installStep1()
{
$this->schemaManager()->createTable('xf_th_avatar_gallery_avatar', function (Create $table) {
$table->addColumn('avatar_id', 'int')->autoIncrement();
$table->addColumn('avatar_date', 'int')->setDefault(0);
$table->addColumn('avatar_category_id', 'int')->setDefault(0);
$table->addColumn('display_order', 'int')->setDefault(100);
$table->addColumn('active', 'tinyint')->setDefault(1);
$table->addColumn('avatar_url', 'text')->nullable();
$table->addColumn('user_criteria', 'blob');
$table->addColumn('resized', 'bool')->setDefault(0);
});
}
/**
*
*/
public function installStep2()
{
$this->schemaManager()->createTable('xf_th_avatar_gallery_avatar_category',
function (Create $table) {
$table->addColumn('avatar_category_id', 'int')->unsigned(false)->autoIncrement();
$table->addColumn('display_order', 'int')->setDefault(100);
$table->addColumn('active', 'tinyint')->setDefault(1);
});
}
/**
* @throws \XF\PrintableException
*/
public function installStep3()
{
/** @var AvatarCategory $category */
$category = \XF::em()->create('ThemeHouse\AvatarGallery:AvatarCategory');
$category->save();
/** @var Phrase $title */
$title = $category->getMasterPhrase();
$title->phrase_text = 'Uncategorized';
$title->save();
}
/**
*
*/
public function installStep4()
{
$this->schemaManager()->alterTable('xf_user', function (Alter $table) {
$table->addColumn('thag_avatar_id', 'int')->setDefault(0);
});
}
/**
* @param array $stateChanges
*/
public function postInstall(array &$stateChanges)
{
$this->applyGlobalPermission('th_avatargallery', 'select');
$this->applyGlobalPermission('th_avatargallery', 'upload');
$this->app()->jobManager()->enqueueUnique('languageRebuild', 'XF:Atomic', [
'execute' => ['XF:PhraseRebuild', 'XF:TemplateRebuild']
]);
}
/**
*
*/
public function upgrade1000110Step1()
{
$this->schemaManager()->alterTable('xf_user', function (Alter $table) {
$table->addColumn('thag_avatar_id', 'int')->setDefault(0);
});
}
/**
*
*/
public function upgrade1000110Step2()
{
$this->schemaManager()->alterTable('xf_th_avatar_gallery_avatar', function (Alter $table) {
$table->addColumn('avatar_url', 'text')->nullable();
});
}
public function upgrade1000351Step1()
{
$this->schemaManager()->alterTable('xf_th_avatar_gallery_avatar', function (Alter $table) {
$table->addColumn('resized', 'bool')->setDefault(0);
});
}
/**
*
*/
public function uninstallStep1()
{
$this->schemaManager()->dropTable('xf_th_avatar_gallery_avatar');
}
/**
*
*/
public function uninstallStep2()
{
$this->schemaManager()->dropTable('xf_th_avatar_gallery_avatar_category');
}
public function uninstallStep3()
{
\XF::db()->update('xf_user', ['avatar_date' => 0], 'thag_avatar_id > 0');
}
/**
*
*/
public function uninstallStep4()
{
$this->schemaManager()->alterTable('xf_user', function (Alter $table) {
$table->dropColumns(['thag_avatar_id']);
});
}
}