-
Notifications
You must be signed in to change notification settings - Fork 2
/
openai.install
55 lines (50 loc) · 1.67 KB
/
openai.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
<?php
/**
* Implements hook_requirements().
*/
function openai_requirements($phase) {
$requirements = [];
if ($phase == 'runtime') {
// Check if the Key module is enabled.
if (!module_exists('key')) {
$requirements['openai'] = [
'title' => t('OpenAI'),
'value' => t('Key module not enabled'),
'severity' => REQUIREMENT_ERROR,
'description' => t(
'The OpenAI module requires the Key module to securely manage the API key. Enable the Key module from the <a href="@modules">modules page</a>.',
['@modules' => url('admin/modules')]
),
];
} else {
// Check if a valid key has been selected in the OpenAI settings.
$config = config_get('openai.settings');
$key_id = $config['api_key'];
if (!empty($key_id) && key_get_key($key_id)) {
$requirements['openai'] = [
'title' => t('OpenAI'),
'value' => t('API key detected and managed via Key module'),
'severity' => REQUIREMENT_OK,
];
} else {
$requirements['openai'] = [
'title' => t('OpenAI'),
'value' => t('API key not configured'),
'severity' => REQUIREMENT_ERROR,
'description' => t(
'An API key is required for OpenAI functionality. Configure the key in the <a href="@settings">OpenAI settings</a>.',
['@settings' => url('admin/config/openai/settings')]
),
];
}
}
}
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function openai_uninstall() {
// Delete configuration on uninstall.
config('openai.settings')->delete();
}