Skip to content

Commit bbfb879

Browse files
committed
feat: #64 log title when image not exist
1 parent 6b9846a commit bbfb879

File tree

7 files changed

+274
-5
lines changed

7 files changed

+274
-5
lines changed

app/Coding/Wiki.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function createWiki($token, $projectName, $data)
2525
return json_decode($response->getBody(), true)['Response']['Data'];
2626
}
2727

28-
public function createMarkdownZip($markdown, $path, $markdownFilename): bool|string
28+
public function createMarkdownZip($markdown, $path, $markdownFilename, $title): bool|string
2929
{
3030
$zipFileFullPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $markdownFilename . '-' . Str::uuid() . '.zip';
3131
if ($this->zipArchive->open($zipFileFullPath, ZipArchive::CREATE) !== true) {
@@ -41,7 +41,7 @@ public function createMarkdownZip($markdown, $path, $markdownFilename): bool|str
4141
$filename = $tmp[0];
4242
$filepath = $path . DIRECTORY_SEPARATOR . $filename;
4343
if (!file_exists($filepath)) {
44-
error_log("文件不存在$filename");
44+
Log::error("文件不存在", ['filename' => $filename, 'title' => $title]);
4545
continue;
4646
}
4747
$this->zipArchive->addFile($filepath, $filename);

app/Commands/WikiImportCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private function uploadConfluencePages(string $dataPath, array $tree, array $tit
212212
if ($this->option('save-markdown')) {
213213
file_put_contents($dataPath . $mdFilename, $markdown . "\n");
214214
}
215-
$zipFilePath = $this->codingWiki->createMarkdownZip($markdown, $dataPath, $mdFilename);
215+
$zipFilePath = $this->codingWiki->createMarkdownZip($markdown, $dataPath, $mdFilename, $title);
216216
$result = $this->codingWiki->createWikiByUploadZip(
217217
$this->codingToken,
218218
$this->codingProjectUri,

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"ext-json": "*",
2323
"ext-libxml": "*",
2424
"ext-zip": "*",
25+
"illuminate/log": "^8.0",
2526
"laravel-fans/confluence": "^0.1.1",
2627
"laravel-zero/framework": "^8.8",
2728
"league/html-to-markdown": "^5.0",

composer.lock

Lines changed: 146 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/logging.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
use Monolog\Handler\NullHandler;
4+
use Monolog\Handler\StreamHandler;
5+
use Monolog\Handler\SyslogUdpHandler;
6+
7+
return [
8+
9+
/*
10+
|--------------------------------------------------------------------------
11+
| Default Log Channel
12+
|--------------------------------------------------------------------------
13+
|
14+
| This option defines the default log channel that gets used when writing
15+
| messages to the logs. The name specified in this option should match
16+
| one of the channels defined in the "channels" configuration array.
17+
|
18+
*/
19+
20+
'default' => env('LOG_CHANNEL', 'stack'),
21+
22+
/*
23+
|--------------------------------------------------------------------------
24+
| Log Channels
25+
|--------------------------------------------------------------------------
26+
|
27+
| Here you may configure the log channels for your application. Out of
28+
| the box, Laravel uses the Monolog PHP logging library. This gives
29+
| you a variety of powerful log handlers / formatters to utilize.
30+
|
31+
| Available Drivers: "single", "daily", "slack", "syslog",
32+
| "errorlog", "monolog",
33+
| "custom", "stack"
34+
|
35+
*/
36+
37+
'channels' => [
38+
'stack' => [
39+
'driver' => 'stack',
40+
'channels' => ['stderr'],
41+
'ignore_exceptions' => false,
42+
],
43+
44+
'single' => [
45+
'driver' => 'single',
46+
'path' => storage_path('logs/laravel.log'),
47+
'level' => 'debug',
48+
],
49+
50+
'daily' => [
51+
'driver' => 'daily',
52+
'path' => storage_path('logs/laravel.log'),
53+
'level' => 'debug',
54+
'days' => 14,
55+
],
56+
57+
'slack' => [
58+
'driver' => 'slack',
59+
'url' => env('LOG_SLACK_WEBHOOK_URL'),
60+
'username' => 'Laravel Log',
61+
'emoji' => ':boom:',
62+
'level' => 'critical',
63+
],
64+
65+
'papertrail' => [
66+
'driver' => 'monolog',
67+
'level' => 'debug',
68+
'handler' => SyslogUdpHandler::class,
69+
'handler_with' => [
70+
'host' => env('PAPERTRAIL_URL'),
71+
'port' => env('PAPERTRAIL_PORT'),
72+
],
73+
],
74+
75+
'stderr' => [
76+
'driver' => 'monolog',
77+
'handler' => StreamHandler::class,
78+
'formatter' => env('LOG_STDERR_FORMATTER'),
79+
'with' => [
80+
'stream' => 'php://stderr',
81+
],
82+
],
83+
84+
'syslog' => [
85+
'driver' => 'syslog',
86+
'level' => 'debug',
87+
],
88+
89+
'errorlog' => [
90+
'driver' => 'errorlog',
91+
'level' => 'debug',
92+
],
93+
94+
'null' => [
95+
'driver' => 'monolog',
96+
'handler' => NullHandler::class,
97+
],
98+
99+
'emergency' => [
100+
'path' => storage_path('logs/laravel.log'),
101+
],
102+
],
103+
104+
];

tests/Unit/CodingWikiTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use GuzzleHttp\Client;
66
use GuzzleHttp\Psr7\Response;
7+
use Illuminate\Support\Facades\Log;
78
use Illuminate\Support\Facades\Storage;
89
use Tests\TestCase;
910
use ZipArchive;
@@ -109,7 +110,7 @@ public function testCreateMarkdownZip()
109110
$filename = 'image-demo_65619.md';
110111
$markdown = file_get_contents($path . $filename);
111112
$coding = new Wiki();
112-
$zipFile = $coding->createMarkdownZip($markdown, $path, $filename);
113+
$zipFile = $coding->createMarkdownZip($markdown, $path, $filename, 'hello');
113114

114115
$this->assertTrue(file_exists($zipFile));
115116
$zip = new ZipArchive();
@@ -120,6 +121,23 @@ public function testCreateMarkdownZip()
120121
$this->assertEquals('attachments/65619/65623.png', $zip->getNameIndex(2));
121122
}
122123

124+
public function testCreateMarkdownZipButImageNotExist()
125+
{
126+
$path = $this->dataDir . 'confluence/';
127+
$filename = 'image-not-exist-demo.md';
128+
$markdown = file_get_contents($path . $filename);
129+
$coding = new Wiki();
130+
Log::shouldReceive('error')
131+
->with('文件不存在', ['filename' => 'not/exist.png', 'title' => 'hello']);
132+
$zipFile = $coding->createMarkdownZip($markdown, $path, $filename, 'hello');
133+
134+
$this->assertTrue(file_exists($zipFile));
135+
$zip = new ZipArchive();
136+
$zip->open($zipFile);
137+
$this->assertEquals(1, $zip->numFiles);
138+
$this->assertEquals($filename, $zip->getNameIndex(0));
139+
}
140+
123141
public function testGetImportJobStatus()
124142
{
125143
$responseBody = file_get_contents($this->dataDir . 'coding/DescribeImportJobStatusResponse.json');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
![](not/exist.png)world

0 commit comments

Comments
 (0)