44
55use App \Coding ;
66use Confluence \Content ;
7+ use DOMDocument ;
78use Illuminate \Support \Str ;
89use LaravelFans \Confluence \Facades \Confluence ;
910use LaravelZero \Framework \Commands \Command ;
@@ -37,22 +38,21 @@ class WikiImportCommand extends Command
3738 protected $ description = '从 Confluence 导入 Wiki ' ;
3839
3940 private \App \Confluence $ confluence ;
40- private \ DOMDocument $ document ;
41+ private DOMDocument $ document ;
4142
4243 /**
4344 * Execute the console command.
4445 *
4546 */
46- public function handle (Coding $ coding , \App \Confluence $ confluence , \ DOMDocument $ document ): int
47+ public function handle (Coding $ coding , \App \Confluence $ confluence , DOMDocument $ document ): int
4748 {
4849 $ this ->coding = $ coding ;
4950 $ this ->confluence = $ confluence ;
5051 $ this ->document = $ document ;
5152 $ this ->setCodingApi ();
5253
53- if ($ this ->option ('coding_import_provider ' )) {
54- $ provider = $ this ->option ('coding_import_provider ' );
55- } else {
54+ $ provider = $ this ->option ('coding_import_provider ' );
55+ if (is_null ($ provider )) {
5656 $ provider = config ('coding.import.provider ' ) ?? $ this ->choice (
5757 '数据来源? ' ,
5858 ['Confluence ' , 'MediaWiki ' ],
@@ -64,9 +64,8 @@ public function handle(Coding $coding, \App\Confluence $confluence, \DOMDocument
6464 return 1 ;
6565 }
6666
67- if ($ this ->option ('coding_import_data_type ' )) {
68- $ dataType = $ this ->option ('coding_import_data_type ' );
69- } else {
67+ $ dataType = $ this ->option ('coding_import_data_type ' );
68+ if (is_null ($ dataType )) {
7069 $ dataType = config ('coding.import.data_type ' ) ?? $ this ->choice (
7170 '数据类型? ' ,
7271 ['HTML ' , 'API ' ],
@@ -92,24 +91,21 @@ private function createWiki($data)
9291
9392 private function handleConfluenceApi (): int
9493 {
95- if ($ this ->option ('confluence_base_uri ' )) {
96- $ baseUri = $ this ->option ('confluence_base_uri ' );
97- } else {
94+ $ baseUri = $ this ->option ('confluence_base_uri ' );
95+ if (is_null ($ baseUri )) {
9896 $ baseUri = config ('confluence.base_uri ' ) ?? $ this ->ask (
9997 'Confluence API 链接: ' ,
10098 'http://localhost:8090/rest/api/ '
10199 );
102100 }
103101 config (['confluence.base_uri ' => $ baseUri ]);
104102
105- if ($ this ->option ('confluence_username ' )) {
106- $ username = $ this ->option ('confluence_username ' );
107- } else {
103+ $ username = $ this ->option ('confluence_username ' );
104+ if (is_null ($ username )) {
108105 $ username = config ('confluence.username ' ) ?? $ this ->ask ('Confluence 账号: ' , 'admin ' );
109106 }
110- if ($ this ->option ('confluence_password ' )) {
111- $ password = $ this ->option ('confluence_password ' );
112- } else {
107+ $ password = $ this ->option ('confluence_password ' );
108+ if (is_null ($ password )) {
113109 $ password = config ('confluence.password ' ) ?? $ this ->ask ('Confluence 密码: ' , '123456 ' );
114110 }
115111 config (['confluence.auth ' => [$ username , $ password ]]);
@@ -133,9 +129,8 @@ private function handleConfluenceApi(): int
133129
134130 private function handleConfluenceHtml (): int
135131 {
136- if ($ this ->option ('coding_import_data_path ' )) {
137- $ dataPath = $ this ->option ('coding_import_data_path ' );
138- } else {
132+ $ dataPath = $ this ->option ('coding_import_data_path ' );
133+ if (is_null ($ dataPath )) {
139134 $ dataPath = config ('coding.import.data_path ' ) ?? trim ($ this ->ask (
140135 '空间导出的 HTML 目录 ' ,
141136 './confluence/space1/ '
@@ -167,9 +162,8 @@ private function handleConfluenceHtml(): int
167162 if (empty ($ pages ['tree ' ])) {
168163 $ this ->info ("未发现有效数据 " );
169164 return 0 ;
170- } else {
171- $ this ->info ('发现 ' . count ($ pages ['tree ' ]) . ' 个一级页面 ' );
172165 }
166+ $ this ->info ('发现 ' . count ($ pages ['tree ' ]) . ' 个一级页面 ' );
173167 $ this ->info ("开始导入 CODING: " );
174168 $ this ->uploadConfluencePages ($ dataPath , $ pages ['tree ' ], $ pages ['titles ' ]);
175169 } catch (\ErrorException $ e ) {
@@ -196,7 +190,7 @@ private function uploadConfluencePages(string $dataPath, array $tree, array $tit
196190 );
197191 $ this ->info ('上传成功,正在处理,任务 ID: ' . $ result ['JobId ' ]);
198192 $ wikiId = null ;
199- $ waiting_times = 0 ;
193+ $ waitingTimes = 0 ;
200194 while (true ) {
201195 // HACK 如果上传成功立即查询,会报错:invoke function
202196 sleep (1 );
@@ -205,8 +199,8 @@ private function uploadConfluencePages(string $dataPath, array $tree, array $tit
205199 $ this ->codingProjectUri ,
206200 $ result ['JobId ' ]
207201 );
208- if (in_array ($ jobStatus ['Status ' ], ['wait_process ' , 'processing ' ]) && $ waiting_times < 10 ) {
209- $ waiting_times ++;
202+ if (in_array ($ jobStatus ['Status ' ], ['wait_process ' , 'processing ' ]) && $ waitingTimes < 10 ) {
203+ $ waitingTimes ++;
210204 continue ;
211205 }
212206 if ($ jobStatus ['Status ' ] == 'success ' ) {
0 commit comments