aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2018-09-06 22:26:20 +0200
committerKevin Decherf <kevin@kdecherf.com>2018-10-22 23:01:16 +0200
commite07fadea76aa7329c4b955a59e74cb867c733706 (patch)
tree8dcc67b77766c59961d1764c33976b0aa62ac448 /src/Wallabag
parent781864b9546b0ff2d6fe42ce72f78b8f40b785e9 (diff)
downloadwallabag-e07fadea76aa7329c4b955a59e74cb867c733706.tar.gz
wallabag-e07fadea76aa7329c4b955a59e74cb867c733706.tar.zst
wallabag-e07fadea76aa7329c4b955a59e74cb867c733706.zip
Refactor updateOriginUrl to include new behaviors behaviors
- Leave origin_url unchanged if difference is an ending slash - Leave origin_url unchanged if difference is scheme - Ignore (noop) if difference is query string or fragment Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php54
1 files changed, 45 insertions, 9 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index da0ec5a3..007ee8bb 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -246,15 +246,7 @@ class ContentProxy
246 */ 246 */
247 private function stockEntry(Entry $entry, array $content) 247 private function stockEntry(Entry $entry, array $content)
248 { 248 {
249 // When a redirection occurs while fetching an entry 249 $this->updateOriginUrl($entry, $content['url']);
250 // we move the original url in origin_url property if empty
251 // and set the entry url with the final value
252 if (!empty($content['url']) && $entry->getUrl() !== $content['url']) {
253 if (empty($entry->getOriginUrl())) {
254 $entry->setOriginUrl($entry->getUrl());
255 }
256 $entry->setUrl($content['url']);
257 }
258 250
259 $this->setEntryDomainName($entry); 251 $this->setEntryDomainName($entry);
260 252
@@ -321,6 +313,50 @@ class ContentProxy
321 } 313 }
322 314
323 /** 315 /**
316 * Update the origin_url field when a redirection occurs
317 * This field is set if it is empty and new url does not match ignore list.
318 *
319 * @param Entry $entry
320 * @param string $url
321 */
322 private function updateOriginUrl(Entry $entry, $url)
323 {
324 if (!empty($url) && $entry->getUrl() !== $url) {
325 $parsed_entry_url = parse_url($entry->getUrl());
326 $parsed_content_url = parse_url($url);
327
328 $diff_ec = array_diff_assoc($parsed_entry_url, $parsed_content_url);
329 $diff_ce = array_diff_assoc($parsed_content_url, $parsed_entry_url);
330
331 $diff = array_merge($diff_ec, $diff_ce);
332 $diff_keys = array_keys($diff);
333 sort($diff_keys);
334
335 switch ($diff_keys) {
336 case ['path']:
337 if (($parsed_entry_url['path'] . '/' === $parsed_content_url['path']) // diff is trailing slash, we only replace the url of the entry
338 || ($url === urldecode($entry->getUrl()))) { // we update entry url if new url is a decoded version of it, see EntryRepository#findByUrlAndUserId
339 $entry->setUrl($url);
340 }
341 break;
342 case ['scheme']:
343 $entry->setUrl($url);
344 break;
345 case ['fragment']:
346 case ['query']:
347 // noop
348 break;
349 default:
350 if (empty($entry->getOriginUrl())) {
351 $entry->setOriginUrl($entry->getUrl());
352 }
353 $entry->setUrl($url);
354 break;
355 }
356 }
357 }
358
359 /**
324 * Validate that the given content has at least a title, an html and a url. 360 * Validate that the given content has at least a title, an html and a url.
325 * 361 *
326 * @param array $content 362 * @param array $content