-
Notifications
You must be signed in to change notification settings - Fork 0
/
recurly.install
157 lines (142 loc) · 4.63 KB
/
recurly.install
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
<?php
/**
* @file
* Install hooks for Recurly module.
*/
use Drupal\Component\Utility\Crypt;
use \Drupal\recurly\RecurlyClient;
/**
* Implements hook_requirements().
*/
function recurly_requirements($phase) {
$requirements = [];
if ($phase == 'runtime') {
$requirements['recurly'] = [
'title' => t('Recurly'),
];
if (RecurlyClient::loadLibrary()) {
$requirements['recurly']['value'] = t('The required Recurly PHP library is installed.');
$requirements['recurly']['severity'] = REQUIREMENT_OK;
}
else {
$requirements['recurly']['value'] = t('Not found');
$requirements['recurly']['description'] = t(
'The required Recurly PHP library is <em>not</em> installed. Please follow the installation instructions in the <a href=":doc_link">documentation</a>.', [
':doc_link' => 'https://matteobrusa.github.io/md-styler/?url=cgit.drupalcode.org/recurly/plain/README.md',
]
);
$requirements['recurly']['severity'] = REQUIREMENT_ERROR;
}
}
// Ensure cURL exists if SimpleTest hasn't checked it already.
if (!\Drupal::moduleHandler()->moduleExists('simpletest') && !function_exists('curl_init')) {
$requirements['recurly_curl'] = [
'title' => t('cURL'),
'severity' => REQUIREMENT_ERROR,
'description' => t('Recurly module requires the <a href="http://php.net/manual/en/curl.setup.php">PHP cURL library</a>.'),
];
}
return $requirements;
}
/**
* Implements hook_schema().
*/
function recurly_schema() {
$schema = [];
$schema['recurly_account'] = [
'description' => 'Recurly account information mapped to Drupal entities.',
'fields' => [
'account_code' => [
'description' => 'The unique identifier of the account in Recurly.',
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
'default' => '',
],
'status' => [
'description' => 'Whether the account is closed or active.',
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
'default' => '',
],
'entity_type' => [
'description' => 'The Drupal entity type this account is associated with, typical "user" or "node".',
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
'default' => '',
],
'entity_id' => [
'description' => 'The Drupal entity ID that maps to this account.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'updated' => [
'description' => 'The Unix timestamp when the account information was last updated.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
],
'primary key' => ['account_code'],
'indexes' => [
'entity_type_entity_id' => ['entity_type', 'entity_id'],
],
];
return $schema;
}
/**
* Implements hook_install().
*/
function recurly_install() {
// Initialize the Recurly listener key variable.
\Drupal::configFactory()->getEditable('recurly.settings')->set('recurly_listener_key', substr(Crypt::hashBase64(REQUEST_TIME), 0, 8))->save();
}
/**
* Implements hook_uninstall().
*/
function recurly_uninstall() {
// Remove the site-wide account settings.
\Drupal::configFactory()->getEditable('recurly.settings')
->clear('recurly_subdomain')
->clear('recurly_private_api_key')
->clear('recurly_public_key')
->clear('recurly_default_currency')
->clear('recurly_pages')
->clear('recurly_token_mapping')
->clear('recurly_subscription_cancel_behavior')
->clear('recurly_subscription_display')
->clear('recurly_subscription_downgrade_timeframe')
->clear('recurly_subscription_max')
->clear('recurly_subscription_plans')
->clear('recurly_subscription_upgrade_timeframe')
->clear('recurly_entity_type')
->save();
foreach (array_keys(\Drupal::entityTypeManager()->getDefinitions()) as $entity_name) {
\Drupal::configFactory()->getEditable('recurly.settings')->clear('recurly_bundle_' . $entity_name)->save();
}
// Remove the push notification settings.
\Drupal::configFactory()->getEditable('recurly.settings')
->clear('recurly_listener_key')
->clear('recurly_push_logging')
->save();
}
/**
* Enable the Token module.
*/
function recurly_update_8002() {
\Drupal::service('module_installer')->install(['token']);
}
/**
* Adds default entity type configuration.
*/
function recurly_update_8001() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('recurly.settings');
if (!$config->get('recurly_entity_type')) {
$config->set('recurly_entity_type', 'user');
$config->save(TRUE);
}
}