Exemplo n.º 1
0
 /**
  * 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');
     }
 }
Exemplo n.º 2
0
 private function migrateSections()
 {
     $this->info('Importing Sections');
     $errorCount = 0;
     if (!\Nexus\Section::first()) {
         $count = \DB::select('select count(section_id) as count from sectiontable')[0]->count;
         $this->line("Found {$count} sections ");
         $this->line("Migrating Sections ");
         $bar = $this->output->createProgressBar($count);
         $classicSections = \DB::table('sectiontable')->get();
         foreach ($classicSections as $classicSection) {
             try {
                 $newSection = new \Nexus\Section();
                 $newSection->id = $classicSection->section_id;
                 $newSection->title = $classicSection->section_title;
                 $newSection->intro = $classicSection->section_intro;
                 $newSection->user_id = $classicSection->user_id;
                 $newSection->weight = $classicSection->section_weight;
                 $newSection->save();
                 $bar->advance();
             } catch (\Exception $e) {
                 $errorCount++;
                 \Log::error('Nexus:upgrade - Failed to add section ' . $e);
             }
         }
         $bar->finish();
         $this->line("\nMigration Complete");
         $this->line("Jumbling Sections into Subsections");
         $bar = $this->output->createProgressBar($count);
         foreach ($classicSections as $classicSection) {
             try {
                 $newSection = \Nexus\Section::findOrFail($classicSection->section_id);
                 $newSection->parent_id = $classicSection->parent_id;
                 $newSection->save();
                 $bar->advance();
             } catch (\Exception $e) {
                 $errorCount++;
                 \Log::error('Nexus:upgrade - Failed to add parent to section ' . $e);
             }
         }
         unset($classicSections);
         $bar->finish();
         if ($errorCount) {
             $this->error("\nEncountered {$errorCount} errors. See log for details");
         }
         $this->info("\nSections Complete\n");
     } else {
         $this->error('Upgrade: found existing sections - skipping Sections');
     }
 }