- opções do projeto Redmine montadas no PHP (Twig merge renumera chaves inteiras) - aba mostra o NOME do projeto vinculado (não só o ID) - botão Desvincular (projeto e entidade) + dropdown só com projetos ativos Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
83 lines
3.2 KiB
PHP
83 lines
3.2 KiB
PHP
<?php
|
|
include ("../../../inc/includes.php");
|
|
|
|
Session::checkLoginUser();
|
|
|
|
if (isset($_POST["action"])) {
|
|
$action = $_POST["action"];
|
|
$entities_id = (int) $_POST["entities_id"];
|
|
|
|
// Permission check
|
|
$entity = new Entity();
|
|
if (!$entity->getFromDB($entities_id) || !$entity->can($entities_id, UPDATE)) {
|
|
Html::displayRightError();
|
|
}
|
|
|
|
global $DB;
|
|
|
|
if ($action === 'sync') {
|
|
$metadata = PluginRedmineRedmineapi::syncMetadata();
|
|
if ($metadata !== false) {
|
|
$DB->update('glpi_plugin_redmine_configs', [
|
|
'metadata_cache' => json_encode($metadata)
|
|
], ['id' => 1]);
|
|
PluginRedmineRedmineapi::syncUsers();
|
|
Session::addMessageAfterRedirect(__('Metadados sincronizados com sucesso!', 'redmine'));
|
|
} else {
|
|
Session::addMessageAfterRedirect(__('Erro ao sincronizar com o Redmine.', 'redmine'), false, ERROR);
|
|
}
|
|
}
|
|
elseif ($action === 'set_category') {
|
|
$DB->update('glpi_plugin_redmine_entities', [
|
|
'default_category_id' => (int) ($_POST['default_category_id'] ?? 0)
|
|
], [
|
|
'entities_id' => $entities_id
|
|
]);
|
|
Session::addMessageAfterRedirect(__('Categoria padrão salva com sucesso!', 'redmine'));
|
|
}
|
|
elseif ($action === 'unlink') {
|
|
$DB->delete('glpi_plugin_redmine_entities', ['entities_id' => $entities_id]);
|
|
Session::addMessageAfterRedirect(__('Entidade desvinculada do Redmine.', 'redmine'));
|
|
}
|
|
elseif ($action === 'process') {
|
|
$redmine_project_id = $_POST['redmine_project_id'] ?? '';
|
|
|
|
if (!empty($redmine_project_id)) {
|
|
// LINK OPERATION
|
|
$DB->insert('glpi_plugin_redmine_entities', [
|
|
'entities_id' => $entities_id,
|
|
'redmine_project_id' => $redmine_project_id
|
|
]);
|
|
Session::addMessageAfterRedirect(__('Entidade vinculada com sucesso!', 'redmine'));
|
|
} 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) {
|
|
$DB->insert('glpi_plugin_redmine_entities', [
|
|
'entities_id' => $entities_id,
|
|
'redmine_project_id' => $new_redmine_id
|
|
]);
|
|
Session::addMessageAfterRedirect(__('Projeto criado e vinculado à entidade com sucesso!', 'redmine'));
|
|
} else {
|
|
Session::addMessageAfterRedirect(__('Erro ao criar projeto no Redmine.', 'redmine'), false, ERROR);
|
|
}
|
|
}
|
|
}
|
|
|
|
Html::redirect($CFG_GLPI["root_doc"] . "/front/entity.form.php?id=" . $entities_id);
|
|
}
|
|
|
|
Html::displayErrorAndDie("Lost");
|