Exemplo n.º 1
0
 public function postAddTag(Request $request)
 {
     $user_id = \Auth::user()->id;
     #Validate User Input
     $input = array('tag-name' => $request->input('tag-name'), 'new-tag-weight' => $request->input('new-tag-weight'));
     $validator = Validator::make($input, ['tag-name' => 'required|min:3|max:50', 'new-tag-weight' => 'required|integer|min:1|max:100']);
     if ($validator->fails()) {
         return redirect('/ManageTags')->withErrors($validator)->withInput();
     }
     $tag_name = $request->input('tag-name');
     $tag_weight = $request->input('new-tag-weight');
     #Add Feed to the Feeds table (if it does not already exist)
     if (!\p4\Tag::where('tag', '=', $tag_name)->where('user_id', $user_id)->exists()) {
         $tag = new \p4\Tag();
         $tag->user_id = $user_id;
         $tag->tag = $tag_name;
         $tag->weight = $tag_weight;
         $tag->save();
     }
     # Update the Session Feeds so the updated list will appear in the left nav
     \p4\User::setSessionFeeds($user_id);
     # Update tua table
     \p4\Libraries\RSSParser::updateTagArticlesUsers();
     return \Redirect::to('/ManageTags');
 }
Exemplo n.º 2
0
 public static function processFeeds()
 {
     # This function retrieves all feeds which are due to be refreshed.
     # Any feed where the next update date is before now, will be included.
     # The time interval is determined by the FEED_UPDATE_INTERVAL environment variable
     # A scheduled task automatically gets articles for each feed and stored them in the database.
     # Set the timeout limit to 10 minutes
     set_time_limit(600);
     # Get Feeds which are due to be refreshed
     $current_time = time();
     $dt = new \DateTime("@{$current_time}");
     # Only get feeds where the next update date is before now.
     $feeds = \p4\Feed::where('next_update', '<', $dt->format("Y-m-d H:i:s"))->get();
     foreach ($feeds as $feed) {
         # Do not let a bad feed interrupt the processing of other feeds
         try {
             \p4\Libraries\RSSParser::getFeed($feed);
             echo "Processed Feed #" . $feed->id . "<br>";
         } catch (\Exception $e) {
             echo "Error in processing Feed #" . $feed->id . "<br>";
         }
     }
     # Update the Stats for Feeds
     $sql = "UPDATE\n                feeds INNER JOIN\n                (             \n                    SELECT\n                    f.id,\n                    COUNT(*) cnt\n                    FROM\n                    articles a INNER JOIN feeds f ON a.feed_id = f.id\n                    WHERE\n                    a.created_at > subdate(current_date, 1)\n                    GROUP BY\n                    f.id\n                ) v ON v.id = feeds.id\n                SET\n                stats = v.cnt   ";
     \DB::update(\DB::raw($sql));
     # Update the Stats for Tags
     $sql = "UPDATE\n                tags INNER JOIN\n                (             \n                    SELECT \n                     t.id,                \n                     COUNT(*) cnt\n                    FROM \n                      articles a INNER JOIN feeds f ON f.id = a.feed_id INNER JOIN feed_user u ON u.feed_id = f.id\n                     INNER JOIN tags t ON CONCAT(a.title,a.article_text) LIKE CONCAT('%',t.tag,'%')\n                     WHERE\n                     u.user_id = 1 \n                     GROUP BY\n                     t.id\n                ) v ON v.id = tags.id\n                SET\n                stats = v.cnt   ";
     \DB::update(\DB::raw($sql));
     # Update the Stats for Categories
     $sql = "UPDATE\n                categories INNER JOIN\n                (             \n                    SELECT\n                    u.category_id,\n                    COUNT(*) cnt\n                    FROM\n                    articles a INNER JOIN feeds f ON a.feed_id = f.id\n                    INNER JOIN feed_user u ON u.feed_id = f.id \n                    WHERE\n                    a.created_at > subdate(current_date, 1)\n                    GROUP BY\n                    u.category_id\n                ) v ON v.category_id = categories.id\n                SET\n                stats = v.cnt   ";
     \DB::update(\DB::raw($sql));
     # Update User Stats
     $sql = "UPDATE users\n                INNER JOIN\n                    (\n                        SELECT\n                        u.user_id,\n                        COUNT(*) new_articles\n                        FROM\n                        articles a INNER JOIN feed_user u ON a.feed_id = u.feed_id\n                        WHERE\n                        a.created_at > subdate(current_date, 1)\n                        GROUP BY\n                        u.user_id \n                    ) v ON users.id = v.user_id\n                SET\n                    users.new_articles = v.new_articles";
     \DB::update(\DB::raw($sql));
     # Update tua table
     \p4\Libraries\RSSParser::updateTagArticlesUsers();
 }