UpgradePaliTextId.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\PaliText;
  4. use App\Tools\Tools;
  5. use Illuminate\Console\Command;
  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. if (Tools::isStop()) {
  38. return 0;
  39. }
  40. $this->info('upgrade pali text uuid');
  41. $startTime = time();
  42. $bar = $this->output->createProgressBar(PaliText::count());
  43. // 载入csv数据
  44. $csvFile = config('mint.path.pali_title').'/pali_text_uuid.csv';
  45. if (($fp = fopen($csvFile, 'r')) === false) {
  46. $this->error('can not open csv file. filename='.$csvFile.PHP_EOL);
  47. Log::error('can not open csv file. filename='.$csvFile);
  48. }
  49. Log::info('csv load:'.$csvFile);
  50. $inputRow = 0;
  51. while (($data = fgetcsv($fp, 0, ',')) !== false) {
  52. if ($inputRow > 0) {
  53. PaliText::where('book', $data[0])
  54. ->where('paragraph', $data[1])
  55. ->update(['uid' => $data[2]]);
  56. }
  57. $inputRow++;
  58. $bar->advance();
  59. }
  60. fclose($fp);
  61. $bar->finish();
  62. $this->info('mission finished. in '.time() - $startTime.'s');
  63. Log::info('mission finished. in '.time() - $startTime.'s');
  64. return 0;
  65. }
  66. }