option('driver')); $channels = []; $channel_id = $this->option('channel'); if($channel_id){ $file_suf = $channel_id; $channels[] = $channel_id; }else{ $channel_type = $this->option('type'); $file_suf = $channel_type; if($channel_type === "original"){ $pali_channel = ChannelApi::getSysChannel("_System_Pali_VRI_"); if($pali_channel === false){ return 0; } $channels[] = $pali_channel; }else{ $nissaya_channel = Channel::where('type',$channel_type)->where('status',30)->select('uid')->get(); foreach ($nissaya_channel as $key => $value) { # code... $channels[] = $value->uid; } } } $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"){ $table = 'sentence'; }else{ $table = 'sentence_translation'; } $query = "INSERT INTO {$table} ( book , paragraph , word_start , word_end , content , channel_id ) VALUES ( ? , ? , ? , ? , ? , ? )"; try{ $stmt = $dbh->prepare($query); }catch(PDOException $e){ Log::info($e); return 1; } $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(); foreach ($srcDb as $sent) { 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, ); $stmt->execute($currData); } $bar->advance(); } $dbh->commit(); $bar->finish(); Log::debug('task export sentence finished'); return 0; } }