From 69dfa583bccd2b21b3f86efa99c98783e3086eb2 Mon Sep 17 00:00:00 2001
From: Thomas Hackl <thomas.hackl@uni-passau.de>
Date: Sat, 14 Jul 2018 17:46:39 +0200
Subject: [PATCH] close Gitlab issue if Trac ticket was already closed

---
 src/GitLab.php    | 11 +++++++++++
 src/Migration.php |  8 +++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/GitLab.php b/src/GitLab.php
index 3cef1ac..56f79b2 100644
--- a/src/GitLab.php
+++ b/src/GitLab.php
@@ -86,6 +86,17 @@ class GitLab
 		return $issue;
 	}
 
+    /**
+	 * Closes an issue.
+     * @param mixed $projectId project ID or path
+     * @param int $issueId issue to close
+     * @param string $time time in ISO8601 format
+     */
+	public function closeIssue($projectId, $issueId, $time) {
+		$this->client->api('issues')->update($projectId, $issueId,
+			['state_event' => 'close', 'updated_at' => $time]);
+	}
+
 	/**
 	 * Creates a new note in the given project and on the given issue id (NOTE: id, not iid). When working in admin mode, tries to create the note
 	 * as the given author (SUDO) and if that fails, tries creating the note again as the admin.
diff --git a/src/Migration.php b/src/Migration.php
index bc6cc31..82f27c9 100644
--- a/src/Migration.php
+++ b/src/Migration.php
@@ -128,9 +128,6 @@ class Migration
 				echo "\tAlso created " . count($ticket[4]) . " note(s)\n";
 			}*/
 
-			// Map old image filenames to new markdown links
-			$images = [];
-
             /*
              * Add files attached to Trac ticket to new Gitlab issue.
              */
@@ -144,6 +141,11 @@ class Migration
                 echo "\tAttached file " . $a['filename'] . " to issue " . $issue['iid'] . ".\n";
             }
 
+			// Close issue if Trac ticket was closed.
+			if ($ticket[3]['status'] === 'closed') {
+				$this->gitLab->closeIssue($gitLabProject, $issue['iid'], $dateUpdated);
+			}
+
 		}
         return $mapping;
 	}
-- 
GitLab