-
Notifications
You must be signed in to change notification settings - Fork 0
/
elereg.install
114 lines (105 loc) · 3.01 KB
/
elereg.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
<?php
/**
* @file
* Install, update and uninstall functions for the elereg module.
*/
use Drupal\node\Entity\Node;
/**
* Implements hook_install().
*/
function elereg_install():void
{
Drupal::messenger()->addStatus(__FUNCTION__);
}
/**
* Implements hook_uninstall().
*/
function elereg_uninstall():void
{
Drupal::messenger()->addStatus(__FUNCTION__);
}
/**
* Implements hook_schema().
*/
function elereg_schema():array
{
$schema['elereg_example'] = [
'description' => 'Table description.',
'fields' => [
'id' => [
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique record ID.',
],
'uid' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The {users}.uid of the user who created the record.',
],
'status' => [
'description' => 'Boolean indicating whether this record is active.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
],
'type' => [
'type' => 'varchar_ascii',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'Type of the record.',
],
'created' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Timestamp when the record was created.',
],
'data' => [
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
'description' => 'The arbitrary data for the item.',
],
],
'primary key' => ['id'],
'indexes' => [
'type' => ['type'],
'uid' => ['uid'],
'status' => ['status'],
],
];
return $schema;
}
/**
* Implements hook_requirements().
*/
function elereg_requirements($phase): array
{
$requirements = [];
if ($phase == 'runtime') {
$query = Drupal::entityQuery('node')->condition('type', 'sms')->condition('field_status', false)->sort('created', 'desc')->range(0, 1)->accessCheck(false);
$result = $query->execute();
$goodSend = $badSend = '';
if (count($result)) {
$badSend = Node::load(reset($result))->get('created')->getValue()[0]['value'];
$badSend = (new DateTimeImmutable())->setTimestamp($badSend)->format('Y-m-d H:i:s');
}
$query = Drupal::entityQuery('node')->condition('type', 'sms')->condition('field_status', true)->sort('created', 'desc')->range(0, 1)->accessCheck(false);
$result = $query->execute();
if (count($result)) {
$goodSend = Node::load(reset($result))->get('created')->getValue()[0]['value'];
$goodSend = (new DateTimeImmutable())->setTimestamp($goodSend)->format('Y-m-d H:i:s');
}
$requirements['elereg_status'] = [
'title' => t('elereg status'),
'value' => t('Last SMS: @good, <span style="color:red">Last bad SMS: @bad</span>', ['@bad' => $badSend, '@good' => $goodSend]),
'severity' => REQUIREMENT_INFO,
];
}
return $requirements;
}