@@ -18,6 +18,8 @@ class WikiImportCommand extends Command
1818
1919 protected Disk $ codingDisk ;
2020 protected Wiki $ codingWiki ;
21+ protected array $ errors = [];
22+
2123 /**
2224 * The signature of the command.
2325 *
@@ -81,12 +83,21 @@ public function handle(Disk $codingDisk, Wiki $codingWiki, \App\Confluence $conf
8183 }
8284 switch ($ dataType ) {
8385 case 'HTML ' :
84- return $ this ->handleConfluenceHtml ();
86+ $ this ->handleConfluenceHtml ();
87+ break ;
8588 case 'API ' :
86- return $ this ->handleConfluenceApi ();
89+ $ this ->handleConfluenceApi ();
90+ break ;
8791 default :
8892 break ;
8993 }
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 );
90101 }
91102
92103 private function createWiki ($ data )
@@ -139,7 +150,9 @@ private function handleConfluenceHtml(): int
139150 $ htmlDir = $ this ->unzipConfluenceHtml ();
140151 $ filePath = $ htmlDir . 'index.html ' ;
141152 if (!file_exists ($ filePath )) {
142- $ this ->error ("文件不存在: $ filePath " );
153+ $ message = "文件不存在: $ filePath " ;
154+ $ this ->error ($ message );
155+ $ this ->errors [] = $ message ;
143156 return 1 ;
144157 }
145158 try {
@@ -187,6 +200,13 @@ private function uploadConfluencePages(string $dataPath, array $tree, array $tit
187200 $ dataPath ,
188201 $ attachments
189202 );
203+ foreach ($ codingAttachments as $ attachmentPath => $ codingAttachment ) {
204+ if (empty ($ codingAttachment )) {
205+ $ message = '错误:文件上传失败 ' . $ attachmentPath ;
206+ $ this ->error ($ message );
207+ $ this ->errors [] = $ message ;
208+ }
209+ }
190210 $ markdown = $ this ->codingWiki ->replaceAttachments ($ markdown , $ codingAttachments );
191211 $ mdFilename = substr ($ page , 0 , -5 ) . '.md ' ;
192212 if ($ this ->option ('save-markdown ' )) {
@@ -208,14 +228,18 @@ private function uploadConfluencePages(string $dataPath, array $tree, array $tit
208228 $ result ['JobId ' ]
209229 );
210230 } catch (Exception $ e ) {
211- $ this ->error ('错误:导入失败,跳过 ' );
231+ $ message = '错误:导入失败,跳过 ' . $ title . ' ' . $ page ;
232+ $ this ->error ($ message );
233+ $ this ->errors [] = $ message ;
212234 continue ;
213235 }
214236 if ($ jobStatus ['Status ' ] == 'success ' ) {
215237 $ wikiId = intval ($ jobStatus ['Iids ' ][0 ]);
216238 }
217239 if (empty ($ wikiId )) {
218- $ this ->error ('错误:导入失败,跳过 ' );
240+ $ message = '错误:导入失败,跳过 ' . $ title . ' ' . $ page ;
241+ $ this ->error ($ message );
242+ $ this ->errors [] = $ message ;
219243 continue ;
220244 }
221245 $ this ->codingWiki ->updateTitle ($ this ->codingToken , $ this ->codingProjectUri , $ wikiId , $ title );
0 commit comments