|
|
@@ -45,26 +45,26 @@ class ExportSentence extends Command
|
|
|
public function handle()
|
|
|
{
|
|
|
Log::debug('task export offline sentence-table start');
|
|
|
- if(\App\Tools\Tools::isStop()){
|
|
|
+ if (\App\Tools\Tools::isStop()) {
|
|
|
return 0;
|
|
|
}
|
|
|
\App\Tools\Markdown::driver($this->option('driver'));
|
|
|
$channels = [];
|
|
|
$channel_id = $this->option('channel');
|
|
|
- if($channel_id){
|
|
|
+ if ($channel_id) {
|
|
|
$file_suf = $channel_id;
|
|
|
$channels[] = $channel_id;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$channel_type = $this->option('type');
|
|
|
$file_suf = $channel_type;
|
|
|
- if($channel_type === "original"){
|
|
|
+ if ($channel_type === "original") {
|
|
|
$pali_channel = ChannelApi::getSysChannel("_System_Pali_VRI_");
|
|
|
- if($pali_channel === false){
|
|
|
+ if ($pali_channel === false) {
|
|
|
return 0;
|
|
|
}
|
|
|
$channels[] = $pali_channel;
|
|
|
- }else{
|
|
|
- $nissaya_channel = Channel::where('type',$channel_type)->where('status',30)->select('uid')->get();
|
|
|
+ } else {
|
|
|
+ $nissaya_channel = Channel::where('type', $channel_type)->where('status', 30)->select('uid')->get();
|
|
|
foreach ($nissaya_channel as $key => $value) {
|
|
|
# code...
|
|
|
$channels[] = $value->uid;
|
|
|
@@ -73,53 +73,62 @@ class ExportSentence extends Command
|
|
|
}
|
|
|
|
|
|
|
|
|
- $exportFile = storage_path('app/public/export/offline/wikipali-offline-'.date("Y-m-d").'.db3');
|
|
|
- $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
|
|
|
+ $exportFile = storage_path('app/public/export/offline/wikipali-offline-' . date("Y-m-d") . '.db3');
|
|
|
+ $dbh = new \PDO('sqlite:' . $exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
|
|
|
$dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
|
|
|
$dbh->beginTransaction();
|
|
|
|
|
|
- if($channel_type === "original"){
|
|
|
+ if ($channel_type === "original") {
|
|
|
$table = 'sentence';
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$table = 'sentence_translation';
|
|
|
}
|
|
|
|
|
|
$query = "INSERT INTO {$table} ( book , paragraph ,
|
|
|
word_start , word_end , content , channel_id )
|
|
|
VALUES ( ? , ? , ? , ? , ? , ? )";
|
|
|
- try{
|
|
|
+ try {
|
|
|
$stmt = $dbh->prepare($query);
|
|
|
- }catch(PDOException $e){
|
|
|
+ } catch (\PDOException $e) {
|
|
|
Log::error($e->getMessage(), ['exception' => $e]);
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
- $db = Sentence::whereIn('channel_uid',$channels);
|
|
|
+ $db = Sentence::whereIn('channel_uid', $channels);
|
|
|
$bar = $this->output->createProgressBar($db->count());
|
|
|
- $srcDb = $db->select(['uid','book_id','paragraph',
|
|
|
- 'word_start','word_end',
|
|
|
- 'content','content_type','channel_uid',
|
|
|
- 'editor_uid','language','updated_at'])->cursor();
|
|
|
+ $srcDb = $db->select([
|
|
|
+ 'uid',
|
|
|
+ 'book_id',
|
|
|
+ 'paragraph',
|
|
|
+ 'word_start',
|
|
|
+ 'word_end',
|
|
|
+ 'content',
|
|
|
+ 'content_type',
|
|
|
+ 'channel_uid',
|
|
|
+ 'editor_uid',
|
|
|
+ 'language',
|
|
|
+ 'updated_at'
|
|
|
+ ])->cursor();
|
|
|
foreach ($srcDb as $sent) {
|
|
|
- if(Str::isUuid($sent->channel_uid)){
|
|
|
+ if (Str::isUuid($sent->channel_uid)) {
|
|
|
$channel = ChannelApi::getById($sent->channel_uid);
|
|
|
$currData = array(
|
|
|
- $sent->book_id,
|
|
|
- $sent->paragraph,
|
|
|
- $sent->word_start,
|
|
|
- $sent->word_end,
|
|
|
- MdRender::render($sent->content,
|
|
|
- [$sent->channel_uid],
|
|
|
- null,
|
|
|
- 'read',
|
|
|
- $channel['type'],
|
|
|
- $sent->content_type,
|
|
|
- 'unity',
|
|
|
- ),
|
|
|
- $sent->channel_uid,
|
|
|
- );
|
|
|
+ $sent->book_id,
|
|
|
+ $sent->paragraph,
|
|
|
+ $sent->word_start,
|
|
|
+ $sent->word_end,
|
|
|
+ MdRender::render(
|
|
|
+ $sent->content,
|
|
|
+ [$sent->channel_uid],
|
|
|
+ null,
|
|
|
+ 'read',
|
|
|
+ $channel['type'],
|
|
|
+ $sent->content_type,
|
|
|
+ 'unity',
|
|
|
+ ),
|
|
|
+ $sent->channel_uid,
|
|
|
+ );
|
|
|
$stmt->execute($currData);
|
|
|
-
|
|
|
}
|
|
|
$bar->advance();
|
|
|
}
|