|
7 | 7 | use Confluence\Content;
|
8 | 8 | use DOMDocument;
|
9 | 9 | use Exception;
|
| 10 | +use Illuminate\Contracts\Filesystem\FileNotFoundException; |
10 | 11 | use Illuminate\Support\Str;
|
11 | 12 | use LaravelFans\Confluence\Facades\Confluence;
|
12 | 13 | use LaravelZero\Framework\Commands\Command;
|
@@ -192,26 +193,13 @@ private function uploadConfluencePages(string $dataPath, array $tree, array $tit
|
192 | 193 | foreach ($tree as $page => $subPages) {
|
193 | 194 | $title = $titles[$page];
|
194 | 195 | $this->info('标题:' . $title);
|
195 |
| - $markdown = $this->confluence->htmlFile2Markdown($dataPath . $page); |
196 |
| - $attachments = $this->confluence->parseAttachments($dataPath . $page, $markdown); |
197 |
| - $codingAttachments = $this->codingDisk->uploadAttachments( |
198 |
| - $this->codingToken, |
199 |
| - $this->codingProjectUri, |
200 |
| - $dataPath, |
201 |
| - $attachments |
202 |
| - ); |
203 |
| - foreach ($codingAttachments as $attachmentPath => $codingAttachment) { |
204 |
| - if (empty($codingAttachment)) { |
205 |
| - $message = '错误:文件上传失败 ' . $attachmentPath; |
206 |
| - $this->error($message); |
207 |
| - $this->errors[] = $message; |
208 |
| - } |
209 |
| - } |
210 |
| - $markdown = $this->codingWiki->replaceAttachments($markdown, $codingAttachments); |
211 |
| - $mdFilename = substr($page, 0, -5) . '.md'; |
212 |
| - if ($this->option('save-markdown')) { |
213 |
| - file_put_contents($dataPath . $mdFilename, $markdown . "\n"); |
| 196 | + try { |
| 197 | + $markdown = $this->confluence->htmlFile2Markdown($dataPath . $page); |
| 198 | + } catch (FileNotFoundException $e) { |
| 199 | + $this->error('页面不存在:' . $dataPath . $page); |
| 200 | + continue; |
214 | 201 | }
|
| 202 | + $mdFilename = $this->dealAttachments($dataPath, $page, $markdown); |
215 | 203 | $zipFilePath = $this->codingWiki->createMarkdownZip($markdown, $dataPath, $mdFilename, $title);
|
216 | 204 | $result = $this->codingWiki->createWikiByUploadZip(
|
217 | 205 | $this->codingToken,
|
@@ -277,4 +265,28 @@ private function unzipConfluenceHtml(): string
|
277 | 265 | }
|
278 | 266 | return str_ends_with($dataPath, '/index.html') ? substr($dataPath, 0, -10) : Str::finish($dataPath, '/');
|
279 | 267 | }
|
| 268 | + |
| 269 | + private function dealAttachments(string $dataPath, string $page, string $markdown): string |
| 270 | + { |
| 271 | + $attachments = $this->confluence->parseAttachments($dataPath . $page, $markdown); |
| 272 | + $codingAttachments = $this->codingDisk->uploadAttachments( |
| 273 | + $this->codingToken, |
| 274 | + $this->codingProjectUri, |
| 275 | + $dataPath, |
| 276 | + $attachments |
| 277 | + ); |
| 278 | + foreach ($codingAttachments as $attachmentPath => $codingAttachment) { |
| 279 | + if (empty($codingAttachment)) { |
| 280 | + $message = '错误:文件上传失败 ' . $attachmentPath; |
| 281 | + $this->error($message); |
| 282 | + $this->errors[] = $message; |
| 283 | + } |
| 284 | + } |
| 285 | + $markdown = $this->codingWiki->replaceAttachments($markdown, $codingAttachments); |
| 286 | + $mdFilename = substr($page, 0, -5) . '.md'; |
| 287 | + if ($this->option('save-markdown')) { |
| 288 | + file_put_contents($dataPath . $mdFilename, $markdown . "\n"); |
| 289 | + } |
| 290 | + return $mdFilename; |
| 291 | + } |
280 | 292 | }
|
0 commit comments