@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | |
92 | 92 | public function getSiteDataFromURL(string $site_url) { |
93 | 93 | $query = $this->db->select('id, site_class') |
94 | - ->from('tracker_sites') |
|
95 | - ->where('site', $site_url) |
|
96 | - ->get(); |
|
94 | + ->from('tracker_sites') |
|
95 | + ->where('site', $site_url) |
|
96 | + ->get(); |
|
97 | 97 | |
98 | 98 | if($query->num_rows() > 0) { |
99 | 99 | $siteData = $query->row(); |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | |
105 | 105 | public function getTitleID(string $titleURL, int $siteID) { |
106 | 106 | $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) |
107 | - ->from('tracker_titles') |
|
108 | - ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
109 | - ->where('tracker_titles.title_url', $titleURL) |
|
110 | - ->where('tracker_titles.site_id', $siteID) |
|
111 | - ->get(); |
|
107 | + ->from('tracker_titles') |
|
108 | + ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
109 | + ->where('tracker_titles.title_url', $titleURL) |
|
110 | + ->where('tracker_titles.site_id', $siteID) |
|
111 | + ->get(); |
|
112 | 112 | |
113 | 113 | if($query->num_rows() > 0) { |
114 | 114 | $id = (int) $query->row('id'); |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | //Make sure last_checked is always updated on successful run. |
122 | 122 | //CHECK: Is there a reason we aren't just doing this in updateTitleById? |
123 | 123 | $this->db->set('last_checked', 'CURRENT_TIMESTAMP', FALSE) |
124 | - ->where('id', $id) |
|
125 | - ->update('tracker_titles'); |
|
124 | + ->where('id', $id) |
|
125 | + ->update('tracker_titles'); |
|
126 | 126 | } |
127 | 127 | } else { |
128 | 128 | log_message('error', "{$query->row('title')} failed to update successfully"); |
@@ -160,14 +160,14 @@ discard block |
||
160 | 160 | } |
161 | 161 | |
162 | 162 | $idQuery = $this->db->select('id') |
163 | - ->where('user_id', $userID) |
|
164 | - ->where('title_id', $titleID) |
|
165 | - ->get('tracker_chapters'); |
|
163 | + ->where('user_id', $userID) |
|
164 | + ->where('title_id', $titleID) |
|
165 | + ->get('tracker_chapters'); |
|
166 | 166 | if($idQuery->num_rows() > 0) { |
167 | 167 | $success = (bool) $this->db->set(['current_chapter' => $chapter, 'active' => 'Y', 'last_updated' => NULL]) |
168 | - ->where('user_id', $userID) |
|
169 | - ->where('title_id', $titleID) |
|
170 | - ->update('tracker_chapters'); |
|
168 | + ->where('user_id', $userID) |
|
169 | + ->where('title_id', $titleID) |
|
170 | + ->update('tracker_chapters'); |
|
171 | 171 | |
172 | 172 | if($success) { |
173 | 173 | $idQueryRow = $idQuery->row(); |
@@ -192,9 +192,9 @@ discard block |
||
192 | 192 | |
193 | 193 | public function updateTrackerByID(int $userID, int $chapterID, string $chapter) : bool { |
194 | 194 | $success = (bool) $this->db->set(['current_chapter' => $chapter, 'active' => 'Y', 'last_updated' => NULL]) |
195 | - ->where('user_id', $userID) |
|
196 | - ->where('id', $chapterID) |
|
197 | - ->update('tracker_chapters'); |
|
195 | + ->where('user_id', $userID) |
|
196 | + ->where('id', $chapterID) |
|
197 | + ->update('tracker_chapters'); |
|
198 | 198 | |
199 | 199 | if($success) { |
200 | 200 | $this->History->userUpdateTitle($chapterID, $chapter); |
@@ -207,23 +207,23 @@ discard block |
||
207 | 207 | //This is to allow user history to function properly. |
208 | 208 | |
209 | 209 | $success = $this->db->set(['active' => 'N', 'last_updated' => NULL]) |
210 | - ->where('user_id', $userID) |
|
211 | - ->where('id', $chapterID) |
|
212 | - ->update('tracker_chapters'); |
|
210 | + ->where('user_id', $userID) |
|
211 | + ->where('id', $chapterID) |
|
212 | + ->update('tracker_chapters'); |
|
213 | 213 | |
214 | 214 | return (bool) $success; |
215 | 215 | } |
216 | 216 | private function updateTitleById(int $id, string $latestChapter) { |
217 | 217 | //FIXME: Really not too happy with how we're doing history stuff here, it just feels messy. |
218 | 218 | $query = $this->db->select('latest_chapter AS current_chapter') |
219 | - ->from('tracker_titles') |
|
220 | - ->where('id', $id) |
|
221 | - ->get(); |
|
219 | + ->from('tracker_titles') |
|
220 | + ->where('id', $id) |
|
221 | + ->get(); |
|
222 | 222 | $row = $query->row(); |
223 | 223 | |
224 | 224 | $success = $this->db->set(['latest_chapter' => $latestChapter]) //last_updated gets updated via a trigger if something changes |
225 | - ->where('id', $id) |
|
226 | - ->update('tracker_titles'); |
|
225 | + ->where('id', $id) |
|
226 | + ->update('tracker_titles'); |
|
227 | 227 | |
228 | 228 | //Update History |
229 | 229 | //NOTE: To avoid doing another query to grab the last_updated time, we just use time() which <should> get the same thing. |
@@ -234,16 +234,16 @@ discard block |
||
234 | 234 | } |
235 | 235 | private function updateTitleDataById(int $id, array $titleData) { |
236 | 236 | $success = $this->db->set($titleData) |
237 | - ->where('id', $id) |
|
238 | - ->update('tracker_titles'); |
|
237 | + ->where('id', $id) |
|
238 | + ->update('tracker_titles'); |
|
239 | 239 | |
240 | 240 | return (bool) $success; |
241 | 241 | } |
242 | 242 | private function addTitle(string $titleURL, int $siteID) { |
243 | 243 | $query = $this->db->select('site, site_class') |
244 | - ->from('tracker_sites') |
|
245 | - ->where('id', $siteID) |
|
246 | - ->get(); |
|
244 | + ->from('tracker_sites') |
|
245 | + ->where('id', $siteID) |
|
246 | + ->get(); |
|
247 | 247 | |
248 | 248 | $titleData = $this->sites->{$query->row()->site_class}->getTitleData($titleURL); |
249 | 249 | $this->db->insert('tracker_titles', array_merge($titleData, ['title_url' => $titleURL, 'site_id' => $siteID])); |
@@ -294,8 +294,8 @@ discard block |
||
294 | 294 | //Make sure last_checked is always updated on successful run. |
295 | 295 | //CHECK: Is there a reason we aren't just doing this in updateTitleById? |
296 | 296 | $this->db->set('last_checked', 'CURRENT_TIMESTAMP', FALSE) |
297 | - ->where('id', $row->id) |
|
298 | - ->update('tracker_titles'); |
|
297 | + ->where('id', $row->id) |
|
298 | + ->update('tracker_titles'); |
|
299 | 299 | |
300 | 300 | print " - ({$titleData['latest_chapter']})\n"; |
301 | 301 | } |
@@ -412,9 +412,9 @@ discard block |
||
412 | 412 | } |
413 | 413 | public function setCategoryTrackerByID(int $userID, int $chapterID, string $category) : bool { |
414 | 414 | $success = $this->db->set(['category' => $category, 'active' => 'Y', 'last_updated' => NULL]) |
415 | - ->where('user_id', $userID) |
|
416 | - ->where('id', $chapterID) |
|
417 | - ->update('tracker_chapters'); |
|
415 | + ->where('user_id', $userID) |
|
416 | + ->where('id', $chapterID) |
|
417 | + ->update('tracker_chapters'); |
|
418 | 418 | |
419 | 419 | return (bool) $success; |
420 | 420 | } |
@@ -424,9 +424,9 @@ discard block |
||
424 | 424 | $success = FALSE; |
425 | 425 | if(preg_match("/^[a-z0-9-_,]{0,255}$/", $tag_string)) { |
426 | 426 | $success = (bool) $this->db->set(['tags' => $tag_string, 'active' => 'Y', 'last_updated' => NULL]) |
427 | - ->where('user_id', $userID) |
|
428 | - ->where('id', $chapterID) |
|
429 | - ->update('tracker_chapters'); |
|
427 | + ->where('user_id', $userID) |
|
428 | + ->where('id', $chapterID) |
|
429 | + ->update('tracker_chapters'); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | if($success) { |
@@ -464,23 +464,23 @@ discard block |
||
464 | 464 | |
465 | 465 | //We need the series to be tracked |
466 | 466 | $idCQuery = $this->db->select('id') |
467 | - ->where('user_id', $userID) |
|
468 | - ->where('title_id', $titleID) |
|
469 | - ->get('tracker_chapters'); |
|
467 | + ->where('user_id', $userID) |
|
468 | + ->where('title_id', $titleID) |
|
469 | + ->get('tracker_chapters'); |
|
470 | 470 | if($idCQuery->num_rows() > 0) { |
471 | 471 | $idCQueryRow = $idCQuery->row(); |
472 | 472 | |
473 | 473 | //Check if it is already favourited |
474 | 474 | $idFQuery = $this->db->select('id') |
475 | - ->where('chapter_id', $idCQueryRow->id) |
|
476 | - ->where('chapter', $chapter) |
|
477 | - ->get('tracker_favourites'); |
|
475 | + ->where('chapter_id', $idCQueryRow->id) |
|
476 | + ->where('chapter', $chapter) |
|
477 | + ->get('tracker_favourites'); |
|
478 | 478 | if($idFQuery->num_rows() > 0) { |
479 | 479 | //Chapter is already favourited, so remove it from DB |
480 | 480 | $idFQueryRow = $idFQuery->row(); |
481 | 481 | |
482 | 482 | $isSuccess = (bool) $this->db->where('id', $idFQueryRow->id) |
483 | - ->delete('tracker_favourites'); |
|
483 | + ->delete('tracker_favourites'); |
|
484 | 484 | |
485 | 485 | if($isSuccess) { |
486 | 486 | $success = array( |
@@ -553,10 +553,10 @@ discard block |
||
553 | 553 | $usedCategories = []; |
554 | 554 | |
555 | 555 | $query = $this->db->distinct() |
556 | - ->select('category') |
|
557 | - ->from('tracker_chapters') |
|
558 | - ->where('tracker_chapters.active', 'Y') |
|
559 | - ->get(); |
|
556 | + ->select('category') |
|
557 | + ->from('tracker_chapters') |
|
558 | + ->where('tracker_chapters.active', 'Y') |
|
559 | + ->get(); |
|
560 | 560 | |
561 | 561 | return array_column($query->result_array(), 'category'); |
562 | 562 | } |
@@ -568,51 +568,51 @@ discard block |
||
568 | 568 | |
569 | 569 | //$this->db->cache_on(); |
570 | 570 | $queryUsers = $this->db->select([ |
571 | - 'COUNT(*) AS total_users', |
|
572 | - 'SUM(CASE WHEN api_key IS NOT NULL THEN 1 ELSE 0 END) AS validated_users', |
|
573 | - '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' |
|
574 | - ], FALSE) |
|
575 | - ->from('auth_users') |
|
576 | - ->get(); |
|
571 | + 'COUNT(*) AS total_users', |
|
572 | + 'SUM(CASE WHEN api_key IS NOT NULL THEN 1 ELSE 0 END) AS validated_users', |
|
573 | + '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' |
|
574 | + ], FALSE) |
|
575 | + ->from('auth_users') |
|
576 | + ->get(); |
|
577 | 577 | $stats = array_merge($stats, $queryUsers->result_array()[0]); |
578 | 578 | |
579 | 579 | $queryCounts = $this->db->select([ |
580 | - 'tracker_titles.title', |
|
581 | - 'COUNT(tracker_chapters.title_id) AS count' |
|
582 | - ], FALSE) |
|
583 | - ->from('tracker_chapters') |
|
584 | - ->join('tracker_titles', 'tracker_titles.id = tracker_chapters.title_id', 'left') |
|
585 | - ->group_by('tracker_chapters.title_id') |
|
586 | - ->having('count > 1') |
|
587 | - ->order_by('count DESC') |
|
588 | - ->get(); |
|
580 | + 'tracker_titles.title', |
|
581 | + 'COUNT(tracker_chapters.title_id) AS count' |
|
582 | + ], FALSE) |
|
583 | + ->from('tracker_chapters') |
|
584 | + ->join('tracker_titles', 'tracker_titles.id = tracker_chapters.title_id', 'left') |
|
585 | + ->group_by('tracker_chapters.title_id') |
|
586 | + ->having('count > 1') |
|
587 | + ->order_by('count DESC') |
|
588 | + ->get(); |
|
589 | 589 | $stats['titles_tracked_more'] = count($queryCounts->result_array()); |
590 | 590 | $stats['top_title_name'] = $queryCounts->result_array()[0]['title'] ?? 'N/A'; |
591 | 591 | $stats['top_title_count'] = $queryCounts->result_array()[0]['count'] ?? 'N/A'; |
592 | 592 | |
593 | 593 | $queryTitles = $this->db->select([ |
594 | - 'COUNT(DISTINCT tracker_titles.id) AS total_titles', |
|
595 | - 'COUNT(DISTINCT tracker_titles.site_id) AS total_sites', |
|
596 | - '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', |
|
597 | - 'SUM(CASE WHEN (tracker_titles.last_updated > DATE_SUB(NOW(), INTERVAL 24 HOUR)) THEN 1 ELSE 0 END) AS updated_titles' |
|
598 | - ], FALSE) |
|
599 | - ->from('tracker_titles') |
|
600 | - ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
601 | - ->join('tracker_chapters', 'tracker_titles.id = tracker_chapters.title_id', 'left') |
|
602 | - ->join('auth_users', 'tracker_chapters.user_id = auth_users.id', 'left') |
|
603 | - ->get(); |
|
594 | + 'COUNT(DISTINCT tracker_titles.id) AS total_titles', |
|
595 | + 'COUNT(DISTINCT tracker_titles.site_id) AS total_sites', |
|
596 | + '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', |
|
597 | + 'SUM(CASE WHEN (tracker_titles.last_updated > DATE_SUB(NOW(), INTERVAL 24 HOUR)) THEN 1 ELSE 0 END) AS updated_titles' |
|
598 | + ], FALSE) |
|
599 | + ->from('tracker_titles') |
|
600 | + ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
601 | + ->join('tracker_chapters', 'tracker_titles.id = tracker_chapters.title_id', 'left') |
|
602 | + ->join('auth_users', 'tracker_chapters.user_id = auth_users.id', 'left') |
|
603 | + ->get(); |
|
604 | 604 | $stats = array_merge($stats, $queryTitles->result_array()[0]); |
605 | 605 | |
606 | 606 | $querySites = $this->db->select([ |
607 | - 'tracker_sites.site', |
|
608 | - 'COUNT(*) AS count' |
|
609 | - ], FALSE) |
|
610 | - ->from('tracker_titles') |
|
611 | - ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
612 | - ->group_by('tracker_titles.site_id') |
|
613 | - ->order_by('count DESC') |
|
614 | - ->limit(3) |
|
615 | - ->get(); |
|
607 | + 'tracker_sites.site', |
|
608 | + 'COUNT(*) AS count' |
|
609 | + ], FALSE) |
|
610 | + ->from('tracker_titles') |
|
611 | + ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
|
612 | + ->group_by('tracker_titles.site_id') |
|
613 | + ->order_by('count DESC') |
|
614 | + ->limit(3) |
|
615 | + ->get(); |
|
616 | 616 | $querySitesResult = $querySites->result_array(); |
617 | 617 | $stats['rank1_site'] = $querySitesResult[0]['site']; |
618 | 618 | $stats['rank1_site_count'] = $querySitesResult[0]['count']; |
@@ -622,17 +622,17 @@ discard block |
||
622 | 622 | $stats['rank3_site_count'] = $querySitesResult[2]['count']; |
623 | 623 | |
624 | 624 | $queryTitlesU = $this->db->select([ |
625 | - 'COUNT(*) AS title_updated_count' |
|
626 | - ], FALSE) |
|
627 | - ->from('tracker_titles_history') |
|
628 | - ->get(); |
|
625 | + 'COUNT(*) AS title_updated_count' |
|
626 | + ], FALSE) |
|
627 | + ->from('tracker_titles_history') |
|
628 | + ->get(); |
|
629 | 629 | $stats = array_merge($stats, $queryTitlesU->result_array()[0]); |
630 | 630 | |
631 | 631 | $queryUsersU = $this->db->select([ |
632 | - 'COUNT(*) AS user_updated_count' |
|
633 | - ], FALSE) |
|
634 | - ->from('tracker_user_history') |
|
635 | - ->get(); |
|
632 | + 'COUNT(*) AS user_updated_count' |
|
633 | + ], FALSE) |
|
634 | + ->from('tracker_user_history') |
|
635 | + ->get(); |
|
636 | 636 | $stats = array_merge($stats, $queryUsersU->result_array()[0]); |
637 | 637 | |
638 | 638 | $stats['live_time'] = timespan(/*2016-09-10T03:17:19*/ 1473477439, time(), 2); |