Redmine/front/project.form.php
Gemini 80d1576a80 Redmine Integration 1.3.0
Plugin de integração GLPI <-> Redmine:
- Config nativa (Twig) com API key cifrada (GLPIKey)
- Vínculo projeto GLPI <-> projeto Redmine (aba do projeto) + categoria por vínculo
- 1 issue Redmine por chamado; defaults (tracker/priority/activity) e mapa de status
- Tempo das TicketTasks -> time entries (gate em "Feito"), idempotente
- Autores via impersonation (X-Redmine-Switch-User) + auto-membership por role
- Mapeamento de usuários GLPI->Redmine (auto-match por e-mail + overrides)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-29 18:32:19 -03:00

88 lines
3.1 KiB
PHP

<?php
include ("../../../inc/includes.php");
Session::checkLoginUser();
if (isset($_POST["action"])) {
$action = $_POST["action"];
$projects_id = $_POST["projects_id"];
// Permission check
$project = new Project();
if (!$project->getFromDB($projects_id) || !$project->can($projects_id, UPDATE)) {
Html::displayRightError();
}
if ($action === 'sync') {
// Fetch projects from Redmine and cache them
$redmine_projects = PluginRedmineRedmineapi::getProjects();
if ($redmine_projects !== false) {
global $DB;
$metadata = ['projects' => $redmine_projects];
$DB->update('glpi_plugin_redmine_configs', [
'metadata_cache' => json_encode($metadata)
], [
'id' => 1
]);
Session::addMessageAfterRedirect("Metadados sincronizados com sucesso!");
} else {
Session::addMessageAfterRedirect("Erro ao sincronizar com Redmine.", false, ERROR);
}
}
elseif ($action === 'set_category') {
global $DB;
$DB->update('glpi_plugin_redmine_projects', [
'default_category_id' => (int) ($_POST['default_category_id'] ?? 0)
], [
'projects_id' => $projects_id
]);
Session::addMessageAfterRedirect("Categoria padrão salva com sucesso!");
}
elseif ($action === 'process') {
$redmine_project_id = $_POST['redmine_project_id'] ?? '';
if (!empty($redmine_project_id)) {
// LINK OPERATION
global $DB;
$DB->insert('glpi_plugin_redmine_projects', [
'projects_id' => $projects_id,
'redmine_project_id' => $redmine_project_id
]);
Session::addMessageAfterRedirect("Projeto vinculado com sucesso!");
} else {
// CREATE OPERATION
$payload = [
'name' => $_POST['name'],
'identifier' => $_POST['identifier'],
'description' => $_POST['description'],
'is_public' => !empty($_POST['is_public'])
];
if (!empty($_POST['parent_id'])) {
$payload['parent_id'] = $_POST['parent_id'];
}
if (!empty($_POST['enabled_module_names'])) {
$payload['enabled_module_names'] = $_POST['enabled_module_names'];
}
$new_redmine_id = PluginRedmineRedmineapi::createProjectFull($payload);
if ($new_redmine_id) {
global $DB;
$DB->insert('glpi_plugin_redmine_projects', [
'projects_id' => $projects_id,
'redmine_project_id' => $new_redmine_id
]);
Session::addMessageAfterRedirect("Projeto criado e vinculado com sucesso!");
} else {
Session::addMessageAfterRedirect("Erro ao criar projeto no Redmine.", false, ERROR);
}
}
}
Html::redirect($CFG_GLPI["root_doc"] . "/front/project.form.php?id=" . $projects_id);
}
Html::displayErrorAndDie("Lost");