[FallGuysBridge] fix: handle new data structure (#4640)
Some checks failed
Lint / phpcs (7.4) (push) Waiting to run
Lint / phpcompatibility (7.4) (push) Waiting to run
Lint / executable_php_files_check (push) Waiting to run
Tests / phpunit8 (7.4) (push) Waiting to run
Tests / phpunit8 (8.0) (push) Waiting to run
Tests / phpunit8 (8.1) (push) Waiting to run
Tests / phpunit8 (8.2) (push) Waiting to run
Tests / phpunit8 (8.3) (push) Waiting to run
Tests / phpunit8 (8.4) (push) Waiting to run
Build Image on Commit and Release / bake (push) Waiting to run
Documentation / documentation (push) Has been cancelled

* [FallGuysBridge] fix: handle new data structure

* [FallGuysBridge] review feedback: removed mixed
This commit is contained in:
User123698745 2025-08-04 01:36:44 +02:00 committed by GitHub
parent e5f9fe6251
commit 6ec4da854f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -37,13 +37,14 @@ class FallGuysBridge extends BridgeAbstract
public function collectData() public function collectData()
{ {
$html = getSimpleHTMLDOM(self::getURI()); $newsData = self::requestJsonData(self::getURI(), false);
$data = json_decode($html->find('#__NEXT_DATA__', 0)->innertext); foreach ($newsData->props->pageProps->newsList as $newsItem) {
$newsItemUrl = self::getURI() . '/' . $newsItem->slug;
$newsItemTitle = $newsItem->header->title;
foreach ($data->props->pageProps->newsList as $newsItem) {
$headerDescription = property_exists($newsItem->header, 'description') ? $newsItem->header->description : ''; $headerDescription = property_exists($newsItem->header, 'description') ? $newsItem->header->description : '';
$headerImage = $newsItem->header->image->src; $headerImage = $newsItem->newsLandingConfig->options[0]->image->src->url;
$contentImages = [$headerImage]; $contentImages = [$headerImage];
@ -52,7 +53,16 @@ class FallGuysBridge extends BridgeAbstract
<p><img src="{$headerImage}"></p> <p><img src="{$headerImage}"></p>
HTML; HTML;
foreach ($newsItem->content->items as $contentItem) { try {
$newsItemData = self::requestJsonData($newsItemUrl, true);
} catch (\Exception $e) {
$this->logger->error(sprintf('Failed to request data for news item "%s" (%s)', $newsItemTitle, $newsItemUrl), ['e' => $e]);
$newsItemData = null;
}
if (!$newsItemData) {
$this->logger->error(sprintf('Failed to parse json data for news item "%s" (%s)', $newsItemTitle, $newsItemUrl));
} else {
foreach ($newsItemData->props->pageProps->pageData->content->items as $contentItem) {
if (property_exists($contentItem, 'articleCopy')) { if (property_exists($contentItem, 'articleCopy')) {
if (property_exists($contentItem->articleCopy, 'title')) { if (property_exists($contentItem->articleCopy, 'title')) {
$title = $contentItem->articleCopy->title; $title = $contentItem->articleCopy->title;
@ -105,14 +115,17 @@ class FallGuysBridge extends BridgeAbstract
} }
} }
} }
} else {
$this->logger->warning(sprintf('Unsupported content item in news item "%s" (%s)', $newsItemTitle, $newsItemUrl));
}
} }
} }
$item = [ $item = [
'uid' => $newsItem->_id, 'uid' => $newsItem->id,
'uri' => self::getURI() . '/' . $newsItem->_slug, 'uri' => $newsItemUrl,
'title' => $newsItem->_title, 'title' => $newsItemTitle,
'timestamp' => $newsItem->lastModified, 'timestamp' => $newsItem->activeDate,
'content' => $content, 'content' => $content,
'enclosures' => $contentImages, 'enclosures' => $contentImages,
]; ];
@ -131,4 +144,12 @@ class FallGuysBridge extends BridgeAbstract
{ {
return self::BASE_URI . '/favicon.ico'; return self::BASE_URI . '/favicon.ico';
} }
private function requestJsonData(string $url, bool $useCache)
{
$html = $useCache ? getSimpleHTMLDOMCached($url) : getSimpleHTMLDOM($url);
$jsonElement = $html->find('#__NEXT_DATA__', 0);
$json = $jsonElement ? $jsonElement->innertext : null;
return json_decode($json);
}
} }