. */ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\User; use Illuminate\Console\Command; /** * Class FixAccountOrder */ class FixAccountOrder extends Command { use ShowsFriendlyMessages; protected $description = 'Make sure account order is correct.'; protected $signature = 'firefly-iii:fix-account-order'; private AccountRepositoryInterface $repository; /** * Execute the console command. */ public function handle(): int { $this->stupidLaravel(); $users = User::get(); foreach ($users as $user) { $this->repository->setUser($user); $this->repository->resetAccountOrder(); } $this->friendlyPositive('All accounts are ordered correctly'); return 0; } /** * Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is * executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should * be called from the handle method instead of using the constructor to initialize the command. */ private function stupidLaravel(): void { $this->repository = app(AccountRepositoryInterface::class); } }