diff options
author | Lukas Winkler <github@lw1.at> | 2018-11-04 23:42:44 +0300 |
---|---|---|
committer | Stefan Giehl <stefan@piwik.org> | 2018-11-04 23:42:44 +0300 |
commit | e58934998b0276b50c14e1ef4f72e62ef4ef75ed (patch) | |
tree | c6da956d8dd0ee966a4019f379ad80b5665b38bf /plugins/SEO | |
parent | ef0a497d1f107853f437e21df1b291d5403da22d (diff) |
fix domain age from archive.org (#13574)
* fix domain age from archive.org
* fix test
* improve archive.org error handling
Diffstat (limited to 'plugins/SEO')
-rw-r--r-- | plugins/SEO/Metric/DomainAge.php | 14 | ||||
-rw-r--r-- | 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 855e0ada67..e48f40dbec 100644 --- a/plugins/SEO/Metric/DomainAge.php +++ b/plugins/SEO/Metric/DomainAge.php @@ -74,16 +74,12 @@ class DomainAge implements MetricsProvider */ private function getAgeArchiveOrg($domain) { - $data = $this->getUrl('https://wayback.archive.org/web/*/' . urlencode($domain)); - preg_match('#<a href=\"([^>]*)' . 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 ded1caa444..b42791fa15 100644 --- a/plugins/SEO/tests/Integration/SEOTest.php +++ b/plugins/SEO/tests/Integration/SEOTest.php @@ -55,11 +55,10 @@ class SEOTest extends \PHPUnit_Framework_TestCase $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'] . ']'); } } |