From 913fd82272ed5db0a988712db2dd164ad232de99 Mon Sep 17 00:00:00 2001 From: Gemini Date: Tue, 30 Jun 2026 16:32:52 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20recria=20issue=20se=20a=20vinculada=20fo?= =?UTF-8?q?i=20apagada=20no=20Redmine=20(v=C3=ADnculo=20=C3=B3rf=C3=A3o)?= =?UTF-8?q?=20(1.5.5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 --- CHANGELOG.md | 7 +++++++ hook.php | 13 +++++++++++-- inc/redmineapi.class.php | 10 ++++++++++ setup.php | 2 +- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 513124b..330c1f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ Todas as mudanças relevantes deste plugin são documentadas aqui. O formato segue [Keep a Changelog](https://keepachangelog.com/pt-BR/1.0.0/) e o versionamento segue [SemVer](https://semver.org/lang/pt-BR/). +## [1.5.5] + +### Corrigido +- Se a issue Redmine vinculada a um chamado foi **apagada** no Redmine, o plugin + reusava o ID órfão e falhava ("Tarefa não é válido"). Agora ele verifica se a + issue ainda existe; se não, remove o vínculo órfão e **recria** a issue. + ## [1.5.4] ### Corrigido diff --git a/hook.php b/hook.php index 273789f..0c5c26e 100644 --- a/hook.php +++ b/hook.php @@ -366,8 +366,17 @@ function _plugin_redmine_process_tickettask(TicketTask $task) { 'WHERE' => ['tickets_id' => $ticketId] ]); if (count($issueMap) > 0) { - $issueId = (int) $issueMap->current()['redmine_issue_id']; - } else { + $candidate = (int) $issueMap->current()['redmine_issue_id']; + if (PluginRedmineRedmineapi::issueExists($candidate)) { + $issueId = $candidate; + } else { + // A issue foi apagada no Redmine: remove o vínculo órfão e recria. + Toolbox::logInFile('redmine', "Issue #{$candidate} do ticket #{$ticketId} não existe mais; recriando.\n"); + $DB->delete('glpi_plugin_redmine_tickets', ['tickets_id' => $ticketId]); + } + } + + if (!$issueId) { // Build the issue from the ticket + the configured defaults. $cfg = PluginRedmineConfig::getConfigRow(); $extra = []; diff --git a/inc/redmineapi.class.php b/inc/redmineapi.class.php index c8a7653..28a906f 100644 --- a/inc/redmineapi.class.php +++ b/inc/redmineapi.class.php @@ -257,6 +257,16 @@ class PluginRedmineRedmineapi { return ($result && isset($result['issue_categories'])) ? $result['issue_categories'] : []; } + /** + * Whether a Redmine issue still exists (returns false if it was deleted). + * @param int $issueId + * @return bool + */ + public static function issueExists($issueId) { + $result = self::get("/issues/{$issueId}.json"); + return $result && isset($result['issue']['id']); + } + /** * Get all Redmine users (paginated). Requires admin API key. * @return array diff --git a/setup.php b/setup.php index 91bdb19..5738353 100644 --- a/setup.php +++ b/setup.php @@ -1,6 +1,6 @@