|
|
@@ -15,7 +15,7 @@ use App\Models\Sentence;
|
|
|
use App\Http\Api\ChannelApi;
|
|
|
use App\Http\Api\MdRender;
|
|
|
use App\Tools\Export;
|
|
|
-use App\Tools\RedisClusters;
|
|
|
+use Illuminate\Support\Facades\Cache;
|
|
|
use App\Tools\ExportDownload;
|
|
|
|
|
|
|
|
|
@@ -56,37 +56,39 @@ class ExportChapter extends Command
|
|
|
{
|
|
|
$this->info('task export chapter start');
|
|
|
Log::debug('task export chapter start');
|
|
|
- if(\App\Tools\Tools::isStop()){
|
|
|
+ if (\App\Tools\Tools::isStop()) {
|
|
|
return 0;
|
|
|
}
|
|
|
$book = $this->argument('book');
|
|
|
$para = $this->argument('para');
|
|
|
|
|
|
$upload = new ExportDownload([
|
|
|
- 'queryId'=>$this->argument('query_id'),
|
|
|
- 'format'=>$this->option('format'),
|
|
|
- 'debug'=>$this->option('debug'),
|
|
|
- 'filename'=>$book.'-'.$para,
|
|
|
+ 'queryId' => $this->argument('query_id'),
|
|
|
+ 'format' => $this->option('format'),
|
|
|
+ 'debug' => $this->option('debug'),
|
|
|
+ 'filename' => $book . '-' . $para,
|
|
|
]);
|
|
|
|
|
|
- $m = new \Mustache_Engine(array('entity_flags'=>ENT_QUOTES,
|
|
|
- 'delimiters' => '[[ ]]',
|
|
|
- 'escape'=>function ($value){
|
|
|
- return $value;
|
|
|
- }));
|
|
|
+ $m = new \Mustache_Engine(array(
|
|
|
+ 'entity_flags' => ENT_QUOTES,
|
|
|
+ 'delimiters' => '[[ ]]',
|
|
|
+ 'escape' => function ($value) {
|
|
|
+ return $value;
|
|
|
+ }
|
|
|
+ ));
|
|
|
$tplFile = resource_path("mustache/chapter/md/paragraph.md");
|
|
|
$tplParagraph = file_get_contents($tplFile);
|
|
|
|
|
|
MdRender::init();
|
|
|
|
|
|
- $renderFormat='markdown';
|
|
|
+ $renderFormat = 'markdown';
|
|
|
|
|
|
//获取原文channel
|
|
|
$orgChannelId = ChannelApi::getSysChannel('_System_Pali_VRI_');
|
|
|
|
|
|
- $tranChannelsId = explode('_',$this->argument('channel'));
|
|
|
+ $tranChannelsId = explode('_', $this->argument('channel'));
|
|
|
|
|
|
- $channelsId = array_merge([$orgChannelId],$tranChannelsId);
|
|
|
+ $channelsId = array_merge([$orgChannelId], $tranChannelsId);
|
|
|
|
|
|
$channels = array();
|
|
|
$channelsIndex = array();
|
|
|
@@ -101,88 +103,89 @@ class ExportChapter extends Command
|
|
|
$bookMeta['book_author'] .= $channel['name'] . ' ';
|
|
|
}
|
|
|
|
|
|
- $chapter = PaliText::where('book',$book)
|
|
|
- ->where('paragraph',$para)->first();
|
|
|
- if(!$chapter){
|
|
|
+ $chapter = PaliText::where('book', $book)
|
|
|
+ ->where('paragraph', $para)->first();
|
|
|
+ if (!$chapter) {
|
|
|
return $this->error("no data");
|
|
|
}
|
|
|
|
|
|
$currProgress = 0;
|
|
|
- $this->info($upload->setStatus($currProgress,'start'));
|
|
|
+ $this->info($upload->setStatus($currProgress, 'start'));
|
|
|
|
|
|
|
|
|
- if(empty($chapter->toc)){
|
|
|
+ if (empty($chapter->toc)) {
|
|
|
$bookMeta['title'] = "unknown";
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$bookMeta['book_title'] = '';
|
|
|
foreach ($channelsId as $key => $id) {
|
|
|
- $title = ProgressChapter::where('book',$book)->where('para',$para)
|
|
|
- ->where('channel_id',$id)
|
|
|
- ->value('title');
|
|
|
+ $title = ProgressChapter::where('book', $book)->where('para', $para)
|
|
|
+ ->where('channel_id', $id)
|
|
|
+ ->value('title');
|
|
|
$bookMeta['book_title'] .= $title;
|
|
|
}
|
|
|
$bookMeta['sub_title'] = $chapter->toc;
|
|
|
}
|
|
|
|
|
|
- $subChapter = PaliText::where('book',$book)->where('parent',$para)
|
|
|
- ->where('level','<',8)
|
|
|
- ->orderBy('paragraph')
|
|
|
- ->get();
|
|
|
- if(count($subChapter) === 0){
|
|
|
+ $subChapter = PaliText::where('book', $book)->where('parent', $para)
|
|
|
+ ->where('level', '<', 8)
|
|
|
+ ->orderBy('paragraph')
|
|
|
+ ->get();
|
|
|
+ if (count($subChapter) === 0) {
|
|
|
//没有子章节
|
|
|
- $subChapter = PaliText::where('book',$book)->where('paragraph',$para)
|
|
|
- ->where('level','<',8)
|
|
|
- ->orderBy('paragraph')
|
|
|
- ->get();
|
|
|
+ $subChapter = PaliText::where('book', $book)->where('paragraph', $para)
|
|
|
+ ->where('level', '<', 8)
|
|
|
+ ->orderBy('paragraph')
|
|
|
+ ->get();
|
|
|
}
|
|
|
|
|
|
- $chapterParagraph = PaliText::where('book',$book)->where('paragraph',$para)->value('chapter_len');
|
|
|
- if($chapterParagraph >0 ){
|
|
|
+ $chapterParagraph = PaliText::where('book', $book)->where('paragraph', $para)->value('chapter_len');
|
|
|
+ if ($chapterParagraph > 0) {
|
|
|
$step = 0.9 / $chapterParagraph;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$step = 0.9;
|
|
|
- Log::error('段落长度不能为0',['book'=>$book,'para'=>$para]);
|
|
|
+ Log::error('段落长度不能为0', ['book' => $book, 'para' => $para]);
|
|
|
}
|
|
|
|
|
|
$outputChannelsId = [];
|
|
|
- if($this->option('origin') === 'true'){
|
|
|
+ if ($this->option('origin') === 'true') {
|
|
|
$outputChannelsId[] = $orgChannelId;
|
|
|
}
|
|
|
- if($this->option('translation') === 'true'){
|
|
|
- $outputChannelsId = array_merge($outputChannelsId,$tranChannelsId);
|
|
|
+ if ($this->option('translation') === 'true') {
|
|
|
+ $outputChannelsId = array_merge($outputChannelsId, $tranChannelsId);
|
|
|
}
|
|
|
|
|
|
$sections = array();
|
|
|
foreach ($subChapter as $key => $sub) {
|
|
|
# 看这个章节是否存在译文
|
|
|
$hasChapter = false;
|
|
|
- if($this->option('origin') === 'true'){
|
|
|
+ if ($this->option('origin') === 'true') {
|
|
|
$hasChapter = true;
|
|
|
}
|
|
|
- if($this->option('translation') === 'true'){
|
|
|
+ if ($this->option('translation') === 'true') {
|
|
|
foreach ($tranChannelsId as $id) {
|
|
|
- if(ProgressChapter::where('book',$book)->where('para',$sub->paragraph)
|
|
|
- ->where('channel_id',$id)
|
|
|
- ->exists()){
|
|
|
- $hasChapter = true;
|
|
|
+ if (ProgressChapter::where('book', $book)->where('para', $sub->paragraph)
|
|
|
+ ->where('channel_id', $id)
|
|
|
+ ->exists()
|
|
|
+ ) {
|
|
|
+ $hasChapter = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if(!$hasChapter){
|
|
|
+ if (!$hasChapter) {
|
|
|
//不存在需要导出的数据
|
|
|
continue;
|
|
|
}
|
|
|
- $filename = "{$sub->paragraph}.".$this->option('format');
|
|
|
- $bookMeta['sections'][] = ['filename'=>$filename];
|
|
|
- $paliTitle = PaliText::where('book',$book)
|
|
|
- ->where('paragraph',$sub->paragraph)
|
|
|
- ->value('toc');
|
|
|
+ $filename = "{$sub->paragraph}." . $this->option('format');
|
|
|
+ $bookMeta['sections'][] = ['filename' => $filename];
|
|
|
+ $paliTitle = PaliText::where('book', $book)
|
|
|
+ ->where('paragraph', $sub->paragraph)
|
|
|
+ ->value('toc');
|
|
|
$sectionTitle = $paliTitle;
|
|
|
- if($this->option('translation') === 'true'){
|
|
|
- $chapter = ProgressChapter::where('book',$book)->where('para',$sub->paragraph)
|
|
|
- ->where('channel_id',$tranChannelsId[0])
|
|
|
- ->first();
|
|
|
- if($chapter && !empty($chapter->title)){
|
|
|
+ if ($this->option('translation') === 'true') {
|
|
|
+ $chapter = ProgressChapter::where('book', $book)->where('para', $sub->paragraph)
|
|
|
+ ->where('channel_id', $tranChannelsId[0])
|
|
|
+ ->first();
|
|
|
+ if ($chapter && !empty($chapter->title)) {
|
|
|
$sectionTitle = $chapter->title;
|
|
|
}
|
|
|
}
|
|
|
@@ -190,80 +193,80 @@ class ExportChapter extends Command
|
|
|
|
|
|
$content = array();
|
|
|
|
|
|
- $chapterStart = $sub->paragraph+1;
|
|
|
+ $chapterStart = $sub->paragraph + 1;
|
|
|
$chapterEnd = $sub->paragraph + $sub->chapter_len;
|
|
|
- $chapterBody = PaliText::where('book',$book)
|
|
|
- ->whereBetween('paragraph',[$chapterStart,$chapterEnd])
|
|
|
- ->orderBy('paragraph')->get();
|
|
|
+ $chapterBody = PaliText::where('book', $book)
|
|
|
+ ->whereBetween('paragraph', [$chapterStart, $chapterEnd])
|
|
|
+ ->orderBy('paragraph')->get();
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($chapterBody as $body) {
|
|
|
$currProgress += $step;
|
|
|
- $this->info($upload->setStatus($currProgress,'export chapter '.$body->paragraph));
|
|
|
+ $this->info($upload->setStatus($currProgress, 'export chapter ' . $body->paragraph));
|
|
|
$paraData = array();
|
|
|
$paraData['translations'] = array();
|
|
|
foreach ($outputChannelsId as $key => $channelId) {
|
|
|
- $translationData = Sentence::where('book_id',$book)
|
|
|
- ->where('paragraph',$body->paragraph)
|
|
|
- ->where('channel_uid',$channelId)
|
|
|
- ->orderBy('word_start')->get();
|
|
|
+ $translationData = Sentence::where('book_id', $book)
|
|
|
+ ->where('paragraph', $body->paragraph)
|
|
|
+ ->where('channel_uid', $channelId)
|
|
|
+ ->orderBy('word_start')->get();
|
|
|
$sentContent = array();
|
|
|
foreach ($translationData as $sent) {
|
|
|
- $texText = MdRender::render($sent->content,
|
|
|
- [$sent->channel_uid],
|
|
|
- null,
|
|
|
- 'read',
|
|
|
- $channelsIndex[$channelId]['type'],
|
|
|
- $sent->content_type,
|
|
|
- $renderFormat
|
|
|
- );
|
|
|
+ $texText = MdRender::render(
|
|
|
+ $sent->content,
|
|
|
+ [$sent->channel_uid],
|
|
|
+ null,
|
|
|
+ 'read',
|
|
|
+ $channelsIndex[$channelId]['type'],
|
|
|
+ $sent->content_type,
|
|
|
+ $renderFormat
|
|
|
+ );
|
|
|
$sentContent[] = trim($texText);
|
|
|
}
|
|
|
- $paraContent = implode(' ',$sentContent);
|
|
|
- if($channelsIndex[$channelId]['type'] === 'original'){
|
|
|
+ $paraContent = implode(' ', $sentContent);
|
|
|
+ if ($channelsIndex[$channelId]['type'] === 'original') {
|
|
|
$paraData['origin'] = $paraContent;
|
|
|
- }else{
|
|
|
- $paraData['translations'][] = ['content'=>$paraContent];
|
|
|
+ } else {
|
|
|
+ $paraData['translations'][] = ['content' => $paraContent];
|
|
|
}
|
|
|
}
|
|
|
- if($body->level > 7){
|
|
|
- $content[] = $m->render($tplParagraph,$paraData);
|
|
|
- }else{
|
|
|
+ if ($body->level > 7) {
|
|
|
+ $content[] = $m->render($tplParagraph, $paraData);
|
|
|
+ } else {
|
|
|
$currLevel = $body->level - $sub->level;
|
|
|
- if($currLevel<=0){
|
|
|
+ if ($currLevel <= 0) {
|
|
|
$currLevel = 1;
|
|
|
}
|
|
|
|
|
|
- if(count($paraData['translations'])===0){
|
|
|
- $subSessionTitle = PaliText::where('book',$book)
|
|
|
- ->where('paragraph',$body->paragraph)
|
|
|
- ->value('toc');
|
|
|
- }else{
|
|
|
+ if (count($paraData['translations']) === 0) {
|
|
|
+ $subSessionTitle = PaliText::where('book', $book)
|
|
|
+ ->where('paragraph', $body->paragraph)
|
|
|
+ ->value('toc');
|
|
|
+ } else {
|
|
|
$subSessionTitle = $paraData['translations'][0]['content'];
|
|
|
}
|
|
|
|
|
|
//标题
|
|
|
- $subStr = array_fill(0,$currLevel,'#');
|
|
|
- $content[] = implode('',$subStr) . " ".$subSessionTitle;
|
|
|
-
|
|
|
+ $subStr = array_fill(0, $currLevel, '#');
|
|
|
+ $content[] = implode('', $subStr) . " " . $subSessionTitle;
|
|
|
}
|
|
|
$content[] = "\n\n";
|
|
|
}
|
|
|
|
|
|
$sections[] = [
|
|
|
- 'name'=>$filename,
|
|
|
- 'body'=>[
|
|
|
- 'title'=>$sectionTitle,
|
|
|
- 'content'=>implode('',$content)
|
|
|
- ]
|
|
|
- ];
|
|
|
+ 'name' => $filename,
|
|
|
+ 'body' => [
|
|
|
+ 'title' => $sectionTitle,
|
|
|
+ 'content' => implode('', $content)
|
|
|
+ ]
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
//导出术语表
|
|
|
$keyPali = array();
|
|
|
$keyMeaning = array();
|
|
|
- if(isset($GLOBALS['glossary'])){
|
|
|
+ if (isset($GLOBALS['glossary'])) {
|
|
|
$glossary = $GLOBALS['glossary'];
|
|
|
foreach ($glossary as $word => $meaning) {
|
|
|
$keyMeaning[$meaning] = $word;
|
|
|
@@ -277,34 +280,34 @@ class ExportChapter extends Command
|
|
|
$glossaryData['pali'] = [];
|
|
|
$glossaryData['meaning'] = [];
|
|
|
foreach ($keyPali as $word => $meaning) {
|
|
|
- $glossaryData['pali'][] = ['pali'=>$word,'meaning'=>$meaning];
|
|
|
+ $glossaryData['pali'][] = ['pali' => $word, 'meaning' => $meaning];
|
|
|
}
|
|
|
foreach ($keyMeaning as $meaning => $word) {
|
|
|
- $glossaryData['meaning'][] = ['pali' => $word,'meaning'=>$meaning];
|
|
|
+ $glossaryData['meaning'][] = ['pali' => $word, 'meaning' => $meaning];
|
|
|
}
|
|
|
|
|
|
- Log::debug('glossary',['data' => $glossaryData]);
|
|
|
+ Log::debug('glossary', ['data' => $glossaryData]);
|
|
|
|
|
|
- $tplFile = resource_path("mustache/chapter/".$this->option('format')."/glossary.".$this->option('format'));
|
|
|
+ $tplFile = resource_path("mustache/chapter/" . $this->option('format') . "/glossary." . $this->option('format'));
|
|
|
$tplGlossary = file_get_contents($tplFile);
|
|
|
|
|
|
- $glossaryContent = $m->render($tplGlossary,$glossaryData);
|
|
|
+ $glossaryContent = $m->render($tplGlossary, $glossaryData);
|
|
|
|
|
|
$sections[] = [
|
|
|
- 'name'=>'glossary.'.$this->option('format'),
|
|
|
- 'body'=>[
|
|
|
+ 'name' => 'glossary.' . $this->option('format'),
|
|
|
+ 'body' => [
|
|
|
'title' => 'glossary',
|
|
|
'content' => $glossaryContent
|
|
|
]
|
|
|
];
|
|
|
- $this->info($upload->setStatus($currProgress,'export glossary '. count($keyPali)));
|
|
|
+ $this->info($upload->setStatus($currProgress, 'export glossary ' . count($keyPali)));
|
|
|
|
|
|
- $this->info($upload->setStatus(0.9,'export content done sections='.count($sections)));
|
|
|
+ $this->info($upload->setStatus(0.9, 'export content done sections=' . count($sections)));
|
|
|
|
|
|
- Log::debug('导出结束',['sections'=>count($sections)]);
|
|
|
+ Log::debug('导出结束', ['sections' => count($sections)]);
|
|
|
|
|
|
- $upload->upload('chapter',$sections,$bookMeta);
|
|
|
- $this->info($upload->setStatus(1,'export chapter done'));
|
|
|
+ $upload->upload('chapter', $sections, $bookMeta);
|
|
|
+ $this->info($upload->setStatus(1, 'export chapter done'));
|
|
|
|
|
|
return 0;
|
|
|
}
|