From e58934998b0276b50c14e1ef4f72e62ef4ef75ed Mon Sep 17 00:00:00 2001 From: Lukas Winkler Date: Sun, 4 Nov 2018 21:42:44 +0100 Subject: [PATCH] fix domain age from archive.org (#13574) * fix domain age from archive.org * fix test * improve archive.org error handling --- plugins/SEO/Metric/DomainAge.php | 14 +++++--------- plugins/SEO/tests/Integration/SEOTest.php | 7 +++---- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/plugins/SEO/Metric/DomainAge.php b/plugins/SEO/Metric/DomainAge.php index 855e0ada677..e48f40dbece 100644 --- a/plugins/SEO/Metric/DomainAge.php +++ b/plugins/SEO/Metric/DomainAge.php @@ -74,16 +74,12 @@ public function getMetrics($domain) */ private function getAgeArchiveOrg($domain) { - $data = $this->getUrl('https://wayback.archive.org/web/*/' . urlencode($domain)); - preg_match('#]*)' . preg_quote($domain) . '/\">([^<]*)<\/a>#', $data, $p); - if (!empty($p[2])) { - $value = strtotime($p[2]); - if ($value === false) { - return 0; - } - return $value; + $response = $this->getUrl('https://archive.org/wayback/available?timestamp=19900101&url=' . urlencode($domain)); + $data = json_decode($response, true); + if (empty($data["archived_snapshots"]["closest"]["timestamp"])) { + return 0; } - return 0; + return strtotime($data["archived_snapshots"]["closest"]["timestamp"]); } /** diff --git a/plugins/SEO/tests/Integration/SEOTest.php b/plugins/SEO/tests/Integration/SEOTest.php index ded1caa4442..b42791fa15f 100644 --- a/plugins/SEO/tests/Integration/SEOTest.php +++ b/plugins/SEO/tests/Integration/SEOTest.php @@ -55,11 +55,10 @@ public function test_API() $renderer->setSerialize(false); $ranks = $renderer->render($dataTable); foreach ($ranks as $rank) { - $message = $rank['id'] . ' expected non-zero rank, got [' . $rank['rank'] . ']'; - if(empty($rank['rank'])) { - $this->markTestSkipped("Skipped to avoid random build failure: " . $message); + if ($rank["id"] == "alexa") { // alexa is broken at the moment + continue; } - $this->assertNotEmpty($rank['rank'], $message); + $this->assertNotEmpty($rank['rank'], $rank['id'] . ' expected non-zero rank, got [' . $rank['rank'] . ']'); } }