-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpush.install
More file actions
138 lines (122 loc) · 3.96 KB
/
webpush.install
File metadata and controls
138 lines (122 loc) · 3.96 KB
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
<?php
/**
* Implements hook_requirements().
*/
function webpush_requirements($phase) {
$requirements = [];
$t = get_t();
if (!class_exists('\Minishlink\WebPush\Subscription')) {
$requirements['webpush_php_library'] = [
'title' => $t('WebPush PHP library', [], ['context' => 'webpush']),
'description' => $t('WebPush requires the <a href="@library_url">WebPush PHP (<code>minishlink/web-push</code>)</a> library to be installed and autoloaded with composer (e.g. using the <a href="@composer_manager_url">composer_manager</a> module).', [
'@library_url' => 'https://github.com/web-push-libs/web-push-php',
'@composer_manager_url' => 'https://www.drupal.org/project/composer_manager',
],
['context' => 'webpush']),
'severity' => REQUIREMENT_ERROR,
];
}
return $requirements;
}
/**
* Implements hook_schema()
*
* @return array
*/
function webpush_schema() {
$schema['webpush_subscription'] = [
'description' => 'The main table that will store webpush_subscription entities',
'fields' => [
'id' => [
'description' => 'Primary key for webpush subscriptions',
'type' => 'serial',
'not null' => TRUE,
'unsigned' => TRUE,
],
'created' => [
'description' => 'The Unix timestamp when the node was most recently created by services.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'subscription' => [
'description' => 'Serialized object of type Minishlink\WebPush\Subscription',
'type' => 'text',
'size' => 'normal',
'not null' => TRUE,
],
],
'unique keys' => [
'id' => ['id'],
],
'primary key' => ['id'],
];
$schema['webpush_notification'] = [
'description' => 'The main table that will store webpush_notification entities',
'fields' => [
'id' => [
'description' => 'Primary key for webpush notifications',
'type' => 'serial',
'not null' => TRUE,
'unsigned' => TRUE,
],
'created' => [
'description' => 'The Unix timestamp when the node was most recently created by services.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'title' => [
// 'description' => 'Serialized object of type Minishlink\WebPush\Subscription',
'type' => 'text',
'size' => 'normal',
'not null' => TRUE,
],
'body' => [
// 'description' => 'Serialized object of type Minishlink\WebPush\Subscription',
'type' => 'text',
'size' => 'normal',
'not null' => TRUE,
],
'link' => [
// 'description' => 'Serialized object of type Minishlink\WebPush\Subscription',
'type' => 'text',
'size' => 'normal',
'not null' => FALSE,
],
'total' => [
'description' => 'The number of subscriptions that this notification was attempted to be sent to.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
],
'success' => [
'description' => 'The number of subscriptions that this notification was successfully sent to.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
],
],
'unique keys' => [
'id' => ['id'],
],
'primary key' => ['id'],
];
return $schema;
}
/**
* Implements hook_uninstall().
*
* At uninstall time we'll notify field.module that the entity was deleted
* so that attached fields can be cleaned up.
*/
function webpush_uninstall() {
field_attach_delete_bundle('webpush_subscription', 'webpush_subscription');
field_attach_delete_bundle('webpush_notification', 'webpush_notification');
variable_delete('webpush_public_key');
variable_delete('webpush_private_key');
variable_delete('webpush_link_type');
variable_delete('webpush_icon_fid');
variable_delete('webpush_badge_fid');
variable_delete('webpush_keep_invalid_subscriptions');
}