@@ -39,7 +39,7 @@ class WikiImportCommand extends Command
3939 {--coding_team_domain= : CODING 团队域名,如 xxx.coding.net 即填写 xxx}
4040 {--coding_project_uri= : CODING 项目标识,如 xxx.coding.net/p/yyy 即填写 yyy}
4141 {--save-markdown : 本地保留生成的 Markdown 文件}
42- {--continue : 断点续传 }
42+ {--clean : 清除上次产生的本地临时文件,比如断点续传的日志 }
4343 ' ;
4444
4545 /**
@@ -186,6 +186,7 @@ private function handleConfluenceHtml(): int
186186 }
187187 $ this ->info ('发现 ' . count ($ pages ['tree ' ]) . ' 个一级页面 ' );
188188 $ this ->info ("开始导入 CODING: " );
189+ $ this ->clean ($ htmlDir );
189190 $ this ->uploadConfluencePages ($ htmlDir , $ pages ['tree ' ], $ pages ['titles ' ]);
190191 } catch (\ErrorException $ e ) {
191192 $ this ->error ($ e ->getMessage ());
@@ -195,11 +196,18 @@ private function handleConfluenceHtml(): int
195196 return 0 ;
196197 }
197198
198- private function uploadConfluencePages (string $ htmlDir, array $ tree , array $ titles , int $ parentId = 0 ): void
199+ private function clean (string $ htmlDir ): void
199200 {
200- if ($ this ->option ('continue ' ) && file_exists ($ htmlDir . DIRECTORY_SEPARATOR . 'success.log ' )) {
201+ if ($ this ->option ('clean ' )) {
202+ File::delete ($ htmlDir . DIRECTORY_SEPARATOR . 'success.log ' );
203+ }
204+ if (file_exists ($ htmlDir . DIRECTORY_SEPARATOR . 'success.log ' )) {
201205 $ this ->importedPages = parse_ini_file ($ htmlDir . DIRECTORY_SEPARATOR . 'success.log ' );
202206 }
207+ }
208+
209+ private function uploadConfluencePages (string $ htmlDir , array $ tree , array $ titles , int $ parentId = 0 ): void
210+ {
203211 foreach ($ tree as $ page => $ subPages ) {
204212 $ title = $ titles [$ page ];
205213 $ wikiId = $ this ->uploadConfluencePage ($ htmlDir . DIRECTORY_SEPARATOR . $ page , $ title , $ parentId );
@@ -214,7 +222,7 @@ private function uploadConfluencePages(string $htmlDir, array $tree, array $titl
214222 private function uploadConfluencePage (string $ filePath , string $ title = '' , int $ parentId = 0 ): int
215223 {
216224 $ page = basename ($ filePath );
217- if ($ this ->option ('continue ' ) && isset ($ this ->importedPages [$ page ])) {
225+ if (! $ this ->option ('clean ' ) && isset ($ this ->importedPages [$ page ])) {
218226 $ this ->warn ('断点续传,跳过页面: ' . $ page );
219227 return $ this ->importedPages [$ page ];
220228 }
@@ -247,7 +255,6 @@ private function uploadConfluencePage(string $filePath, string $title = '', int
247255 $ parentId ,
248256 );
249257 $ this ->info ('上传成功,正在处理,任务 ID: ' . $ result ['JobId ' ]);
250- $ wikiId = null ;
251258 try {
252259 $ jobStatus = $ this ->codingWiki ->getImportJobStatusWithRetry (
253260 $ this ->codingToken ,
@@ -265,9 +272,7 @@ private function uploadConfluencePage(string $filePath, string $title = '', int
265272 return false ;
266273 }
267274 $ this ->codingWiki ->updateTitle ($ this ->codingToken , $ this ->codingProjectUri , $ wikiId , $ title );
268- if ($ this ->option ('continue ' )) {
269- file_put_contents ($ htmlDir . DIRECTORY_SEPARATOR . 'success.log ' , "$ page = $ wikiId \n" , FILE_APPEND );
270- }
275+ file_put_contents ($ htmlDir . DIRECTORY_SEPARATOR . 'success.log ' , "$ page = $ wikiId \n" , FILE_APPEND );
271276 return $ wikiId ;
272277 }
273278
0 commit comments