From aa72fa19ed4f532e7defb1f25bd14e3d1597aa23 Mon Sep 17 00:00:00 2001 From: Thomas Hackl <thomas.hackl@uni-passau.de> Date: Sat, 14 Jul 2018 15:22:57 +0200 Subject: [PATCH] migrate ticket attachments to issues --- src/GitLab.php | 2 +- src/Migration.php | 8 ++++---- src/Trac.php | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/GitLab.php b/src/GitLab.php index 2fef53d..3b78dec 100644 --- a/src/GitLab.php +++ b/src/GitLab.php @@ -48,7 +48,7 @@ class GitLab $page = 1; // Stop when we either have all users or we have exhausted the sane number of attempts while (!$gotAll && $page < USER_FETCH_MAX_PAGES) { - $response = $this->client->api('users')->all(null, $page++, USER_FETCH_PAGE_SIZE); + $response = $this->client->api('users')->all([], $page++, USER_FETCH_PAGE_SIZE); foreach($response as $user) { $users[$user['username']] = $user; // We assume that 'Administrator' user is in there diff --git a/src/Migration.php b/src/Migration.php index e353a9b..86f1e16 100644 --- a/src/Migration.php +++ b/src/Migration.php @@ -123,7 +123,7 @@ class Migration $commentAuthor = $this->getGitLabUser($comment['author']); $commentAuthorId = is_array($commentAuthor) ? $commentAuthor['id'] : null; $commentText = $this->translateTracToMarkdown($comment['text']); - $note = $this->gitLab->createNote($gitLabProject, $issue['id'], $commentText, $commentAuthorId); + $note = $this->gitLab->createNote($gitLabProject, $issue['iid'], $commentText, $commentAuthorId); } echo "\tAlso created " . count($ticket[4]) . " note(s)\n"; }*/ @@ -133,12 +133,12 @@ class Migration */ foreach ($attachments as $a) { - $file = file_put_contents($a['filename'], $a['content']['__jsonclass__'][1]); + file_put_contents($a['filename'], base64_decode($a['content'])); - $this->gitLab->createIssueAttachment($gitLabProject, $issue['id'], $a['filename'], $a['author']); + $this->gitLab->createIssueAttachment($gitLabProject, $issue['iid'], $a['filename'], $a['author']); unlink($a['filename']); - echo "\tAttached file " . $a['filename'] . " to issue " . $issue['id'] . ".\n"; + echo "\tAttached file " . $a['filename'] . " to issue " . $issue['iid'] . ".\n"; } } diff --git a/src/Trac.php b/src/Trac.php index f263dee..22542cf 100644 --- a/src/Trac.php +++ b/src/Trac.php @@ -68,9 +68,11 @@ class Trac $attachments = $this->client->execute('ticket.listAttachments', [$id]); foreach ($attachments as $attachment) { + $data = $this->client->execute('ticket.getAttachment', [$id, $attachment[0]]); + $result[] = [ 'filename' => $attachment[0], - 'content' => $this->client->execute('ticket.getAttachment', [$id, $attachment[0]]), + 'content' => $data['__jsonclass__'][1], 'author' => $attachment[4] ]; -- GitLab