UpgradePaliTextId.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\PaliText;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Log;
  7. class UpgradePaliTextId extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'upgrade:palitextid';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'upgrade pali text uuid';
  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. $this->info("upgrade pali text uuid");
  38. $startTime = time();
  39. $bar = $this->output->createProgressBar(PaliText::count());
  40. #载入csv数据
  41. $csvFile = config("app.path.pali_title") .'/pali_text_uuid.csv';
  42. if (($fp = fopen($csvFile, "r")) === false) {
  43. $this->error( "can not open csv file. filename=" . $csvFile. PHP_EOL) ;
  44. Log::error( "can not open csv file. filename=" . $csvFile) ;
  45. }
  46. Log::info("csv load:" . $csvFile);
  47. $inputRow=0;
  48. while (($data = fgetcsv($fp, 0, ',')) !== false) {
  49. if ($inputRow > 0) {
  50. PaliText::where('book',$data[0])
  51. ->where('paragraph',$data[1])
  52. ->update(['uid'=>$data[2]]);
  53. }
  54. $inputRow++;
  55. $bar->advance();
  56. }
  57. fclose($fp);
  58. $bar->finish();
  59. $this->info("mission finished. in ". time()-$startTime . "s");
  60. Log::info("mission finished. in ". time()-$startTime . "s");
  61. return 0;
  62. }
  63. }