@@ -39,7 +39,7 @@ class WikiImportCommand extends Command
39
39
{--coding_team_domain= : CODING 团队域名,如 xxx.coding.net 即填写 xxx}
40
40
{--coding_project_uri= : CODING 项目标识,如 xxx.coding.net/p/yyy 即填写 yyy}
41
41
{--save-markdown : 本地保留生成的 Markdown 文件}
42
- {--continue : 断点续传 }
42
+ {--clean : 清除上次产生的本地临时文件,比如断点续传的日志 }
43
43
' ;
44
44
45
45
/**
@@ -186,6 +186,7 @@ private function handleConfluenceHtml(): int
186
186
}
187
187
$ this ->info ('发现 ' . count ($ pages ['tree ' ]) . ' 个一级页面 ' );
188
188
$ this ->info ("开始导入 CODING: " );
189
+ $ this ->clean ($ htmlDir );
189
190
$ this ->uploadConfluencePages ($ htmlDir , $ pages ['tree ' ], $ pages ['titles ' ]);
190
191
} catch (\ErrorException $ e ) {
191
192
$ this ->error ($ e ->getMessage ());
@@ -195,11 +196,18 @@ private function handleConfluenceHtml(): int
195
196
return 0 ;
196
197
}
197
198
198
- private function uploadConfluencePages (string $ htmlDir, array $ tree , array $ titles , int $ parentId = 0 ): void
199
+ private function clean (string $ htmlDir ): void
199
200
{
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 ' )) {
201
205
$ this ->importedPages = parse_ini_file ($ htmlDir . DIRECTORY_SEPARATOR . 'success.log ' );
202
206
}
207
+ }
208
+
209
+ private function uploadConfluencePages (string $ htmlDir , array $ tree , array $ titles , int $ parentId = 0 ): void
210
+ {
203
211
foreach ($ treeas $ page => $ subPages ) {
204
212
$ title = $ titles [$ page ];
205
213
$ wikiId = $ this ->uploadConfluencePage ($ htmlDir . DIRECTORY_SEPARATOR . $ page , $ title , $ parentId );
@@ -214,7 +222,7 @@ private function uploadConfluencePages(string $htmlDir, array $tree, array $titl
214
222
private function uploadConfluencePage (string $ filePath , string $ title = '' , int $ parentId = 0 ): int
215
223
{
216
224
$ page = basename ($ filePath );
217
- if ($ this ->option ('continue ' ) && isset ($ this ->importedPages [$ page ])) {
225
+ if (! $ this ->option ('clean ' ) && isset ($ this ->importedPages [$ page ])) {
218
226
$ this ->warn ('断点续传,跳过页面: ' . $ page );
219
227
return $ this ->importedPages [$ page ];
220
228
}
@@ -247,7 +255,6 @@ private function uploadConfluencePage(string $filePath, string $title = '', int
247
255
$ parentId ,
248
256
);
249
257
$ this ->info ('上传成功,正在处理,任务 ID: ' . $ result ['JobId ' ]);
250
- $ wikiId = null ;
251
258
try {
252
259
$ jobStatus = $ this ->codingWiki ->getImportJobStatusWithRetry (
253
260
$ this ->codingToken ,
@@ -265,9 +272,7 @@ private function uploadConfluencePage(string $filePath, string $title = '', int
265
272
return false ;
266
273
}
267
274
$ 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 );
271
276
return $ wikiId ;
272
277
}
273
278
0 commit comments