/** * Execute the console command. * * @return mixed */ public function fire() { // Retrieve the path $csv_path = $this->argument('csv'); $file = file($csv_path); $dry_run = $this->option('dry'); $domains = array_map('str_getcsv', $file); if ($dry_run) { $this->warn('Running on dry-mode'); } $success = 0; foreach ($domains as $domain) { // Set the time $date = strtotime($domain[1]); if ($date === false) { $date = time(); } $date = date('Y-m-d H:i:s', $date); // Set the domain $domain = strtolower($domain[0]); // Domain already exists, skip. if (Site::where('url', '=', $domain)->first() != null) { $this->error(" * " . $domain . " already exists. Skipping."); continue; } $new_site = new Site(); $new_site->url = $domain; $new_site->setCreatedAt($date); if ($dry_run) { $this->info(" * Should add " . $domain . " at " . $date . "."); } else { $this->info(" * Added add " . $domain . " at " . $date . "."); $new_site->save(); } $success++; } $this->info("\nDone! Added {$success} new sites"); }