summaryrefslogtreecommitdiff
path: root/app/Libraries/Background.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Libraries/Background.php')
-rw-r--r--app/Libraries/Background.php34
1 files changed, 23 insertions, 11 deletions
diff --git a/app/Libraries/Background.php b/app/Libraries/Background.php
index 79d3ab1..626cc6f 100644
--- a/app/Libraries/Background.php
+++ b/app/Libraries/Background.php
@@ -19,6 +19,11 @@ use Eluceo\iCal\Component\Event;
class Background {
public function saveAiring(Anime $anime) {
+ if ( ! $anime->is_airing ) {
+ echo "Anime (" . $anime->mal_id . ") is not airing. Skipping.\n";
+ return;
+ }
+
$stats = $anime->getStats()->get()->first();
if ( is_null($stats->score) ) {
return;
@@ -55,10 +60,17 @@ class Background {
* Double entry.
*/
return;
+ } else {
+ /**
+ * We need to delete/reinsert because the airing date was postponed.
+ * Keep in mind that it's still the same episode which should be aired.
+ */
+ DB::table('airing')
+ ->where('mal_id', $anime->mal_id)
+ ->where('episode', $airing->episode)
+ ->where('aired_at', $airing->aired_at)
+ ->delete();
}
- /**
- * We need to update because the airing data was postponed.
- */
}
}
@@ -89,7 +101,7 @@ class Background {
public function saveAiringForAll() {
$anime_all = Anime::where('is_airing', true)->get();
foreach( $anime_all as $anime ) {
- $this->setAiring($anime);
+ $this->saveAiring($anime);
sleep(1);
}
}
@@ -106,13 +118,8 @@ class Background {
);
foreach($season->anime as $entry) {
- /**
- * Sleep to avoid 403 by MAL.
- */
- sleep(10);
- $check = Anime::where('mal_id', $entry->getMalID() )->first()->get();
- if ( ! is_null($check) ) {
+ if ( Anime::where('mal_id', $entry->getMalID())->exists() ) {
/**
* We already have this anime saved.
*/
@@ -121,6 +128,11 @@ class Background {
}
$anime = new Anime();
+
+ /**
+ * Sleep to avoid 403 by MAL.
+ */
+ sleep(10);
$anime->fill( $entry->getMalID(), $is_airing=true );
if( ! DB::table('anime')->where('mal_id', $entry->getMalID() )->exists() ) {
@@ -136,7 +148,7 @@ class Background {
foreach($anime as $entry ) {
$animeStats = new AnimeStats();
- $animeStats->fill( $entry->getMalID() );
+ $animeStats->fill( $entry->mal_id );
$animeStats->save();
}