@@ -155,9 +155,9 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | public function getSiteDataFromURL(string $site_url) { |
| 157 | 157 | $query = $this->db->select('id, site_class') |
| 158 | - ->from('tracker_sites') |
|
| 159 | - ->where('site', $site_url) |
|
| 160 | - ->get(); |
|
| 158 | + ->from('tracker_sites') |
|
| 159 | + ->where('site', $site_url) |
|
| 160 | + ->get(); |
|
| 161 | 161 | |
| 162 | 162 | if($query->num_rows() > 0) { |
| 163 | 163 | $siteData = $query->row(); |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | public function getTitleID(string $titleURL, int $siteID) { |
| 170 | 170 | $query = $this->db->select('tracker_titles.id, tracker_titles.title, tracker_titles.title_url, tracker_titles.complete, tracker_sites.site_class, (tracker_titles.last_checked > DATE_SUB(NOW(), INTERVAL 3 DAY)) AS active', FALSE) |
| 171 | - ->from('tracker_titles') |
|
| 172 | - ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
| 173 | - ->where('tracker_titles.title_url', $titleURL) |
|
| 174 | - ->where('tracker_titles.site_id', $siteID) |
|
| 175 | - ->get(); |
|
| 171 | + ->from('tracker_titles') |
|
| 172 | + ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
| 173 | + ->where('tracker_titles.title_url', $titleURL) |
|
| 174 | + ->where('tracker_titles.site_id', $siteID) |
|
| 175 | + ->get(); |
|
| 176 | 176 | |
| 177 | 177 | if($query->num_rows() > 0) { |
| 178 | 178 | $id = (int) $query->row('id'); |
@@ -185,8 +185,8 @@ discard block |
||
| 185 | 185 | //Make sure last_checked is always updated on successful run. |
| 186 | 186 | //CHECK: Is there a reason we aren't just doing this in updateTitleById? |
| 187 | 187 | $this->db->set('last_checked', 'CURRENT_TIMESTAMP', FALSE) |
| 188 | - ->where('id', $id) |
|
| 189 | - ->update('tracker_titles'); |
|
| 188 | + ->where('id', $id) |
|
| 189 | + ->update('tracker_titles'); |
|
| 190 | 190 | } |
| 191 | 191 | } else { |
| 192 | 192 | log_message('error', "{$query->row('title')} failed to update successfully"); |
@@ -224,14 +224,14 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | $idQuery = $this->db->select('id') |
| 227 | - ->where('user_id', $userID) |
|
| 228 | - ->where('title_id', $titleID) |
|
| 229 | - ->get('tracker_chapters'); |
|
| 227 | + ->where('user_id', $userID) |
|
| 228 | + ->where('title_id', $titleID) |
|
| 229 | + ->get('tracker_chapters'); |
|
| 230 | 230 | if($idQuery->num_rows() > 0) { |
| 231 | 231 | $success = (bool) $this->db->set(['current_chapter' => $chapter, 'active' => 'Y', 'last_updated' => NULL]) |
| 232 | - ->where('user_id', $userID) |
|
| 233 | - ->where('title_id', $titleID) |
|
| 234 | - ->update('tracker_chapters'); |
|
| 232 | + ->where('user_id', $userID) |
|
| 233 | + ->where('title_id', $titleID) |
|
| 234 | + ->update('tracker_chapters'); |
|
| 235 | 235 | |
| 236 | 236 | if($success) { |
| 237 | 237 | $idQueryRow = $idQuery->row(); |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | public function updateTrackerByID(int $userID, int $chapterID, string $chapter) : bool { |
| 258 | 258 | $success = (bool) $this->db->set(['current_chapter' => $chapter, 'active' => 'Y', 'last_updated' => NULL]) |
| 259 | - ->where('user_id', $userID) |
|
| 260 | - ->where('id', $chapterID) |
|
| 261 | - ->update('tracker_chapters'); |
|
| 259 | + ->where('user_id', $userID) |
|
| 260 | + ->where('id', $chapterID) |
|
| 261 | + ->update('tracker_chapters'); |
|
| 262 | 262 | |
| 263 | 263 | if($success) { |
| 264 | 264 | $this->History->userUpdateTitle($chapterID, $chapter); |
@@ -271,23 +271,23 @@ discard block |
||
| 271 | 271 | //This is to allow user history to function properly. |
| 272 | 272 | |
| 273 | 273 | $success = $this->db->set(['active' => 'N', 'last_updated' => NULL]) |
| 274 | - ->where('user_id', $userID) |
|
| 275 | - ->where('id', $chapterID) |
|
| 276 | - ->update('tracker_chapters'); |
|
| 274 | + ->where('user_id', $userID) |
|
| 275 | + ->where('id', $chapterID) |
|
| 276 | + ->update('tracker_chapters'); |
|
| 277 | 277 | |
| 278 | 278 | return (bool) $success; |
| 279 | 279 | } |
| 280 | 280 | private function updateTitleById(int $id, string $latestChapter) { |
| 281 | 281 | //FIXME: Really not too happy with how we're doing history stuff here, it just feels messy. |
| 282 | 282 | $query = $this->db->select('latest_chapter AS current_chapter') |
| 283 | - ->from('tracker_titles') |
|
| 284 | - ->where('id', $id) |
|
| 285 | - ->get(); |
|
| 283 | + ->from('tracker_titles') |
|
| 284 | + ->where('id', $id) |
|
| 285 | + ->get(); |
|
| 286 | 286 | $row = $query->row(); |
| 287 | 287 | |
| 288 | 288 | $success = $this->db->set(['latest_chapter' => $latestChapter]) //last_updated gets updated via a trigger if something changes |
| 289 | - ->where('id', $id) |
|
| 290 | - ->update('tracker_titles'); |
|
| 289 | + ->where('id', $id) |
|
| 290 | + ->update('tracker_titles'); |
|
| 291 | 291 | |
| 292 | 292 | //Update History |
| 293 | 293 | //NOTE: To avoid doing another query to grab the last_updated time, we just use time() which <should> get the same thing. |
@@ -298,16 +298,16 @@ discard block |
||
| 298 | 298 | } |
| 299 | 299 | private function updateTitleDataById(int $id, array $titleData) { |
| 300 | 300 | $success = $this->db->set($titleData) |
| 301 | - ->where('id', $id) |
|
| 302 | - ->update('tracker_titles'); |
|
| 301 | + ->where('id', $id) |
|
| 302 | + ->update('tracker_titles'); |
|
| 303 | 303 | |
| 304 | 304 | return (bool) $success; |
| 305 | 305 | } |
| 306 | 306 | private function addTitle(string $titleURL, int $siteID) { |
| 307 | 307 | $query = $this->db->select('site, site_class') |
| 308 | - ->from('tracker_sites') |
|
| 309 | - ->where('id', $siteID) |
|
| 310 | - ->get(); |
|
| 308 | + ->from('tracker_sites') |
|
| 309 | + ->where('id', $siteID) |
|
| 310 | + ->get(); |
|
| 311 | 311 | |
| 312 | 312 | $titleData = $this->sites->{$query->row()->site_class}->getTitleData($titleURL); |
| 313 | 313 | //FIXME: getTitleData can fail, which will in turn cause the below to fail aswell, we should try and account for that |
@@ -359,8 +359,8 @@ discard block |
||
| 359 | 359 | //Make sure last_checked is always updated on successful run. |
| 360 | 360 | //CHECK: Is there a reason we aren't just doing this in updateTitleById? |
| 361 | 361 | $this->db->set('last_checked', 'CURRENT_TIMESTAMP', FALSE) |
| 362 | - ->where('id', $row->id) |
|
| 363 | - ->update('tracker_titles'); |
|
| 362 | + ->where('id', $row->id) |
|
| 363 | + ->update('tracker_titles'); |
|
| 364 | 364 | |
| 365 | 365 | print " - ({$titleData['latest_chapter']})\n"; |
| 366 | 366 | } |
@@ -477,9 +477,9 @@ discard block |
||
| 477 | 477 | } |
| 478 | 478 | public function setCategoryTrackerByID(int $userID, int $chapterID, string $category) : bool { |
| 479 | 479 | $success = $this->db->set(['category' => $category, 'active' => 'Y', 'last_updated' => NULL]) |
| 480 | - ->where('user_id', $userID) |
|
| 481 | - ->where('id', $chapterID) |
|
| 482 | - ->update('tracker_chapters'); |
|
| 480 | + ->where('user_id', $userID) |
|
| 481 | + ->where('id', $chapterID) |
|
| 482 | + ->update('tracker_chapters'); |
|
| 483 | 483 | |
| 484 | 484 | return (bool) $success; |
| 485 | 485 | } |
@@ -489,9 +489,9 @@ discard block |
||
| 489 | 489 | $success = FALSE; |
| 490 | 490 | if(preg_match("/^[a-z0-9-_,]{0,255}$/", $tag_string)) { |
| 491 | 491 | $success = (bool) $this->db->set(['tags' => $tag_string, 'active' => 'Y', 'last_updated' => NULL]) |
| 492 | - ->where('user_id', $userID) |
|
| 493 | - ->where('id', $chapterID) |
|
| 494 | - ->update('tracker_chapters'); |
|
| 492 | + ->where('user_id', $userID) |
|
| 493 | + ->where('id', $chapterID) |
|
| 494 | + ->update('tracker_chapters'); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | if($success) { |
@@ -529,23 +529,23 @@ discard block |
||
| 529 | 529 | |
| 530 | 530 | //We need the series to be tracked |
| 531 | 531 | $idCQuery = $this->db->select('id') |
| 532 | - ->where('user_id', $userID) |
|
| 533 | - ->where('title_id', $titleID) |
|
| 534 | - ->get('tracker_chapters'); |
|
| 532 | + ->where('user_id', $userID) |
|
| 533 | + ->where('title_id', $titleID) |
|
| 534 | + ->get('tracker_chapters'); |
|
| 535 | 535 | if($idCQuery->num_rows() > 0) { |
| 536 | 536 | $idCQueryRow = $idCQuery->row(); |
| 537 | 537 | |
| 538 | 538 | //Check if it is already favourited |
| 539 | 539 | $idFQuery = $this->db->select('id') |
| 540 | - ->where('chapter_id', $idCQueryRow->id) |
|
| 541 | - ->where('chapter', $chapter) |
|
| 542 | - ->get('tracker_favourites'); |
|
| 540 | + ->where('chapter_id', $idCQueryRow->id) |
|
| 541 | + ->where('chapter', $chapter) |
|
| 542 | + ->get('tracker_favourites'); |
|
| 543 | 543 | if($idFQuery->num_rows() > 0) { |
| 544 | 544 | //Chapter is already favourited, so remove it from DB |
| 545 | 545 | $idFQueryRow = $idFQuery->row(); |
| 546 | 546 | |
| 547 | 547 | $isSuccess = (bool) $this->db->where('id', $idFQueryRow->id) |
| 548 | - ->delete('tracker_favourites'); |
|
| 548 | + ->delete('tracker_favourites'); |
|
| 549 | 549 | |
| 550 | 550 | if($isSuccess) { |
| 551 | 551 | $success = array( |
@@ -616,11 +616,11 @@ discard block |
||
| 616 | 616 | |
| 617 | 617 | public function getUsedCategories(int $userID) : array { |
| 618 | 618 | $query = $this->db->distinct() |
| 619 | - ->select('category') |
|
| 620 | - ->from('tracker_chapters') |
|
| 621 | - ->where('tracker_chapters.active', 'Y') |
|
| 622 | - ->where('user_id', $userID) |
|
| 623 | - ->get(); |
|
| 619 | + ->select('category') |
|
| 620 | + ->from('tracker_chapters') |
|
| 621 | + ->where('tracker_chapters.active', 'Y') |
|
| 622 | + ->where('user_id', $userID) |
|
| 623 | + ->get(); |
|
| 624 | 624 | |
| 625 | 625 | return array_column($query->result_array(), 'category'); |
| 626 | 626 | } |
@@ -631,51 +631,51 @@ discard block |
||
| 631 | 631 | |
| 632 | 632 | //CHECK: Is it possible to merge some of these queries? |
| 633 | 633 | $queryUsers = $this->db->select([ |
| 634 | - 'COUNT(*) AS total_users', |
|
| 635 | - 'SUM(CASE WHEN api_key IS NOT NULL THEN 1 ELSE 0 END) AS validated_users', |
|
| 636 | - 'SUM(CASE WHEN (api_key IS NOT NULL AND from_unixtime(last_login) > DATE_SUB(NOW(), INTERVAL 7 DAY)) THEN 1 ELSE 0 END) AS active_users' |
|
| 637 | - ], FALSE) |
|
| 638 | - ->from('auth_users') |
|
| 639 | - ->get(); |
|
| 634 | + 'COUNT(*) AS total_users', |
|
| 635 | + 'SUM(CASE WHEN api_key IS NOT NULL THEN 1 ELSE 0 END) AS validated_users', |
|
| 636 | + 'SUM(CASE WHEN (api_key IS NOT NULL AND from_unixtime(last_login) > DATE_SUB(NOW(), INTERVAL 7 DAY)) THEN 1 ELSE 0 END) AS active_users' |
|
| 637 | + ], FALSE) |
|
| 638 | + ->from('auth_users') |
|
| 639 | + ->get(); |
|
| 640 | 640 | $stats = array_merge($stats, $queryUsers->result_array()[0]); |
| 641 | 641 | |
| 642 | 642 | $queryCounts = $this->db->select([ |
| 643 | - 'tracker_titles.title', |
|
| 644 | - 'COUNT(tracker_chapters.title_id) AS count' |
|
| 645 | - ], FALSE) |
|
| 646 | - ->from('tracker_chapters') |
|
| 647 | - ->join('tracker_titles', 'tracker_titles.id = tracker_chapters.title_id', 'left') |
|
| 648 | - ->group_by('tracker_chapters.title_id') |
|
| 649 | - ->having('count > 1') |
|
| 650 | - ->order_by('count DESC') |
|
| 651 | - ->get(); |
|
| 643 | + 'tracker_titles.title', |
|
| 644 | + 'COUNT(tracker_chapters.title_id) AS count' |
|
| 645 | + ], FALSE) |
|
| 646 | + ->from('tracker_chapters') |
|
| 647 | + ->join('tracker_titles', 'tracker_titles.id = tracker_chapters.title_id', 'left') |
|
| 648 | + ->group_by('tracker_chapters.title_id') |
|
| 649 | + ->having('count > 1') |
|
| 650 | + ->order_by('count DESC') |
|
| 651 | + ->get(); |
|
| 652 | 652 | $stats['titles_tracked_more'] = count($queryCounts->result_array()); |
| 653 | 653 | $stats['top_title_name'] = $queryCounts->result_array()[0]['title'] ?? 'N/A'; |
| 654 | 654 | $stats['top_title_count'] = $queryCounts->result_array()[0]['count'] ?? 'N/A'; |
| 655 | 655 | |
| 656 | 656 | $queryTitles = $this->db->select([ |
| 657 | - 'COUNT(DISTINCT tracker_titles.id) AS total_titles', |
|
| 658 | - 'COUNT(DISTINCT tracker_titles.site_id) AS total_sites', |
|
| 659 | - 'SUM(CASE WHEN from_unixtime(auth_users.last_login) > DATE_SUB(NOW(), INTERVAL 120 HOUR) IS NOT NULL THEN 0 ELSE 1 END) AS inactive_titles', |
|
| 660 | - 'SUM(CASE WHEN (tracker_titles.last_updated > DATE_SUB(NOW(), INTERVAL 24 HOUR)) THEN 1 ELSE 0 END) AS updated_titles' |
|
| 661 | - ], FALSE) |
|
| 662 | - ->from('tracker_titles') |
|
| 663 | - ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
| 664 | - ->join('tracker_chapters', 'tracker_titles.id = tracker_chapters.title_id', 'left') |
|
| 665 | - ->join('auth_users', 'tracker_chapters.user_id = auth_users.id', 'left') |
|
| 666 | - ->get(); |
|
| 657 | + 'COUNT(DISTINCT tracker_titles.id) AS total_titles', |
|
| 658 | + 'COUNT(DISTINCT tracker_titles.site_id) AS total_sites', |
|
| 659 | + 'SUM(CASE WHEN from_unixtime(auth_users.last_login) > DATE_SUB(NOW(), INTERVAL 120 HOUR) IS NOT NULL THEN 0 ELSE 1 END) AS inactive_titles', |
|
| 660 | + 'SUM(CASE WHEN (tracker_titles.last_updated > DATE_SUB(NOW(), INTERVAL 24 HOUR)) THEN 1 ELSE 0 END) AS updated_titles' |
|
| 661 | + ], FALSE) |
|
| 662 | + ->from('tracker_titles') |
|
| 663 | + ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
| 664 | + ->join('tracker_chapters', 'tracker_titles.id = tracker_chapters.title_id', 'left') |
|
| 665 | + ->join('auth_users', 'tracker_chapters.user_id = auth_users.id', 'left') |
|
| 666 | + ->get(); |
|
| 667 | 667 | $stats = array_merge($stats, $queryTitles->result_array()[0]); |
| 668 | 668 | |
| 669 | 669 | $querySites = $this->db->select([ |
| 670 | - 'tracker_sites.site', |
|
| 671 | - 'COUNT(*) AS count' |
|
| 672 | - ], FALSE) |
|
| 673 | - ->from('tracker_titles') |
|
| 674 | - ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
| 675 | - ->group_by('tracker_titles.site_id') |
|
| 676 | - ->order_by('count DESC') |
|
| 677 | - ->limit(3) |
|
| 678 | - ->get(); |
|
| 670 | + 'tracker_sites.site', |
|
| 671 | + 'COUNT(*) AS count' |
|
| 672 | + ], FALSE) |
|
| 673 | + ->from('tracker_titles') |
|
| 674 | + ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
| 675 | + ->group_by('tracker_titles.site_id') |
|
| 676 | + ->order_by('count DESC') |
|
| 677 | + ->limit(3) |
|
| 678 | + ->get(); |
|
| 679 | 679 | $querySitesResult = $querySites->result_array(); |
| 680 | 680 | $stats['rank1_site'] = $querySitesResult[0]['site']; |
| 681 | 681 | $stats['rank1_site_count'] = $querySitesResult[0]['count']; |
@@ -685,17 +685,17 @@ discard block |
||
| 685 | 685 | $stats['rank3_site_count'] = $querySitesResult[2]['count']; |
| 686 | 686 | |
| 687 | 687 | $queryTitlesU = $this->db->select([ |
| 688 | - 'COUNT(*) AS title_updated_count' |
|
| 689 | - ], FALSE) |
|
| 690 | - ->from('tracker_titles_history') |
|
| 691 | - ->get(); |
|
| 688 | + 'COUNT(*) AS title_updated_count' |
|
| 689 | + ], FALSE) |
|
| 690 | + ->from('tracker_titles_history') |
|
| 691 | + ->get(); |
|
| 692 | 692 | $stats = array_merge($stats, $queryTitlesU->result_array()[0]); |
| 693 | 693 | |
| 694 | 694 | $queryUsersU = $this->db->select([ |
| 695 | - 'COUNT(*) AS user_updated_count' |
|
| 696 | - ], FALSE) |
|
| 697 | - ->from('tracker_user_history') |
|
| 698 | - ->get(); |
|
| 695 | + 'COUNT(*) AS user_updated_count' |
|
| 696 | + ], FALSE) |
|
| 697 | + ->from('tracker_user_history') |
|
| 698 | + ->get(); |
|
| 699 | 699 | $stats = array_merge($stats, $queryUsersU->result_array()[0]); |
| 700 | 700 | |
| 701 | 701 | $stats['live_time'] = timespan(/*2016-09-10T03:17:19*/ 1473477439, time(), 2); |