Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .git-pre-commit
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
#!/bin/sh
set -e

FILES=$(git diff --diff-filter=d --name-only HEAD | grep '.php$')
for file in $FILES; do
Expand Down
4 changes: 2 additions & 2 deletions app/Coding/Wiki.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,7 +25,7 @@ public function createWiki($token, $projectName, $data)
return json_decode($response->getBody(), true)['Response']['Data'];
}

public function createMarkdownZip($markdown, $path, $markdownFilename): bool|string
public function createMarkdownZip($markdown, $path, $markdownFilename, $title): bool|string
{
$zipFileFullPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $markdownFilename . '-' . Str::uuid() . '.zip'
if ($this->zipArchive->open($zipFileFullPath, ZipArchive::CREATE) !== true){
Expand All@@ -41,7 +41,7 @@ public function createMarkdownZip($markdown, $path, $markdownFilename): bool|str
$filename = $tmp[0];
$filepath = $path . DIRECTORY_SEPARATOR . $filename;
if (!file_exists($filepath)){
error_log("文件不存在$filename");
Log::error("文件不存在", ['filename' => $filename, 'title' => $title]);
continue;
}
$this->zipArchive->addFile($filepath, $filename);
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/WikiImportCommand.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -212,7 +212,7 @@ private function uploadConfluencePages(string $dataPath, array $tree, array $tit
if ($this->option('save-markdown')){
file_put_contents($dataPath . $mdFilename, $markdown . "\n");
}
$zipFilePath = $this->codingWiki->createMarkdownZip($markdown, $dataPath, $mdFilename);
$zipFilePath = $this->codingWiki->createMarkdownZip($markdown, $dataPath, $mdFilename, $title);
$result = $this->codingWiki->createWikiByUploadZip(
$this->codingToken,
$this->codingProjectUri,
Expand Down
2 changes: 2 additions & 0 deletions app/Confluence.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@

use DOMDocument;
use DOMXPath;
use League\HTMLToMarkdown\Converter\TableConverter;
use League\HTMLToMarkdown\HtmlConverter;

class Confluence
Expand All@@ -17,6 +18,7 @@ public function __construct(DOMDocument $document = null, HtmlConverter $htmlCon
$this->document = $document ?? new DOMDocument();
$this->htmlConverter = $htmlConverter ?? new HtmlConverter();
$this->htmlConverter->getConfig()->setOption('strip_tags', true);
$this->htmlConverter->getEnvironment()->addConverter(new TableConverter());
}

public function parsePageHtml(string $filename, string $spaceName): array
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,6 +22,7 @@
"ext-json": "*",
"ext-libxml": "*",
"ext-zip": "*",
"illuminate/log": "^8.0",
"laravel-fans/confluence": "^0.1.1",
"laravel-zero/framework": "^8.8",
"league/html-to-markdown": "^5.0",
Expand Down
147 changes: 146 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions config/logging.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
<?php

use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;

return [

/*
|--------------------------------------------------------------------------
| Default Log Channel
|--------------------------------------------------------------------------
|
| This option defines the default log channel that gets used when writing
| messages to the logs. The name specified in this option should match
| one of the channels defined in the "channels" configuration array.
|
*/

'default' => env('LOG_CHANNEL', 'stack'),

/*
|--------------------------------------------------------------------------
| Log Channels
|--------------------------------------------------------------------------
|
| Here you may configure the log channels for your application. Out of
| the box, Laravel uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Drivers: "single", "daily", "slack", "syslog",
| "errorlog", "monolog",
| "custom", "stack"
|
*/

'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['stderr'],
'ignore_exceptions' => false,
],

'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],

'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
],

'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'critical',
],

'papertrail' => [
'driver' => 'monolog',
'level' => 'debug',
'handler' => SyslogUdpHandler::class,
'handler_with' => [
'host' => env('PAPERTRAIL_URL'),
'port' => env('PAPERTRAIL_PORT'),
],
],

'stderr' => [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
'stream' => 'php://stderr',
],
],

'syslog' => [
'driver' => 'syslog',
'level' => 'debug',
],

'errorlog' => [
'driver' => 'errorlog',
'level' => 'debug',
],

'null' => [
'driver' => 'monolog',
'handler' => NullHandler::class,
],

'emergency' => [
'path' => storage_path('logs/laravel.log'),
],
],

];
20 changes: 19 additions & 1 deletion tests/Unit/CodingWikiTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
use ZipArchive;
Expand DownExpand Up@@ -109,7 +110,7 @@ public function testCreateMarkdownZip()
$filename = 'image-demo_65619.md'
$markdown = file_get_contents($path . $filename);
$coding = new Wiki();
$zipFile = $coding->createMarkdownZip($markdown, $path, $filename);
$zipFile = $coding->createMarkdownZip($markdown, $path, $filename, 'hello');

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

public function testCreateMarkdownZipButImageNotExist()
{
$path = $this->dataDir . 'confluence/'
$filename = 'image-not-exist-demo.md'
$markdown = file_get_contents($path . $filename);
$coding = new Wiki();
Log::shouldReceive('error')
->with('文件不存在', ['filename' => 'not/exist.png', 'title' => 'hello']);
$zipFile = $coding->createMarkdownZip($markdown, $path, $filename, 'hello');

$this->assertTrue(file_exists($zipFile));
$zip = new ZipArchive();
$zip->open($zipFile);
$this->assertEquals(1, $zip->numFiles);
$this->assertEquals($filename, $zip->getNameIndex(0));
}

public function testGetImportJobStatus()
{
$responseBody = file_get_contents($this->dataDir . 'coding/DescribeImportJobStatusResponse.json');
Expand Down
Loading