public function run() { $output = null; $faker = Faker::create(); if (isset($this->command)) { $output = $this->command->getOutput(); } // Get first 100 license types and accounts $licTypes = LicenseType::select('type')->take(100)->get()->toArray(); $accounts = Account::take(100)->get(); // Ensure we have at least one license type and account if (empty($licTypes)) { return false; } if ($accounts->isEmpty()) { return false; } // Initialize the progress bar $progress = $this->progressBarStart($output, count($accounts)); foreach ($accounts as $acct) { if ($acct->status === 'locked') { continue; } $numLicenses = mt_rand(1, count($licTypes)); for ($i = 0; $i < $numLicenses; $i++) { $status = $acct->status === STATUS_PENDING ? $acct->status : $faker->randomElement([STATUS_ACTIVE, STATUS_ACTIVE, STATUS_PENDING]); // Increase chance for 'active' $licDays = $status != STATUS_ACTIVE ? 10 : $faker->numberBetween(30, 730); // Create the record ... factory(License::class)->create(['type' => $faker->randomElement($licTypes)['type'], 'account_id' => $acct->id, 'status' => $status, 'start_at' => Carbon::now(), 'end_at' => Carbon::now()->addDays($licDays)]); } // ... and update the progress bar $this->progressBarAdvance($output, $progress); } // Close the progress bar $this->progressBarFinish($output, $progress); }
public function run() { $maxTypes = 10; $output = null; $faker = Faker::create(); if (isset($this->command)) { $output = $this->command->getOutput(); } // Initialize the progress bar $progress = $this->progressBarStart($output, $maxTypes); for ($i = 0; $i < $maxTypes; $i++) { do { //$type = $faker->safeColorName; $type = $faker->firstName; } while (LicenseType::where('type', $type)->first()); $status = $faker->randomElement([STATUS_ACTIVE, STATUS_ACTIVE, STATUS_ACTIVE, STATUS_PENDING, STATUS_PENDING, STATUS_EXPIRED]); // Create the record ... factory(LicenseType::class)->create(['type' => $type, 'name' => ucfirst($type) . ' License', 'status' => $status]); // ... and update the progress bar $this->progressBarAdvance($output, $progress); } // Close the progress bar $this->progressBarFinish($output, $progress); }
/** * Execute the console command. * * @return mixed */ public function handle() { // // STEP 1: check if system is installed at all // if (!$this->checkInstallation()) { $this->showError(["This system has not been set up properly.", "One or more core components are missing."], 'ERRORS'); return false; } // // STEP 2: check installation and collect some data // $login = $this->askName($this->option('login'), null, 'User'); $pswd = $this->askPswd($this->option('pswd'), $login); if (!$this->authUser($login, $pswd)) { $this->showError("Invalid credentials or insufficient access right", 'ERRORS'); return false; } // // STEP 2: collect data // // @todo need more magic stuff $success = true; if ($success) { $this->accounts = Account::all(); $this->licTypes = LicenseType::all(); $this->licenses = License::all(); $this->orgs = Organization::all(); $this->users = User::all(); } // // STEP 3: show summary or error // if ($success) { $this->info("\n--[SUMMARY]------------------------------------------------"); $this->info('ACCOUNTs: ' . $this->accounts->count()); $this->info('LIC TYPEs: ' . $this->licTypes->count()); $this->info('LICs: ' . $this->licenses->count()); $this->info('ORGs: ' . $this->orgs->count()); $this->info('USERs: ' . $this->users->count()); $this->info("-----------------------------------------------------------"); } else { if (!empty($this->errMsgs)) { $this->showError($this->errMsgs, 'ERRORS'); } $this->showError(["This system has not been set up properly.", "Please re-install and try again."], 'ERRORS'); } return $success; }