-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhook.php
More file actions
151 lines (128 loc) · 5.48 KB
/
hook.php
File metadata and controls
151 lines (128 loc) · 5.48 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
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* Hook file for Ticket Answers plugin
*/
function plugin_ticketanswers_install() {
/** @var DBmysql $DB */
global $DB;
// Criar a tabela de visualizações se não existir
if (!$DB->tableExists('glpi_plugin_ticketanswers_views')) {
$table = 'glpi_plugin_ticketanswers_views';
$DB->doQuery("CREATE TABLE IF NOT EXISTS `$table` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`ticket_id` VARCHAR(255) NOT NULL,
`users_id` int unsigned NOT NULL,
`followup_id` VARCHAR(255) NOT NULL,
`viewed_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`message_id` VARCHAR(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_view` (`users_id`, `ticket_id`, `followup_id`),
KEY `idx_users_id` (`users_id`),
KEY `idx_ticket_id` (`ticket_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC");
}
// Criar a tabela de preferências de notificação se não existir
if (!$DB->tableExists('glpi_plugin_ticketanswers_notification_prefs')) {
$table = 'glpi_plugin_ticketanswers_notification_prefs';
$DB->doQuery("CREATE TABLE IF NOT EXISTS `$table` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`users_id` int unsigned NOT NULL,
`enable_sound` tinyint(1) NOT NULL DEFAULT 1,
`sound_volume` int NOT NULL DEFAULT 70,
`check_interval` int NOT NULL DEFAULT 5,
`notifications_per_page` int NOT NULL DEFAULT 10,
PRIMARY KEY (`id`),
UNIQUE KEY `users_id` (`users_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC");
}
// Instalar direitos de perfil
PluginTicketanswersProfile::install();
return true;
}
function plugin_ticketanswers_update($current_version) {
/** @var DBmysql $DB */
global $DB;
$migration = new Migration(PLUGIN_TICKETANSWERS_VERSION);
$table = 'glpi_plugin_ticketanswers_views';
// Se estiver atualizando de uma versão anterior à 1.1.1
if (version_compare($current_version, '1.1.1', '<')) {
// Verificar se a coluna existe e alterar seu tipo
if ($DB->fieldExists($table, 'message_id')) {
$migration->changeField($table, 'message_id', 'message_id', 'varchar(20)');
$migration->migrationOneTable($table);
// Registrar a alteração no log
Toolbox::logInFile('plugin_ticketanswers', "Coluna message_id alterada para VARCHAR(20)\n");
}
}
// Atualizar para versão 2.0.0 (GLPI 11)
if (version_compare($current_version, '2.0.0', '<')) {
// Adicionar índices se não existirem
if ($DB->tableExists($table)) {
// Verificar e adicionar índice users_id
if (!$DB->indexExists($table, 'idx_users_id')) {
$migration->addKey($table, 'users_id', 'idx_users_id');
}
// Verificar e adicionar índice ticket_id
if (!$DB->indexExists($table, 'idx_ticket_id')) {
$migration->addKey($table, 'ticket_id', 'idx_ticket_id');
}
// Executar migração
$migration->migrationOneTable($table);
}
// Criar tabela de preferências se não existir
if (!$DB->tableExists('glpi_plugin_ticketanswers_notification_prefs')) {
$prefs_table = 'glpi_plugin_ticketanswers_notification_prefs';
$migration->createTable($prefs_table, [
'id' => [
'type' => 'int unsigned',
'notnull' => true,
'autoincrement' => true
],
'users_id' => [
'type' => 'int unsigned',
'notnull' => true
],
'enable_sound' => [
'type' => 'bool',
'notnull' => true,
'default' => 1
],
'sound_volume' => [
'type' => 'int',
'notnull' => true,
'default' => 70
],
'check_interval' => [
'type' => 'int',
'notnull' => true,
'default' => 5
],
'notifications_per_page' => [
'type' => 'int',
'notnull' => true,
'default' => 10
]
]);
$migration->addKey($prefs_table, 'users_id', 'users_id', 'UNIQUE');
$migration->migrationOneTable($prefs_table);
}
// Atualizar direitos de perfil
PluginTicketanswersProfile::install();
Toolbox::logInFile('plugin_ticketanswers', "Plugin atualizado para versão 2.0.1 (GLPI 11)\n");
}
return true;
}
function plugin_ticketanswers_uninstall() {
/** @var DBmysql $DB */
global $DB;
// Remover direitos de perfil
PluginTicketanswersProfile::uninstall();
// Remover tabelas
if ($DB->tableExists("glpi_plugin_ticketanswers_views")) {
$DB->doQuery("DROP TABLE `glpi_plugin_ticketanswers_views`");
}
if ($DB->tableExists("glpi_plugin_ticketanswers_notification_prefs")) {
$DB->doQuery("DROP TABLE `glpi_plugin_ticketanswers_notification_prefs`");
}
return true;
}