/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // we are assuming that the sysop is always the first user
     $this->info('Creating administrator, default section and first topic...');
     $user = \Nexus\User::first();
     if (!$user) {
         $this->info("Please enter in values for the administrator account. Don't worry You can change this later.");
         $username = $this->ask('Username');
         $email = $this->ask('Email Address');
         $password = $this->ask('Password');
         $administrator = new \Nexus\User();
         $administrator->username = $username;
         $administrator->name = 'Administrator';
         $administrator->email = $email;
         $administrator->password = \Hash::make($password);
         $administrator->administrator = true;
         try {
             $administrator->save();
         } catch (\Exception $e) {
             $this->error('Failed to add administrator ' . $e);
         }
     } else {
         $this->error('There is already a user account');
     }
     $section = \Nexus\Section::first();
     if (!$section) {
         $this->info("Please enter in values for the main menu. Don't worry You can change this later.");
         $title = $this->ask('Title');
         $mainmenu = new \Nexus\Section();
         $mainmenu->title = $title;
         $mainmenu->user_id = $administrator->id;
         try {
             $mainmenu->save();
         } catch (\Exception $e) {
             $this->error('Failed to add main menu ' . $e);
         }
     } else {
         $this->error('There is already a main menu');
     }
     $topic = \Nexus\Topic::first();
     if (!$topic) {
         $this->info("Please enter in values for the first topic. Don't worry You can change this later.");
         $title = $this->ask('Title');
         $firstTopic = new \Nexus\Topic();
         $firstTopic->title = $title;
         $firstTopic->section_id = $mainmenu->id;
         try {
             $firstTopic->save();
         } catch (\Exception $e) {
             $this->error('Failed to add first topic ' . $e);
         }
     } else {
         $this->error('There is already a topic');
     }
 }
 private function migrateTopics()
 {
     $this->info('Importing Topics');
     $errorCount = 0;
     if (!\Nexus\Topic::first()) {
         $count = \DB::select('select count(topic_id) as count from topictable')[0]->count;
         $this->line("Found {$count} topics");
         $bar = $this->output->createProgressBar($count);
         $classicTopics = \DB::table('topictable')->get();
         foreach ($classicTopics as $classicTopic) {
             $newTopic = new \Nexus\Topic();
             $newTopic->id = $classicTopic->topic_id;
             $newTopic->title = $classicTopic->topic_title;
             $newTopic->intro = $classicTopic->topic_description;
             $newTopic->section_id = $classicTopic->section_id;
             $newTopic->weight = $classicTopic->topic_weight;
             if ($classicTopic->topic_readonly === 'n') {
                 $newTopic->readonly = false;
             } else {
                 $newTopic->readonly = true;
             }
             if ($classicTopic->topic_annon === 'n') {
                 $newTopic->secret = false;
             } else {
                 $newTopic->secret = true;
             }
             try {
                 $newTopic->save();
                 $bar->advance();
             } catch (\Exception $e) {
                 $errorCount++;
                 \Log::error('Nexus:upgrade - Failed to import topic: ' . $e);
             }
         }
         $bar->finish();
         unset($classicTopics);
         if ($errorCount) {
             $this->error("\nFailed to import {$errorCount} posts. See log for details");
         }
         $this->info("\nTopics Complete\n");
     } else {
         $this->error('Upgrade: found existing topics - skipping Topics');
     }
 }