-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.php
85 lines (76 loc) · 2.53 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
<?php namespace Hampel\SparkPostMail;
use XF\AddOn\AbstractSetup;
use XF\Db\Schema\Create;
class Setup extends AbstractSetup
{
public function install(array $stepParams = [])
{
$this->schemaManager()->createTable('xf_sparkpost_mail_message_event', function(Create $table)
{
$table->addColumn('event_id', 'varchar', 32);
$table->addColumn('type', 'varchar', 32);
$table->addColumn('recipient', 'varchar', 120);
$table->addColumn('processed', 'tinyint')->setDefault(0);
$table->addColumn('timestamp', 'int');
$table->addColumn('payload', 'text');
$table->addPrimaryKey('event_id');
$table->addKey('processed');
});
}
public function upgrade(array $stepParams = [])
{
if ($this->addOn->version_id < 2000000)
{
$db = $this->db();
$emailTransport = $db->fetchOne('SELECT option_value FROM xf_option WHERE option_id = \'emailTransport\'');
$emailTransport = json_decode($emailTransport, true);
if ($emailTransport &&
isset($emailTransport['emailTransport']) &&
$emailTransport['emailTransport'] == 'sparkpost' &&
isset($emailTransport['apiKey']) &&
!empty($emailTransport['apiKey']))
{
$clickTracking = $db->fetchOne('SELECT option_value FROM xf_option WHERE option_id = \'sparkpostmailClickTracking\'');
if (is_null($clickTracking))
{
$emailTransport['clickTracking'] = false;
}
else
{
$emailTransport['clickTracking'] = boolval($clickTracking);
}
$openTracking = $db->fetchOne('SELECT option_value FROM xf_option WHERE option_id = \'sparkpostmailOpenTracking\'');
if (is_null($openTracking))
{
$emailTransport['openTracking'] = false;
}
else
{
$emailTransport['openTracking'] = boolval($openTracking);
}
$testMode = $db->fetchOne('SELECT option_value FROM xf_option WHERE option_id = \'sparkpostmailTestMode\'');
if (is_null($testMode))
{
$emailTransport['testMode'] = false;
}
else
{
$emailTransport['testMode'] = boolval($testMode);
}
$this->executeUpgradeQuery('UPDATE xf_option SET option_value = ? WHERE option_id = \'emailTransport\'', json_encode($emailTransport));
}
}
}
public function uninstall(array $stepParams = [])
{
$this->schemaManager()->dropTable('xf_sparkpost_mail_message_event');
}
public function checkRequirements(&$errors = [], &$warnings = [])
{
$vendorDirectory = sprintf("%s/vendor", $this->addOn->getAddOnDirectory());
if (!file_exists($vendorDirectory))
{
$errors[] = "vendor folder does not exist - cannot proceed with addon install";
}
}
}