-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSetup.php
58 lines (44 loc) · 1.59 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
<?php
namespace MinecraftServerChecker;
use XF\AddOn\AbstractSetup;
use XF\Db\Schema\Create;
class Setup extends AbstractSetup
{
public function install(array $stepParams = [])
{
$em = \XF::app()->em();
$this->schemaManager()->createTable('xf_msc_servers', function(Create $table) {
$table->addColumn('thread_id', 'int');
$table->addColumn('ip', 'varchar', 100);
$table->addColumn('status', 'tinyint')->setDefault(0);
$table->addColumn('online', 'int')->setDefault(0);
$table->addColumn('max', 'int')->setDefault(1);
$table->addColumn('last_update', 'varchar', 100);
$table->addPrimaryKey('thread_id');
});
if (!$em->find('XF:ThreadField', 'msc_server_ip')) {
$field = $em->create('XF:ThreadField');
$title = $field->getMasterPhrase(true);
$title->phrase_text = "Minecraft Server IP Address";
$description = $field->getMasterPhrase(false);
$description->phrase_text = "Enter the valid ip address for the server connection.";
$field->set('field_id', 'msc_server_ip');
$field->set('match_type', 'regex');
$field->setFromEncoded('match_params', '{"regex":"(([a-zA-Z0-9-])+[.]+([a-zA-Z0-9-])+[.]+([a-zA-Z0-9-])+)|([a-zA-Z0-9-])+[.]+([a-zA-Z0-9-])+"}');
$field->addCascadedSave($title);
$field->addCascadedSave($description);
$field->save();
}
}
public function upgrade(array $stepParams = [])
{
// First Version
}
public function uninstall(array $stepParams = [])
{
$em = \XF::app()->em();
$field = $em->find('XF:ThreadField', 'msc_server_ip');
if ($field) $field->delete();
$this->schemaManager()->dropTable('xf_msc_servers');
}
}