/**
  * Store a newly created resource in storage.
  *
  * @param  Requests\Message\CreateRequest $request
  * @return Response
  */
 public function store(Requests\Message\CreateRequest $request)
 {
     $input = $request->all();
     $input['read'] = false;
     $input['user_id'] = $input['user_id'];
     $input['time'] = time();
     $input['author_id'] = \Auth::user()->id;
     \Nexus\Message::create($input);
     return redirect(action('Nexus\\MessageController@index'));
 }
示例#2
0
 private function migrateMessages()
 {
     $this->info('Importing Mesages');
     if (!\Nexus\Message::first()) {
         $errorCount = 0;
         $count = \DB::select('select count(nexusmessage_id) as count from nexusmessagetable')[0]->count;
         $this->line("Found {$count} messages");
         $bar = $this->output->createProgressBar($count);
         \DB::table('nexusmessagetable')->chunk(1000, function ($messages) use(&$errorCount, &$count, &$bar) {
             foreach ($messages as $classicMessage) {
                 $newMessage = new \Nexus\Message();
                 $newMessage->id = $classicMessage->nexusmessage_id;
                 $newMessage->user_id = $classicMessage->user_id;
                 $newMessage->author_id = $classicMessage->from_id;
                 $newMessage->text = $classicMessage->text;
                 $newMessage->time = $classicMessage->time;
                 if ($classicMessage->readstatus === 'n') {
                     $newMessage->read = false;
                 } else {
                     $newMessage->read = true;
                 }
                 try {
                     $newMessage->save();
                     $bar->advance();
                 } catch (\Exception $e) {
                     $errorCount++;
                     \Log::info('Nexus:upgrade - Failed to import message: ' . $e);
                 }
             }
         });
         $bar->finish();
         if ($errorCount) {
             $this->error("\nFailed to import {$errorCount} messages. See log for details");
         }
         $this->info("\nMessages Complete\n");
     } else {
         $this->error('Upgrade: found existing messages - skipping Messages');
     }
 }