UpgradeFts.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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} {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('content')){
  38. if(!empty($this->argument('para'))){
  39. $para = explode('-',$this->argument('para'));
  40. $content = $this->getContent($para[0],$para[1]);
  41. if($this->option('test')){
  42. $this->info($content);
  43. }else{
  44. FtsText::where('book',$para[0])->where('paragraph',$para[1])->update(['content'=>$content]);
  45. }
  46. }else{
  47. for ($iBook=1; $iBook <= 217; $iBook++) {
  48. # code...
  49. $this->info('book:'.$iBook);
  50. $maxParagraph = WbwTemplate::where('book',$iBook)->max('paragraph');
  51. $bar = $this->output->createProgressBar($maxParagraph-1);
  52. for($iPara=1; $iPara <= $maxParagraph; $iPara++){
  53. $content = $this->getContent($iBook,$iPara);
  54. FtsText::where('book',$iBook)->where('paragraph',$iPara)->update(['content'=>$content]);
  55. $bar->advance();
  56. }
  57. $bar->finish();
  58. $this->info('done');
  59. }
  60. }
  61. }
  62. return 0;
  63. }
  64. private function getContent($book,$para){
  65. $words = WbwTemplate::where('book',$book)
  66. ->where('paragraph',$para)
  67. ->where('type',"<>",".ctl.")
  68. ->orderBy('wid')->get();
  69. $content = '';
  70. foreach ($words as $word) {
  71. if($word->style === 'bld'){
  72. if(strpos($word->word,"{")===FALSE){
  73. $content .= "**{$word->word}** ";
  74. }else{
  75. $content .= str_replace(['{','}'],['**','** '],$word->word);
  76. }
  77. }else if($word->style === 'note'){
  78. $content .= " _{$word->word}_ ";
  79. }else{
  80. $content .= $word->word . " ";
  81. }
  82. }
  83. return $content;
  84. }
  85. }