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');
     }
 }
 /**
  * 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();
     }
 }
    /**
     * redirects a visitor to a section  with an updated topic
     */
    public function leap()
    {
        // should we be passing the user_id into this method?
        $views = \Nexus\View::with('topic')->where('user_id', \Auth::user()->id)->where('latest_view_date', '!=', "0000-00-00 00:00:00")->where('unsubscribed', 0)->get();
        $topics = $views->map(function ($view, $key) {
            if (!is_null($view->topic)) {
                if ($view->latest_view_date != $view->topic->most_recent_post_time) {
                    return $view;
                }
            }
        })->reject(function ($view) {
            return empty($view);
        });
        if ($topics->count()) {
            $destinationTopic = $topics->first()->topic;
            // set alert
            $topicURL = action('Nexus\\TopicController@show', ['topic_id' => $destinationTopic->id]);
            // force the url to be relative so we don't later make this open in the new window
            $topicURL = str_replace(url('/'), '', $topicURL);
            $topicTitle = $destinationTopic->title;
            $subscribeAllURL = action('Nexus\\TopicController@markAllSubscribedTopicsAsRead');
            $subscribeAllURL = str_replace(url('/'), '', $subscribeAllURL);
            $message = <<<Markdown
People have been talking! New posts found in **[{$topicTitle}]({$topicURL})**

Seeing too many old topics then **[mark all subscribed topics as read]({$subscribeAllURL})**
Markdown;
            \Nexus\Helpers\FlashHelper::showAlert($message, 'success');
            // redirect to the parent section of the unread topic
            return redirect()->action('Nexus\\SectionController@show', [$destinationTopic->section->id]);
        } else {
            // set alert
            $message = 'No updated topics found. Why not start a new conversation or read more sections?';
            \Nexus\Helpers\FlashHelper::showAlert($message, 'warning');
            // redirect to main menu
            return redirect('/');
        }
    }