1
0

AccountPostCountStatUpdate.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Services\AccountService;
  5. use App\Services\Account\AccountStatService;
  6. use App\Status;
  7. use App\Profile;
  8. class AccountPostCountStatUpdate extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'app:account-post-count-stat-update';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Update post counts from recent activities';
  22. /**
  23. * Execute the console command.
  24. */
  25. public function handle()
  26. {
  27. $ids = AccountStatService::getAllPostCountIncr();
  28. if(!$ids || !count($ids)) {
  29. return;
  30. }
  31. foreach($ids as $id) {
  32. $acct = AccountService::get($id, true);
  33. if(!$acct) {
  34. AccountStatService::removeFromPostCount($id);
  35. continue;
  36. }
  37. $statusCount = Status::whereProfileId($id)->count();
  38. if($statusCount != $acct['statuses_count']) {
  39. $profile = Profile::find($id);
  40. if(!$profile) {
  41. AccountStatService::removeFromPostCount($id);
  42. continue;
  43. }
  44. $profile->status_count = $statusCount;
  45. $profile->save();
  46. AccountService::del($id);
  47. }
  48. AccountStatService::removeFromPostCount($id);
  49. }
  50. return;
  51. }
  52. }