UpgradeFts.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 {--content : upgrade col content}
  15. {para?}
  16. {--test : output log}';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = 'upgrade full text search table';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return int
  36. */
  37. public function handle()
  38. {
  39. if(\App\Tools\Tools::isStop()){
  40. return 0;
  41. }
  42. if($this->option('content')){
  43. if(!empty($this->argument('para'))){
  44. $para = explode('-',$this->argument('para'));
  45. }
  46. for ($iBook=1; $iBook <= 217; $iBook++) {
  47. if(isset($para[0]) && $para[0] != $iBook){
  48. continue;
  49. }
  50. # code...
  51. $this->info('book:'.$iBook);
  52. $maxParagraph = WbwTemplate::where('book',$iBook)->max('paragraph');
  53. $bar = $this->output->createProgressBar($maxParagraph-1);
  54. for($iPara=1; $iPara <= $maxParagraph; $iPara++){
  55. if(isset($para[1]) && $para[1] != $iPara){
  56. $bar->advance();
  57. continue;
  58. }
  59. $content = $this->getContent($iBook,$iPara);
  60. if($this->option('test')){
  61. $this->info($content);
  62. }else{
  63. //TODO update bold
  64. FtsText::where('book',$iBook)->where('paragraph',$iPara)->update(['content'=>$content]);
  65. }
  66. $bar->advance();
  67. }
  68. $bar->finish();
  69. $this->info('done');
  70. }
  71. }
  72. return 0;
  73. }
  74. private function getContent($book,$para){
  75. $words = WbwTemplate::where('book',$book)
  76. ->where('paragraph',$para)
  77. ->where('type',"<>",".ctl.")
  78. ->orderBy('wid')->get();
  79. $content = '';
  80. foreach ($words as $word) {
  81. if($word->style === 'bld'){
  82. if(strpos($word->word,"{")===FALSE){
  83. $content .= "**{$word->word}** ";
  84. }else{
  85. $content .= str_replace(['{','}'],['**','** '],$word->word);
  86. }
  87. }else if($word->style === 'note'){
  88. $content .= " _{$word->word}_ ";
  89. }else{
  90. $content .= $word->word . " ";
  91. }
  92. }
  93. return $content;
  94. }
  95. }