Skip to content

Commit 9557fab

Browse files
committed
1.2.1
1 parent cde34d6 commit 9557fab

File tree

6 files changed

+180
-108
lines changed

6 files changed

+180
-108
lines changed

inc/RRAssignmentsEntity.class.php

Lines changed: 120 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function cleanUp() {
3535
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - entrou...');
3636

3737
/**
38-
* remover configurações
38+
* Remover configurações
3939
*/
4040
if ($this->DB->tableExists($this->rrAssignmentTable)) {
4141
$sqlDropAssign = <<< EOT
@@ -48,7 +48,7 @@ public function cleanUp() {
4848
}
4949

5050
/**
51-
* remover opções
51+
* Remover opções
5252
*/
5353
if ($this->DB->tableExists($this->rrOptionsTable)) {
5454
$sqlDropOptions = <<< EOT
@@ -64,35 +64,34 @@ public function cleanUp() {
6464
protected function createTable() {
6565
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - entrou...');
6666

67-
/**
68-
* criar tabela de configurações
69-
*/
67+
// Criar tabela de configurações
7068
if (!$this->DB->tableExists($this->rrAssignmentTable)) {
7169
$sqlCreateAssign = <<< EOT
72-
CREATE TABLE IF NOT EXISTS {$this->rrAssignmentTable} (
73-
id INT(11) NOT NULL auto_increment,
74-
itilcategories_id INT(11),
75-
is_active INT(1) DEFAULT 0,
76-
last_assignment_index INT(11) DEFAULT NULL,
77-
PRIMARY KEY (id),
78-
UNIQUE INDEX ix_itilcategories_uq (itilcategories_id ASC)
79-
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
70+
CREATE TABLE IF NOT EXISTS {$this->rrAssignmentTable} (
71+
id INT(11) NOT NULL AUTO_INCREMENT,
72+
itilcategories_id INT(11),
73+
is_active INT(1) DEFAULT 0,
74+
last_assignment_index INT(11) DEFAULT NULL,
75+
PRIMARY KEY (id),
76+
UNIQUE INDEX ix_itilcategories_uq (itilcategories_id ASC)
77+
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
8078
EOT;
8179
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlCreate: ' . $sqlCreateAssign);
8280
$this->DB->queryOrDie($sqlCreateAssign, $this->DB->error());
8381
}
8482

8583
/**
86-
* criar tabela de opções
84+
* Criar tabela de opções
8785
*/
8886
if (!$this->DB->tableExists($this->rrOptionsTable)) {
8987
$sqlCreateOption = <<< EOT
90-
CREATE TABLE IF NOT EXISTS {$this->rrOptionsTable} (
91-
id INT(11) UNSIGNED NOT NULL auto_increment,
92-
auto_assign_group INT(1) DEFAULT 1,
93-
auto_assign_tipe INT(1) DEFAULT 1,
94-
PRIMARY KEY (id)
95-
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
88+
CREATE TABLE IF NOT EXISTS {$this->rrOptionsTable} (
89+
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
90+
auto_assign_group INT(1) DEFAULT 1,
91+
auto_assign_type INT(1) DEFAULT 1,
92+
auto_assign_mode INT(1) DEFAULT 1,
93+
PRIMARY KEY (id)
94+
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
9695
EOT;
9796
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlCreate: ' . $sqlCreateOption);
9897
$this->DB->queryOrDie($sqlCreateOption, $this->DB->error());
@@ -103,7 +102,7 @@ protected function truncateTable() {
103102
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - entrou...');
104103

105104
/**
106-
* limpar todas as configurações
105+
* Limpar todas as configurações
107106
*/
108107
if ($this->DB->tableExists($this->rrAssignmentTable)) {
109108
$sqlTruncAssign = <<< EOT
@@ -114,7 +113,7 @@ protected function truncateTable() {
114113
}
115114

116115
/**
117-
* limpar todas as opções
116+
* Limpar todas as opções
118117
*/
119118
if ($this->DB->tableExists($this->rrOptionsTable)) {
120119
$sqlTruncOptions = <<< EOT
@@ -142,10 +141,10 @@ protected function insertAllItilCategory() {
142141
}
143142

144143
public function insertItilCategory($itilCategory) {
145-
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - entrou...');
144+
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - entered...');
146145

147146
/**
148-
* inserir uma única entrada
147+
* insert a single entry
149148
*/
150149
$sqlInsert = <<< EOT
151150
INSERT INTO {$this->rrAssignmentTable} (itilcategories_id) VALUES ({$itilCategory})
@@ -157,117 +156,151 @@ public function insertItilCategory($itilCategory) {
157156
public function insertOptions() {
158157
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - entrou...');
159158

160-
// inserir entrada
161-
$sqlInsert = <<< EOT
162-
INSERT INTO {$this->rrOptionsTable} (auto_assign_group, auto_assign_tipe)
163-
VALUES (1, 1)
164-
EOT;
159+
// Inserir entrada
160+
$sqlInsert = <<< EOT
161+
INSERT INTO {$this->rrOptionsTable} (auto_assign_group, auto_assign_type, auto_assign_mode)
162+
VALUES (1, 1, 1)
163+
EOT;
165164
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlInsert: ' . $sqlInsert);
166165
$this->DB->queryOrDie($sqlInsert, $this->DB->error());
167166
}
168167

169168
public function getOptionAutoAssignGroup() {
170169
$sql = <<< EOT
171-
SELECT auto_assign_group FROM {$this->rrOptionsTable} LIMIT 1
172-
EOT;
170+
SELECT auto_assign_group FROM {$this->rrOptionsTable} LIMIT 1
171+
EOT;
173172
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sql: ' . $sql);
174173
$resultCollection = $this->DB->queryOrDie($sql, $this->DB->error());
175174
$resultArray = iterator_to_array($resultCollection);
176175
return $resultArray[0]['auto_assign_group'];
177176
}
178177

179-
public function getOptionAutoAssignTipe() {
178+
public function getOptionAutoAssignType() {
180179
$sql = <<< EOT
181-
SELECT auto_assign_tipe FROM {$this->rrOptionsTable} LIMIT 1
182-
EOT;
180+
SELECT auto_assign_type FROM {$this->rrOptionsTable} LIMIT 1
181+
EOT;
183182
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sql: ' . $sql);
184183
$resultCollection = $this->DB->queryOrDie($sql, $this->DB->error());
185184
$resultArray = iterator_to_array($resultCollection);
186-
return $resultArray[0]['auto_assign_tipe'];
185+
return $resultArray[0]['auto_assign_type'];
186+
}
187+
188+
public function getOptionAutoAssignMode() {
189+
$sql = <<< EOT
190+
SELECT auto_assign_mode FROM {$this->rrOptionsTable} LIMIT 1
191+
EOT;
192+
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sql: ' . $sql);
193+
$resultCollection = $this->DB->queryOrDie($sql, $this->DB->error());
194+
$resultArray = iterator_to_array($resultCollection);
195+
return $resultArray[0]['auto_assign_mode'];
187196
}
188197

189198
public function getGroupByItilCategory($itilCategory) {
190199
$sql = <<< EOT
191-
SELECT groups_id FROM glpi_itilcategories
192-
WHERE id = {$itilCategory}
193-
EOT;
200+
SELECT groups_id FROM glpi_itilcategories
201+
WHERE id = {$itilCategory}
202+
EOT;
194203
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sql: ' . $sql);
195204
$resultCollection = $this->DB->queryOrDie($sql, $this->DB->error());
196205
$resultArray = iterator_to_array($resultCollection);
197206
$groupsId = $resultArray[0]['groups_id'];
198207
return $groupsId !== 0 ? $groupsId : false;
199208
}
200209

201-
public function updateAutoAssignGroup($autoAssignGroup) {
202-
global $DB; // Certifique-se de usar a instância global do banco de dados
210+
public function updateAutoAssignGroup($autoAssignGroup) {
211+
global $DB; // Certifique-se de usar a instância global do banco de dados
203212

204-
// Escape do valor para evitar SQL Injection
205-
$escapedValue = $DB->escape($autoAssignGroup);
213+
// Escape do valor para evitar SQL Injection
214+
$escapedValue = intval($autoAssignGroup);
206215

207-
$sqlUpdate = <<< EOT
208-
UPDATE {$this->rrOptionsTable}
209-
SET auto_assign_group = {$escapedValue}
210-
WHERE id = 1
211-
EOT;
216+
$sqlUpdate = <<< EOT
217+
UPDATE {$this->rrOptionsTable}
218+
SET auto_assign_group = {$escapedValue}
219+
WHERE id = 1
220+
EOT;
212221

213-
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlUpdate: ' . $sqlUpdate);
222+
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlUpdate: ' . $sqlUpdate);
214223

215-
// Executa a query
216-
$DB->queryOrDie($sqlUpdate, $DB->error());
217-
}
224+
// Executa a query
225+
$DB->queryOrDie($sqlUpdate, $DB->error());
226+
}
218227

219-
public function updateAutoAssignTipe($autoAssignTipe) {
220-
global $DB; // Certifique-se de usar a instância global do banco de dados
228+
public function updateAutoAssignType($autoAssignType) {
229+
global $DB; // Certifique-se de usar a instância global do banco de dados
221230

222-
// Escape do valor para evitar SQL Injection
223-
$escapedValue = $DB->escape($autoAssignTipe);
231+
// Escape do valor para evitar SQL Injection
232+
$escapedValue = intval($autoAssignType);
224233

225-
$sqlUpdate = <<< EOT
226-
UPDATE {$this->rrOptionsTable}
227-
SET auto_assign_tipe = {$escapedValue}
228-
WHERE id = 1
229-
EOT;
234+
$sqlUpdate = <<< EOT
235+
UPDATE {$this->rrOptionsTable}
236+
SET auto_assign_type = {$escapedValue}
237+
WHERE id = 1
238+
EOT;
239+
240+
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlUpdate: ' . $sqlUpdate);
241+
242+
// Executa a query
243+
$DB->queryOrDie($sqlUpdate, $DB->error());
244+
}
230245

231-
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlUpdate: ' . $sqlUpdate);
246+
public function updateAutoAssignMode($autoAssignMode) {
247+
global $DB; // Certifique-se de usar a instância global do banco de dados
232248

233-
// Executa a query
234-
$DB->queryOrDie($sqlUpdate, $DB->error());
235-
}
249+
// Escape do valor para evitar SQL Injection
250+
$escapedValue = intval($autoAssignMode);
251+
252+
$sqlUpdate = <<< EOT
253+
UPDATE {$this->rrOptionsTable}
254+
SET auto_assign_mode = {$escapedValue}
255+
WHERE id = 1
256+
EOT;
257+
258+
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlUpdate: ' . $sqlUpdate);
259+
260+
// Executa a query
261+
$DB->queryOrDie($sqlUpdate, $DB->error());
262+
}
236263

237264
public function deleteItilCategory($itilCategory) {
238265
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - entrou...');
239266

240-
// excluir uma única entrada
267+
// Excluir uma única entrada
268+
$itilCategory = intval($itilCategory);
241269
$sqlDelete = <<< EOT
242-
DELETE FROM {$this->rrAssignmentTable} WHERE itilcategories_id = {$itilCategory}
243-
EOT;
270+
DELETE FROM {$this->rrAssignmentTable} WHERE itilcategories_id = {$itilCategory}
271+
EOT;
244272
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlDelete: ' . $sqlDelete);
245273
$this->DB->queryOrDie($sqlDelete, $this->DB->error());
246274
}
247275

248-
// Acionado com quanto Tipo for Categoria
276+
// Acionado quando o Tipo for Categoria
249277
public function updateLastAssignmentIndexCategoria($itilcategoriesId, $index) {
278+
$itilcategoriesId = intval($itilcategoriesId);
279+
$index = intval($index);
280+
250281
$sqlUpdate = <<< EOT
251-
UPDATE {$this->rrAssignmentTable}
252-
SET last_assignment_index = {$index}
253-
WHERE itilcategories_id = {$itilcategoriesId}
254-
EOT;
282+
UPDATE {$this->rrAssignmentTable}
283+
SET last_assignment_index = {$index}
284+
WHERE itilcategories_id = {$itilcategoriesId}
285+
EOT;
255286
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlUpdate: ' . $sqlUpdate);
256287
$this->DB->queryOrDie($sqlUpdate, $this->DB->error());
257288
}
258289

259-
// Acionado com quanto Tipo for Grupo
290+
// Acionado quando o Tipo for Grupo
260291
public function updateLastAssignmentIndexGrupo($itilcategoriesId, $index) {
261292
// Obtém o grupo responsável pela categoria fornecida
262293
$groupId = $this->getGroupByItilCategory($itilcategoriesId);
263-
294+
264295
if ($groupId !== false) {
296+
$itilcategoriesId = intval($itilcategoriesId);
297+
$index = intval($index);
265298
$sqlUpdate = <<<EOT
266299
UPDATE {$this->rrAssignmentTable} AS ra
267300
JOIN glpi_itilcategories AS ic ON ra.itilcategories_id = ic.id
268301
SET ra.last_assignment_index = {$index}
269302
WHERE ra.is_active = 1 AND ic.groups_id = {$groupId}
270-
EOT;
303+
EOT;
271304
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlUpdate: ' . $sqlUpdate);
272305
$this->DB->queryOrDie($sqlUpdate, $this->DB->error());
273306
} else {
@@ -276,27 +309,31 @@ public function updateLastAssignmentIndexGrupo($itilcategoriesId, $index) {
276309
}
277310

278311
public function updateIsActive($itilcategoriesId, $isActive) {
312+
$itilcategoriesId = intval($itilcategoriesId);
313+
$isActive = intval($isActive);
314+
279315
$sqlUpdate = <<< EOT
280-
UPDATE {$this->rrAssignmentTable}
281-
SET is_active = {$isActive}
282-
WHERE itilcategories_id = {$itilcategoriesId}
283-
EOT;
316+
UPDATE {$this->rrAssignmentTable}
317+
SET is_active = {$isActive}
318+
WHERE itilcategories_id = {$itilcategoriesId}
319+
EOT;
284320
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlUpdate: ' . $sqlUpdate);
285321
$this->DB->queryOrDie($sqlUpdate, $this->DB->error());
286322
}
287323

288324
public function getLastAssignmentIndex($itilcategoriesId) {
325+
$itilcategoriesId = intval($itilcategoriesId);
289326
$sql = <<< EOT
290-
SELECT last_assignment_index FROM {$this->rrAssignmentTable}
291-
WHERE itilcategories_id = {$itilcategoriesId} AND is_active = 1
292-
EOT;
327+
SELECT last_assignment_index FROM {$this->rrAssignmentTable}
328+
WHERE itilcategories_id = {$itilcategoriesId} AND is_active = 1
329+
EOT;
293330
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sql: ' . $sql);
294331
$resultCollection = $this->DB->queryOrDie($sql, $this->DB->error());
295332
$resultArray = iterator_to_array($resultCollection);
296333
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - $resultArray: ' . print_r($resultArray, true));
297334
if (count($resultArray) === 0 || count($resultArray) > 1) {
298335
/**
299-
* para o comportamento especificado da categoria não é necessário
336+
* Para o comportamento especificado da categoria não é necessário
300337
* ou existem mais de uma linha para a categoria
301338
*/
302339
return false;
@@ -356,5 +393,4 @@ public function getAll() {
356393
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - $resultArray: ' . print_r($resultArray, true));
357394
return $resultArray;
358395
}
359-
360396
}

inc/TicketHookHandler.class.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function assignTicket(CommonDBTM $item) {
8484
$newAssignmentIndex = 0;
8585
}
8686
}
87-
if ($this->rrAssignmentsEntity->getOptionAutoAssignTipe() === 1) {
87+
if ($this->rrAssignmentsEntity->getOptionAutoAssignType() === 1) {
8888
$this->rrAssignmentsEntity->updateLastAssignmentIndexCategoria($itilcategoriesId, $newAssignmentIndex);
8989
} else {
9090
$this->rrAssignmentsEntity->updateLastAssignmentIndexGrupo($itilcategoriesId, $newAssignmentIndex);
@@ -122,18 +122,28 @@ protected function setAssignment($ticketId, $userId, $itilcategoriesId) {
122122
DELETE FROM glpi_groups_tickets
123123
WHERE tickets_id = {$ticketId};
124124
EOT;
125-
126125
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlDelete_glpi_groups_tickets: ' . $sqlDelete_glpi_groups_tickets);
127126
$this->DB->queryOrDie($sqlDelete_glpi_groups_tickets, $this->DB->error());
128127

129128
/**
130129
* insert the new assignment, based on rr
131130
*/
132131
$sqlInsert_glpi_tickets_users = <<< EOT
133-
INSERT INTO glpi_tickets_users (tickets_id, users_id, type, use_notification, alternative_email) VALUES ({$ticketId}, {$userId}, 2, 1, '')
132+
INSERT INTO glpi_tickets_users (tickets_id, users_id, type, use_notification, alternative_email) VALUES ({$ticketId}, {$userId}, 2, 1, '');
134133
EOT;
135134
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlInsert_glpi_tickets_users: ' . $sqlInsert_glpi_tickets_users);
136135
$this->DB->queryOrDie($sqlInsert_glpi_tickets_users, $this->DB->error());
136+
137+
/**
138+
* insert the new assignment, based on rr
139+
*/
140+
$sqlUpdate_glpi_tickets = <<< EOT
141+
UPDATE glpi_tickets
142+
SET status = 2
143+
WHERE glpi_tickets.status = 1 AND glpi_tickets.id = {$ticketId};
144+
EOT;
145+
PluginSmartAssignLogger::addWarning(__FUNCTION__ . ' - sqlUpdate_glpi_tickets: ' . $sqlUpdate_glpi_tickets);
146+
$this->DB->queryOrDie($sqlUpdate_glpi_tickets, $this->DB->error());
137147

138148
// if auto group assign is enabled assign the group too
139149

0 commit comments

Comments
 (0)