Repository navigation
Expand file tree
/
Copy pathsetup.php
More file actions
246 lines (213 loc) · 10.3 KB
/
Copy pathsetup.php
File metadata and controls
246 lines (213 loc) · 10.3 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?php
/**
* -----------------------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
*
* @copyright Copyright (c) 2026 Rafael Mendes
* @license GPLv3+ <https://www.gnu.org/licenses/gpl-3.0.html>
* @link GitHub <https://github.com/mendescrafael>
*
* This file is part of Plugin Feed.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* -----------------------------------------------------------------------------
*/
use Glpi\Plugin\Hooks;
use GlpiPlugin\Feed\Action;
use GlpiPlugin\Feed\ActionPreference;
use GlpiPlugin\Feed\MonitoredItemTypes;
define('PLUGIN_FEED_VERSION', '1.0.0');
define('PLUGIN_FEED_MIN_GLPI', '11.0.0');
define('PLUGIN_FEED_MAX_GLPI', '11.99.99');
/**
* Inicializa os hooks, classes, recursos visuais e eventos monitorados pelo plugin.
*
* @return void
*/
function plugin_init_feed(): void
{
global $PLUGIN_HOOKS;
$PLUGIN_HOOKS[Hooks::CSRF_COMPLIANT]['feed'] = true;
// Carrega os recursos globais responsáveis pelo painel lateral.
$PLUGIN_HOOKS[Hooks::ADD_CSS]['feed'][] = 'css/sidebar.css';
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['feed'][] = 'js/sidebar.js';
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['feed'][] = 'js/config.js';
Plugin::registerClass(Action::class);
Plugin::registerClass(ActionPreference::class);
// Adiciona a página completa de ações ao menu Ferramentas.
$PLUGIN_HOOKS[Hooks::MENU_TOADD]['feed'] = [
'tools' => Action::class,
];
// Tipos gerais que não exigem tratamento especializado.
foreach (MonitoredItemTypes::GENERAL as $itemtype) {
if (!class_exists($itemtype)) {
continue;
}
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed'][$itemtype] = 'plugin_feed_item_add';
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['feed'][$itemtype] = 'plugin_feed_item_update';
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['feed'][$itemtype] = 'plugin_feed_item_delete';
$PLUGIN_HOOKS[Hooks::ITEM_RESTORE]['feed'][$itemtype] = 'plugin_feed_item_restore';
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['feed'][$itemtype] = 'plugin_feed_item_purge';
}
// Acompanhamentos apontam para o chamado, mudança ou problema ao qual pertencem.
if (class_exists(ITILFollowup::class)) {
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed'][ITILFollowup::class] = 'plugin_feed_followup_add';
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['feed'][ITILFollowup::class] = 'plugin_feed_followup_update';
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['feed'][ITILFollowup::class] = 'plugin_feed_followup_delete';
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['feed'][ITILFollowup::class] = 'plugin_feed_followup_delete';
}
// Documentos são registrados no item ao qual foram anexados.
if (class_exists(Document_Item::class)) {
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed'][Document_Item::class] = 'plugin_feed_document_add';
}
// Projetos possuem eventos próprios para gerente e membros da equipe.
if (class_exists(Project::class)) {
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed'][Project::class] = 'plugin_feed_project_add';
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['feed'][Project::class] = 'plugin_feed_project_update';
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['feed'][Project::class] = 'plugin_feed_project_delete';
$PLUGIN_HOOKS[Hooks::ITEM_RESTORE]['feed'][Project::class] = 'plugin_feed_project_restore';
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['feed'][Project::class] = 'plugin_feed_project_purge';
}
if (class_exists('ProjectTeam')) {
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed']['ProjectTeam'] = 'plugin_feed_project_team_add';
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['feed']['ProjectTeam'] = 'plugin_feed_project_team_delete';
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['feed']['ProjectTeam'] = 'plugin_feed_project_team_delete';
}
// Tarefas de projeto e integrantes das respectivas equipes.
if (class_exists(ProjectTask::class)) {
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed'][ProjectTask::class] = 'plugin_feed_project_task_add';
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['feed'][ProjectTask::class] = 'plugin_feed_project_task_update';
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['feed'][ProjectTask::class] = 'plugin_feed_project_task_delete';
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['feed'][ProjectTask::class] = 'plugin_feed_project_task_delete';
}
if (class_exists(ProjectTaskTeam::class)) {
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed'][ProjectTaskTeam::class] = 'plugin_feed_project_task_team_add';
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['feed'][ProjectTaskTeam::class] = 'plugin_feed_project_task_team_delete';
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['feed'][ProjectTaskTeam::class] = 'plugin_feed_project_task_team_delete';
}
// Contratos possuem eventos próprios para os usuários diretamente vinculados.
if (class_exists(Contract::class)) {
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed'][Contract::class] = 'plugin_feed_contract_add';
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['feed'][Contract::class] = 'plugin_feed_contract_update';
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['feed'][Contract::class] = 'plugin_feed_contract_delete';
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['feed'][Contract::class] = 'plugin_feed_contract_delete';
}
// Ativos que podem possuir um usuário responsável.
foreach (MonitoredItemTypes::RESPONSIBLE_ASSETS as $itemtype) {
if (!class_exists($itemtype)) {
continue;
}
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed'][$itemtype] = 'plugin_feed_asset_add';
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['feed'][$itemtype] = 'plugin_feed_asset_update';
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['feed'][$itemtype] = 'plugin_feed_asset_delete';
$PLUGIN_HOOKS[Hooks::ITEM_RESTORE]['feed'][$itemtype] = 'plugin_feed_asset_restore';
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['feed'][$itemtype] = 'plugin_feed_asset_purge';
}
// Tarefas de chamados, mudanças e problemas.
foreach (MonitoredItemTypes::ITIL_TASKS as $itemtype) {
if (!class_exists($itemtype)) {
continue;
}
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed'][$itemtype] = 'plugin_feed_task_add';
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['feed'][$itemtype] = 'plugin_feed_task_update';
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['feed'][$itemtype] = 'plugin_feed_task_delete';
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['feed'][$itemtype] = 'plugin_feed_task_delete';
}
// A classe ITILSolution é compartilhada pelos três objetos ITIL.
if (class_exists(ITILSolution::class)) {
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed'][ITILSolution::class] = 'plugin_feed_solution_add';
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['feed'][ITILSolution::class] = 'plugin_feed_solution_update';
}
// Pedidos e respostas de aprovação.
foreach (MonitoredItemTypes::VALIDATIONS as $itemtype) {
if (!class_exists($itemtype)) {
continue;
}
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed'][$itemtype] = 'plugin_feed_validation_add';
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['feed'][$itemtype] = 'plugin_feed_validation_update';
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['feed'][$itemtype] = 'plugin_feed_validation_delete';
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['feed'][$itemtype] = 'plugin_feed_validation_delete';
}
// Relações de requerente, técnico e observador.
foreach (MonitoredItemTypes::USER_RELATIONS as $itemtype) {
if (!class_exists($itemtype)) {
continue;
}
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed'][$itemtype] = 'plugin_feed_relation_add';
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['feed'][$itemtype] = 'plugin_feed_relation_update';
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['feed'][$itemtype] = 'plugin_feed_relation_delete';
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['feed'][$itemtype] = 'plugin_feed_relation_delete';
}
// Vínculos nativos entre itens e objetos ITIL exibidos com categoria própria.
foreach (MonitoredItemTypes::ITEM_LINKS as $itemtype) {
if (!class_exists($itemtype)) {
continue;
}
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['feed'][$itemtype] = 'plugin_feed_item_link_add';
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['feed'][$itemtype] = 'plugin_feed_item_link_delete';
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['feed'][$itemtype] = 'plugin_feed_item_link_delete';
}
}
/**
* Retorna os metadados usados pelo gerenciador de plugins do GLPI.
*
* @return array<string, mixed> Metadados e requisitos do plugin.
*/
function plugin_version_feed(): array
{
return [
'name' => 'Feed',
'version' => PLUGIN_FEED_VERSION,
'author' => 'Rafael Mendes',
'license' => 'GPLv3+',
'homepage' => 'https://github.com/mendescrafael',
'requirements' => [
'glpi' => [
'min' => PLUGIN_FEED_MIN_GLPI,
'max' => PLUGIN_FEED_MAX_GLPI,
],
],
];
}
/**
* Valida a compatibilidade da versão atual do GLPI.
*
* @return bool `true` quando os pré-requisitos são atendidos.
*/
function plugin_feed_check_prerequisites(): bool
{
if (
version_compare(GLPI_VERSION, PLUGIN_FEED_MIN_GLPI, '<')
|| version_compare(GLPI_VERSION, PLUGIN_FEED_MAX_GLPI, '>')
) {
echo sprintf(
__('This plugin requires GLPI from version %1$s through %2$s.', 'feed'),
PLUGIN_FEED_MIN_GLPI,
PLUGIN_FEED_MAX_GLPI
);
return false;
}
return true;
}
/**
* Valida se a configuração do plugin está pronta para uso.
*
* @param bool $verbose Define se mensagens de falha devem ser exibidas.
*
* @return bool `true` quando a configuração é válida.
*/
function plugin_feed_check_config(bool $verbose = false): bool
{
return true;
}