*/
private function updateOriginUrl(Entry $entry, $url)
{
- if (!empty($url) && $entry->getUrl() !== $url) {
- $parsed_entry_url = parse_url($entry->getUrl());
- $parsed_content_url = parse_url($url);
+ if (empty($url) || $entry->getUrl() === $url) {
+ return false;
+ }
+
+ $parsed_entry_url = parse_url($entry->getUrl());
+ $parsed_content_url = parse_url($url);
- $diff_ec = array_diff_assoc($parsed_entry_url, $parsed_content_url);
- $diff_ce = array_diff_assoc($parsed_content_url, $parsed_entry_url);
+ $diff_ec = array_diff_assoc($parsed_entry_url, $parsed_content_url);
+ $diff_ce = array_diff_assoc($parsed_content_url, $parsed_entry_url);
- $diff = array_merge($diff_ec, $diff_ce);
- $diff_keys = array_keys($diff);
- sort($diff_keys);
+ $diff = array_merge($diff_ec, $diff_ce);
+ $diff_keys = array_keys($diff);
+ sort($diff_keys);
+
+ if ($this->ignoreUrl($entry->getUrl())) {
+ $entry->setUrl($url);
+ return false;
+ }
- if ($this->ignoreUrl($entry->getUrl())) {
+ switch ($diff_keys) {
+ case ['path']:
+ if (($parsed_entry_url['path'] . '/' === $parsed_content_url['path']) // diff is trailing slash, we only replace the url of the entry
+ || ($url === urldecode($entry->getUrl()))) { // we update entry url if new url is a decoded version of it, see EntryRepository#findByUrlAndUserId
+ $entry->setUrl($url);
+ }
+ break;
+ case ['scheme']:
$entry->setUrl($url);
- } else {
- switch ($diff_keys) {
- case ['path']:
- if (($parsed_entry_url['path'] . '/' === $parsed_content_url['path']) // diff is trailing slash, we only replace the url of the entry
- || ($url === urldecode($entry->getUrl()))) { // we update entry url if new url is a decoded version of it, see EntryRepository#findByUrlAndUserId
- $entry->setUrl($url);
- }
- break;
- case ['scheme']:
- $entry->setUrl($url);
- break;
- case ['fragment']:
- case ['query']:
- case ['fragment', 'query']:
- // noop
- break;
- default:
- if (empty($entry->getOriginUrl())) {
- $entry->setOriginUrl($entry->getUrl());
- }
- $entry->setUrl($url);
- break;
+ break;
+ case ['fragment']:
+ case ['query']:
+ case ['fragment', 'query']:
+ // noop
+ break;
+ default:
+ if (empty($entry->getOriginUrl())) {
+ $entry->setOriginUrl($entry->getUrl());
}
- }
+ $entry->setUrl($url);
+ break;
}
}