Ejemplo n.º 1
0
 /**
  * subscribes the user from the topic
  **/
 public static function subscribeToTopic(\Nexus\User $user, \Nexus\Topic $topic)
 {
     $lastestView = \Nexus\View::where('topic_id', $topic->id)->where('user_id', $user->id)->first();
     if ($lastestView) {
         $lastestView->unsubscribed = false;
         $lastestView->update();
     } else {
         $view = new \Nexus\View();
         $view->user_id = $user->id;
         $view->topic_id = $topic->id;
         $view->latest_view_date = $topic->most_recent_post_time;
         $view->unsubscribed = false;
         $view->save();
     }
 }
Ejemplo n.º 2
0
 private function migrateViews()
 {
     $this->info('Importing Views');
     if (!\Nexus\View::first()) {
         $errorCount = 0;
         $count = \DB::select('select count(topicview_id) as count from topicview')[0]->count;
         $this->line("Found {$count} views");
         $bar = $this->output->createProgressBar($count);
         \DB::table('topicview')->chunk(1000, function ($views) use(&$errorCount, &$count, &$bar) {
             foreach ($views as $classicView) {
                 $newView = new \Nexus\View();
                 $newView->id = $classicView->topicview_id;
                 $newView->user_id = $classicView->user_id;
                 $newView->topic_id = $classicView->topic_id;
                 $newView->latest_view_date = $classicView->msg_date;
                 if ($classicView->unsubscribe === 0) {
                     $newView->unsubscribed = false;
                 } else {
                     $newView->unsubscribed = true;
                 }
                 try {
                     $newView->save();
                     $bar->advance();
                 } catch (\Exception $e) {
                     $errorCount++;
                     \Log::info('Nexus:upgrade - Failed to import view: ' . $e);
                 }
             }
         });
         $bar->finish();
         if ($errorCount) {
             $this->error("\nFailed to import {$errorCount} views. See log for details");
         }
         $this->info("\nViews Complete\n");
     } else {
         $this->error('Upgrade: found existing views - skipping Posts');
     }
 }