-
Notifications
You must be signed in to change notification settings - Fork 0
/
upd.hey_check_it_webhook.php
161 lines (131 loc) · 4.7 KB
/
upd.hey_check_it_webhook.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
150
151
152
153
154
155
156
157
158
159
160
161
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once __DIR__ . '/vendor/autoload.php';
class Hey_check_it_webhook_upd {
public $version = '1.0.0';
public function install()
{
$data = array(
'module_name' => 'Hey_check_it_webhook',
'module_version' => $this->version,
'has_cp_backend' => 'n',
'has_publish_fields' => 'n'
);
ee()->db->insert('modules', $data);
// Create model tables
$this->createSettingsTable();
$this->createNotificationTable();
// Add Extension calls
$this->addExtensionCalls();
return true;
}
public function update($current = '')
{
return true;
}
public function uninstall()
{
ee()->load->dbforge();
ee()->db->where('module_name', 'Hey_check_it_webhook');
ee()->db->delete('modules');
ee()->db->where('class', 'Hey_check_it_webhook_ext');
ee()->db->delete('extensions');
// Drop tables
if(ee()->db->table_exists('hci_notifications')) ee()->dbforge->drop_table('hci_notifications');
if(ee()->db->table_exists('hci_settings')) ee()->dbforge->drop_table('hci_settings');
return true;
}
private function createNotificationTable()
{
// Notifications model
ee()->load->dbforge();
if(!ee()->db->table_exists('hci_notifications'))
{
ee()->dbforge->add_field(
[
// id, our primary key
'id' => [
'type' => 'int',
'constraint' => 6,
'unsigned' => true,
'auto_increment' => true,
],
'type' => [
'type' => 'VARCHAR',
'constraint' => 20,
],
'emails' => [
'type' => 'VARCHAR',
'constraint' => 250,
],
'notification' => [
'type' => 'TEXT',
],
'data' => [
'type' => 'TEXT',
'null' => true,
],
'read' => [
'type' => 'TINYINT',
'default' => 0,
],
'created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
]
);
ee()->dbforge->add_key('id', true);
ee()->dbforge->create_table('hci_notifications');
}
}
private function createSettingsTable()
{
ee()->load->dbforge();
// Notifications model
if(!ee()->db->table_exists('hci_settings'))
{
ee()->dbforge->add_field(
[
// id, our primary key
'id' => [
'type' => 'int',
'constraint' => 6,
'unsigned' => true,
'auto_increment' => true,
],
'key' => [
'type' => 'VARCHAR',
'constraint' => 50,
],
'value' => [
'type' => 'TEXT',
],
]
);
ee()->dbforge->add_key('id', true);
ee()->dbforge->create_table('hci_settings');
}
}
private function addExtensionCalls()
{
$extensions = [
'cartthrob_save_customer_info_end',
'after_channel_entry_insert',
'after_channel_entry_update',
'cartthrob_pre_process',
'cartthrob_on_authorize',
'cartthrob_on_decline',
'cartthrob_on_processing',
'cartthrob_on_fail',
];
foreach ($extensions as $hook) {
$data = [
'class' => 'Hey_check_it_webhook_ext',
'method' => $hook,
'hook' => $hook,
'settings' => serialize([]),
'priority' => 10,
'version' => $this->version,
'enabled' => 'y'
];
ee()->db->insert('extensions', $data);
}
}
}