@@ -18,6 +18,8 @@ class WikiImportCommand extends Command
18
18
19
19
protected Disk $ codingDisk ;
20
20
protected Wiki $ codingWiki ;
21
+ protected array $ errors = [];
22
+
21
23
/**
22
24
* The signature of the command.
23
25
*
@@ -81,12 +83,21 @@ public function handle(Disk $codingDisk, Wiki $codingWiki, \App\Confluence $conf
81
83
}
82
84
switch ($ dataType ) {
83
85
case 'HTML ' :
84
- return $ this ->handleConfluenceHtml ();
86
+ $ this ->handleConfluenceHtml ();
87
+ break ;
85
88
case 'API ' :
86
- return $ this ->handleConfluenceApi ();
89
+ $ this ->handleConfluenceApi ();
90
+ break ;
87
91
default :
88
92
break ;
89
93
}
94
+ if (!empty ($ this ->errors )) {
95
+ $ this ->info ('报错信息汇总: ' );
96
+ }
97
+ foreach ($ this ->errors as $ error ) {
98
+ $ this ->error ($ error );
99
+ }
100
+ return count ($ this ->errors );
90
101
}
91
102
92
103
private function createWiki ($ data )
@@ -139,7 +150,9 @@ private function handleConfluenceHtml(): int
139
150
$ htmlDir = $ this ->unzipConfluenceHtml ();
140
151
$ filePath = $ htmlDir . 'index.html ' ;
141
152
if (!file_exists ($ filePath )) {
142
- $ this ->error ("文件不存在: $ filePath " );
153
+ $ message = "文件不存在: $ filePath " ;
154
+ $ this ->error ($ message );
155
+ $ this ->errors [] = $ message ;
143
156
return 1 ;
144
157
}
145
158
try {
@@ -187,6 +200,13 @@ private function uploadConfluencePages(string $dataPath, array $tree, array $tit
187
200
$ dataPath ,
188
201
$ attachments
189
202
);
203
+ foreach ($ codingAttachments as $ attachmentPath => $ codingAttachment ) {
204
+ if (empty ($ codingAttachment )) {
205
+ $ message = '错误:文件上传失败 ' . $ attachmentPath ;
206
+ $ this ->error ($ message );
207
+ $ this ->errors [] = $ message ;
208
+ }
209
+ }
190
210
$ markdown = $ this ->codingWiki ->replaceAttachments ($ markdown , $ codingAttachments );
191
211
$ mdFilename = substr ($ page , 0 , -5 ) . '.md ' ;
192
212
if ($ this ->option ('save-markdown ' )) {
@@ -208,14 +228,18 @@ private function uploadConfluencePages(string $dataPath, array $tree, array $tit
208
228
$ result ['JobId ' ]
209
229
);
210
230
} catch (Exception $ e ) {
211
- $ this ->error ('错误:导入失败,跳过 ' );
231
+ $ message = '错误:导入失败,跳过 ' . $ title . ' ' . $ page ;
232
+ $ this ->error ($ message );
233
+ $ this ->errors [] = $ message ;
212
234
continue ;
213
235
}
214
236
if ($ jobStatus ['Status ' ] == 'success ' ) {
215
237
$ wikiId = intval ($ jobStatus ['Iids ' ][0 ]);
216
238
}
217
239
if (empty ($ wikiId )) {
218
- $ this ->error ('错误:导入失败,跳过 ' );
240
+ $ message = '错误:导入失败,跳过 ' . $ title . ' ' . $ page ;
241
+ $ this ->error ($ message );
242
+ $ this ->errors [] = $ message ;
219
243
continue ;
220
244
}
221
245
$ this ->codingWiki ->updateTitle ($ this ->codingToken , $ this ->codingProjectUri , $ wikiId , $ title );
0 commit comments