Skip to content

Commit

Permalink
Fix issue with not retrieving enough episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
canihavesomecoffee committed Oct 2, 2021
1 parent 8a0b405 commit 790c71a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 45 deletions.
9 changes: 7 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

## 2.x

### 2.0.7 (xx October 2021)
### 2.0.7 (02 October 2021)

Feature improvements
Feature improvements, bugfix

* New
* Artwork route
* Fix
* allEpisodes now returns all episodes. Apparently the limit in one page is 500 rather than 100, causing this to be
overlooked.
* Change
* Bump format of phpunit.xml test.

### 2.0.6 (30 September 2021)

Expand Down
5 changes: 5 additions & 0 deletions examples/retrieveAllEpisodesAtOnce.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@

// Retrieve all episodes from The Big Bang Theory (> 100 episodes).
$episodes = $theTVDbAPI->series()->allEpisodes(80379);
var_dump(sizeof($episodes));

// Retrieve all episodes from Casualty, more than 500 episodes.
$episodes = $theTVDbAPI->series()->allEpisodes(71756);
var_dump(sizeof($episodes));
var_dump($episodes);
58 changes: 27 additions & 31 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.4/phpunit.xsd"
bootstrap="tests/bootstrap.php"
verbose="true">

<testsuites>
<testsuite name="theTVDbAPI">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true" addUncoveredFilesFromWhitelist="true">
<directory>src</directory>
<exclude>
<directory suffix="Interface.php">src</directory>
</exclude>
</whitelist>
</filter>

<logging>
<log type="coverage-html" target="build/php/coverage"/>
<log type="coverage-clover" target="build/php/coverage.xml"/>
<log type="junit" target="build/php/test-results.xml"/>
</logging>
<php>
<env name="API_KEY" value="" />
<env name="API_USER" value="" />
<env name="API_USER_KEY" value="" />
</php>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="tests/bootstrap.php" verbose="true">
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
<include>
<directory>src</directory>
</include>
<exclude>
<directory suffix="Interface.php">src</directory>
</exclude>
<report>
<clover outputFile="build/php/coverage.xml"/>
<html outputDirectory="build/php/coverage"/>
</report>
</coverage>
<testsuites>
<testsuite name="theTVDbAPI">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/php/test-results.xml"/>
</logging>
<php>
<env name="API_KEY" value=""/>
<env name="API_USER" value=""/>
<env name="API_USER_KEY" value=""/>
</php>
</phpunit>
32 changes: 20 additions & 12 deletions src/Route/SeriesRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,28 @@ public function allEpisodes(int $id, string $seasonType = self::SEASON_TYPE_DEFA
if ($this->parent->getSecondaryLanguage() !== "") {
// Pre-fill results with fallback language, assuming the fallback language always has more results than the
// translated, primary language.
$eps = $this->episodes($id, 0, 0, $seasonType, $this->parent->getSecondaryLanguage());
foreach ($eps as $episode) {
$result[$episode->id] = $episode;
}
$page = 0;
do {
$eps = $this->episodes($id, 0, $page, $seasonType, $this->parent->getSecondaryLanguage());
foreach ($eps as $episode) {
$result[$episode->id] = $episode;
}
$page++;
} while (sizeof($eps) === 500);
}
$translatedEpisodes = $this->episodes($id, 0, 0, $seasonType, $this->parent->getPrimaryLanguage());
foreach ($translatedEpisodes as $episode) {
if (array_key_exists($episode->id, $result)) {
$result[$episode->id]->name = $episode->name;
$result[$episode->id]->overview = $episode->overview;
} else {
$result[$episode->id] = $episode;
$page = 0;
do {
$translatedEpisodes = $this->episodes($id, 0, $page, $seasonType, $this->parent->getPrimaryLanguage());
foreach ($translatedEpisodes as $episode) {
if (array_key_exists($episode->id, $result)) {
$result[$episode->id]->name = $episode->name;
$result[$episode->id]->overview = $episode->overview;
} else {
$result[$episode->id] = $episode;
}
}
}
$page++;
} while (sizeof($translatedEpisodes) === 500);

return array_values($result);
}
Expand Down

0 comments on commit 790c71a

Please sign in to comment.