UpgradeFts.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\BookTitle;
  5. use App\Models\FtsText;
  6. use App\Models\WbwTemplate;
  7. class UpgradeFts extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'upgrade:fts {--book} {--content} {para?} {--test}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Command description';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return int
  34. */
  35. public function handle()
  36. {
  37. if($this->option('book')){
  38. $bookTitles = BookTitle::orderBy('id')->get();
  39. $bar = $this->output->createProgressBar(count($bookTitles));
  40. foreach ($bookTitles as $key => $value) {
  41. # code...
  42. FtsText::where('book',$value->book)
  43. ->where('paragraph','>=',$value->paragraph)
  44. ->update(['pcd_book_id'=>$value->id]);
  45. $bar->advance();
  46. }
  47. $bar->finish();
  48. }
  49. if($this->option('content')){
  50. if(!empty($this->argument('para'))){
  51. $para = explode('-',$this->argument('para'));
  52. $content = $this->getContent($para[0],$para[1]);
  53. if($this->option('test')){
  54. $this->info($content);
  55. }else{
  56. FtsText::where('book',$para[0])->where('paragraph',$para[1])->update(['content'=>$content]);
  57. }
  58. }else{
  59. for ($iBook=1; $iBook <= 217; $iBook++) {
  60. # code...
  61. $this->info('book:'.$iBook);
  62. $maxParagraph = WbwTemplate::where('book',$iBook)->max('paragraph');
  63. $bar = $this->output->createProgressBar($maxParagraph-1);
  64. for($iPara=1; $iPara <= $maxParagraph; $iPara++){
  65. $content = $this->getContent($iBook,$iPara);
  66. FtsText::where('book',$iBook)->where('paragraph',$iPara)->update(['content'=>$content]);
  67. $bar->advance();
  68. }
  69. $bar->finish();
  70. $this->info('done');
  71. }
  72. }
  73. }
  74. return 0;
  75. }
  76. private function getContent($book,$para){
  77. $words = WbwTemplate::where('book',$book)
  78. ->where('paragraph',$para)
  79. ->where('type',"<>",".ctl.")
  80. ->orderBy('wid')->get();
  81. $content = '';
  82. foreach ($words as $word) {
  83. if($word->style === 'bld'){
  84. if(strpos($word->word,"{")===FALSE){
  85. $content .= "**{$word->word}** ";
  86. }else{
  87. $content .= str_replace(['{','}'],['**','** '],$word->word);
  88. }
  89. }else{
  90. $content .= $word->word . " ";
  91. }
  92. }
  93. return $content;
  94. }
  95. }