diff options
author | Kevin Decherf <kevin@kdecherf.com> | 2018-10-24 21:54:09 +0200 |
---|---|---|
committer | Kevin Decherf <kevin@kdecherf.com> | 2018-10-24 21:54:09 +0200 |
commit | 5ba5e22a092068aeb12213578fd8fc4edb2399fe (patch) | |
tree | fac6c24617f67da0b1c7fe2e53d17664478dc0d1 | |
parent | b49c87acf12f22e38db751fb35be5da2436abc45 (diff) | |
download | wallabag-5ba5e22a092068aeb12213578fd8fc4edb2399fe.tar.gz wallabag-5ba5e22a092068aeb12213578fd8fc4edb2399fe.tar.zst wallabag-5ba5e22a092068aeb12213578fd8fc4edb2399fe.zip |
updateOriginUrl: rewrite some if, resolving feedbacks from PR
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/ContentProxy.php | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 2dc436f8..92351986 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php | |||
@@ -321,43 +321,46 @@ class ContentProxy | |||
321 | */ | 321 | */ |
322 | private function updateOriginUrl(Entry $entry, $url) | 322 | private function updateOriginUrl(Entry $entry, $url) |
323 | { | 323 | { |
324 | if (!empty($url) && $entry->getUrl() !== $url) { | 324 | if (empty($url) || $entry->getUrl() === $url) { |
325 | $parsed_entry_url = parse_url($entry->getUrl()); | 325 | return false; |
326 | $parsed_content_url = parse_url($url); | 326 | } |
327 | |||
328 | $parsed_entry_url = parse_url($entry->getUrl()); | ||
329 | $parsed_content_url = parse_url($url); | ||
327 | 330 | ||
328 | $diff_ec = array_diff_assoc($parsed_entry_url, $parsed_content_url); | 331 | $diff_ec = array_diff_assoc($parsed_entry_url, $parsed_content_url); |
329 | $diff_ce = array_diff_assoc($parsed_content_url, $parsed_entry_url); | 332 | $diff_ce = array_diff_assoc($parsed_content_url, $parsed_entry_url); |
330 | 333 | ||
331 | $diff = array_merge($diff_ec, $diff_ce); | 334 | $diff = array_merge($diff_ec, $diff_ce); |
332 | $diff_keys = array_keys($diff); | 335 | $diff_keys = array_keys($diff); |
333 | sort($diff_keys); | 336 | sort($diff_keys); |
337 | |||
338 | if ($this->ignoreUrl($entry->getUrl())) { | ||
339 | $entry->setUrl($url); | ||
340 | return false; | ||
341 | } | ||
334 | 342 | ||
335 | if ($this->ignoreUrl($entry->getUrl())) { | 343 | switch ($diff_keys) { |
344 | case ['path']: | ||
345 | if (($parsed_entry_url['path'] . '/' === $parsed_content_url['path']) // diff is trailing slash, we only replace the url of the entry | ||
346 | || ($url === urldecode($entry->getUrl()))) { // we update entry url if new url is a decoded version of it, see EntryRepository#findByUrlAndUserId | ||
347 | $entry->setUrl($url); | ||
348 | } | ||
349 | break; | ||
350 | case ['scheme']: | ||
336 | $entry->setUrl($url); | 351 | $entry->setUrl($url); |
337 | } else { | 352 | break; |
338 | switch ($diff_keys) { | 353 | case ['fragment']: |
339 | case ['path']: | 354 | case ['query']: |
340 | if (($parsed_entry_url['path'] . '/' === $parsed_content_url['path']) // diff is trailing slash, we only replace the url of the entry | 355 | case ['fragment', 'query']: |
341 | || ($url === urldecode($entry->getUrl()))) { // we update entry url if new url is a decoded version of it, see EntryRepository#findByUrlAndUserId | 356 | // noop |
342 | $entry->setUrl($url); | 357 | break; |
343 | } | 358 | default: |
344 | break; | 359 | if (empty($entry->getOriginUrl())) { |
345 | case ['scheme']: | 360 | $entry->setOriginUrl($entry->getUrl()); |
346 | $entry->setUrl($url); | ||
347 | break; | ||
348 | case ['fragment']: | ||
349 | case ['query']: | ||
350 | case ['fragment', 'query']: | ||
351 | // noop | ||
352 | break; | ||
353 | default: | ||
354 | if (empty($entry->getOriginUrl())) { | ||
355 | $entry->setOriginUrl($entry->getUrl()); | ||
356 | } | ||
357 | $entry->setUrl($url); | ||
358 | break; | ||
359 | } | 361 | } |
360 | } | 362 | $entry->setUrl($url); |
363 | break; | ||
361 | } | 364 | } |
362 | } | 365 | } |
363 | 366 | ||