-
Notifications
You must be signed in to change notification settings - Fork 2
/
Setup.php
103 lines (90 loc) · 3.78 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
<?php
namespace LiamW\AccountDelete;
use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;
use XF\Db\Schema\Alter;
use XF\Db\Schema\Create;
use XF\Util\Php;
class Setup extends AbstractSetup
{
use StepRunnerInstallTrait;
use StepRunnerUpgradeTrait;
public function installStep1()
{
$this->schemaManager()->createTable('xf_liamw_accountdelete_account_deletions', function(Create $table)
{
$table->addColumn('deletion_id', 'int')->autoIncrement();
$table->addColumn('user_id', 'int');
$table->addColumn('username', 'varchar', 50);
$table->addColumn('reason', 'text')->nullable()->setDefault(null);
$table->addColumn('initiation_date', 'int');
$table->addColumn('completion_date', 'int')->nullable()->setDefault(null);
$table->addColumn('status', 'enum', ['pending', 'complete', 'complete_manual', 'cancelled'])->setDefault('pending');
$table->addColumn('reminder_sent', 'bool')->setDefault(0);
$table->addKey('user_id');
$table->addKey('username');
});
}
public function upgrade1010010Step1()
{
$this->schemaManager()->alterTable('xf_liamw_accountdelete_pending', function(Alter $table)
{
$table->renameTo('xf_liamw_accountdelete_account_deletions');
$table->dropPrimaryKey();
$table->addColumn('deletion_id', 'int')->autoIncrement();
$table->addColumn('username', 'varchar', 50)->after('user_id');
$table->addColumn('reason', 'text')->nullable()->setDefault(null);
$table->renameColumn('initiate_date', 'initiation_date');
$table->addColumn('completion_date', 'int')->nullable()->setDefault(null);
$table->addColumn('status', 'enum', ['pending', 'complete', 'complete_manual', 'cancelled'])->setDefault('pending');
$table->addColumn('reminder_sent', 'bool')->setDefault(0);
$table->addKey('user_id');
$table->addKey('username');
});
}
public function upgrade1010033Step1()
{
$this->schemaManager()->alterTable('xf_liamw_accountdelete_account_deletions', function(Alter $table)
{
$table->changeColumn('status', 'enum', ['pending', 'complete', 'complete_manual', 'cancelled'])->setDefault('pending');
});
}
public function upgrade1020034Step1()
{
$this->db()->query("UPDATE xf_liamw_accountdelete_account_deletions SET status='complete_manual' WHERE status='pending' AND (SELECT user.user_id FROM xf_user AS user WHERE user.user_id=xf_liamw_accountdelete_account_deletions.user_id) IS NULL");
}
public function postUpgrade($previousVersion, array &$stateChanges)
{
$this->app->jobManager()->cancelUniqueJob('lwAccountDeleteReminder');
$this->app->jobManager()->cancelUniqueJob('lwAccountDeleteRunner');
// Schedule the reminder/deletion jobs
$repository = \XF::repository('LiamW\AccountDelete:AccountDelete');
if ($nextRemindTime = $repository->getNextRemindTime())
{
$this->app->jobManager()->enqueueLater('lwAccountDeleteReminder', $nextRemindTime, 'LiamW\AccountDelete:SendDeleteReminders');
}
if ($nextDeletionTime = $repository->getNextDeletionTime())
{
$this->app->jobManager()->enqueueLater('lwAccountDeleteRunner', $nextDeletionTime, 'LiamW\AccountDelete:DeleteAccounts');
}
}
public function onActiveChange($newActive, array &$jobList)
{
if ($newActive)
{
// Can't use the jobList array as the atomic runner doesn't support future resumes
$this->app->jobManager()->enqueueUnique('lwAccountDeleteReminder', 'LiamW\AccountDelete:SendDeleteReminders');
$this->app->jobManager()->enqueueUnique('lwAccountDeleteRunner', 'LiamW\AccountDelete:DeleteAccounts');
}
else
{
$this->app->jobManager()->cancelUniqueJob('lwAccountDeleteReminder');
$this->app->jobManager()->cancelUniqueJob('lwAccountDeleteRunner');
}
}
public function uninstall(array $stepParams = [])
{
$this->schemaManager()->dropTable('xf_liamw_accountdelete_account_deletions');
}
}