-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.php
70 lines (63 loc) · 2.02 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
<?php namespace Hampel\ApprovalQueuePlus;
use XF\Db\Schema\Alter;
use XF\Db\Schema\Create;
use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerUpgradeTrait;
class Setup extends AbstractSetup
{
use StepRunnerUpgradeTrait;
public function install(array $stepParams = [])
{
$this->createTables();
}
// upgrade to 3.5.1
public function upgrade3050170Step1(array $stepParams = [])
{
if ($this->schemaManager()->tableExists('xf_user_agent'))
{
$this->schemaManager()->renameTable('xf_user_agent', 'xf_aqp_user_data');
$this->alterTables350();
}
elseif ($this->schemaManager()->tableExists('xf_aqp_user_agent'))
{
$this->schemaManager()->renameTable('xf_aqp_user_agent', 'xf_aqp_user_data');
$this->alterTables350();
}
elseif ($this->schemaManager()->tableExists('xf_aqp_user_data'))
{
// we renamed the table, but didn't create the new columns - oops
if (!$this->schemaManager()->columnExists('xf_aqp_user_data', 'iso_code'))
{
$this->alterTables350();
}
}
else
{
$this->createTables();
}
}
public function uninstall(array $stepParams = [])
{
$this->schemaManager()->dropTable('xf_aqp_user_data');
}
protected function createTables()
{
$this->schemaManager()->createTable('xf_aqp_user_data', function(Create $table)
{
$table->addColumn('user_id', 'int');
$table->addColumn('user_agent', 'text');
$table->addColumn('iso_code', 'varchar', 2);
$table->addColumn('cf_location', 'mediumblob');
$table->addPrimaryKey('user_id');
});
}
// for v3.5.0+
protected function alterTables350()
{
$this->schemaManager()->alterTable('xf_aqp_user_data', function(Alter $table)
{
$table->addColumn('iso_code', 'varchar', 2)->setDefault('')->after('user_agent');
$table->addColumn('cf_location', 'mediumblob')->after('iso_code');
});
}
}