InstantiateStatTree.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Client;
  4. use App\Models\Pro;
  5. use App\Models\StatTree;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\Http;
  8. class InstantiateStatTree extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'stat-tree:instantiate {slug} {pro-class}';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Instantiate Stat Tree For Multiple Pros';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return int
  35. */
  36. public function handle()
  37. {
  38. global $argv;
  39. // load the tree from slug and ensure it is a template
  40. /** @var StatTree $statTree */
  41. $statTree = StatTree::where('slug', $argv[2])->first();
  42. if(!$statTree) {
  43. $this->error("Tree with specified slug does not exist!");
  44. return 0;
  45. }
  46. if(!$statTree->is_template) {
  47. $this->error("Tree with specified slug is not a template!");
  48. return 0;
  49. }
  50. // check pro-class and get pro uids
  51. $this->info($argv[3]);
  52. $pros = Pro::where('is_active', TRUE)->whereRaw($argv[3])->get();
  53. $this->info(count($pros) . " pros found.");
  54. $this->info("Instantiating...");
  55. $doneCount = 0;
  56. if(count($pros) > 0) {
  57. foreach ($pros as $pro) {
  58. $statTree->instantiateForPro($pro);
  59. $doneCount++;
  60. if($doneCount % 50 == 0) {
  61. $this->info("$doneCount / " . count($pros) . " completed.");
  62. }
  63. }
  64. $this->info("$doneCount / " . count($pros) . " completed.");
  65. }
  66. }
  67. }