Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d28398b

Browse files
feat: #70 clean instead of continue
1 parent 8160c1a commit d28398b

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

‎app/Commands/WikiImportCommand.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎tests/Feature/WikiImportCommandTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use App\Coding\Disk;
66
use App\Coding\Wiki;
77
use Confluence\Content;
8-
use Illuminate\Support\Facades\File;
98
use LaravelFans\Confluence\Facades\Confluence;
109
use Mockery\MockInterface;
1110
use Tests\TestCase;
@@ -181,8 +180,10 @@ public function testHandleConfluenceHtmlSuccess()
181180
$this->instance(Disk::class, $mockDisk);
182181
$mockDisk->shouldReceive('uploadAttachments')->times(4)->andReturn([]);
183182

184-
File::delete($this->dataDir . '/confluence/space1/success.log');
185-
$this->artisan('wiki:import', ['--save-markdown' => true, '--continue' => true])
183+
$log = "image-demo_65619.html = 27\n"
184+
. "65591.html = 27\n";
185+
file_put_contents($this->dataDir . '/confluence/space1/success.log', $log);
186+
$this->artisan('wiki:import', ['--save-markdown' => true, '--clean' => true])
186187
->expectsQuestion('数据来源?', 'Confluence')
187188
->expectsQuestion('数据类型?', 'HTML')
188189
->expectsQuestion('空间导出的 HTML zip 文件路径', $this->dataDir . 'confluence/space1/')
@@ -334,7 +335,7 @@ public function testHandleConfluenceHtmlContinueSuccess()
334335
$log = "image-demo_65619.html = 27\n"
335336
. "65591.html = 27\n";
336337
file_put_contents($this->dataDir . '/confluence/space1/success.log', $log);
337-
$this->artisan('wiki:import', ['--continue' => true])
338+
$this->artisan('wiki:import')
338339
->expectsQuestion('数据来源?', 'Confluence')
339340
->expectsQuestion('数据类型?', 'HTML')
340341
->expectsQuestion('空间导出的 HTML zip 文件路径', $this->dataDir . 'confluence/space1/')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /