phpBB3 importer: Use permalink normalization for category links
This commit is contained in:
parent
0d66a41753
commit
5be52fa821
|
@ -1,5 +1,6 @@
|
||||||
module ImportScripts::PhpBB3
|
module ImportScripts::PhpBB3
|
||||||
class PermalinkImporter
|
class PermalinkImporter
|
||||||
|
CATEGORY_LINK_NORMALIZATION = '/(viewforum.php\?)(?:.*&)?(f=\d+).*/\1\2'
|
||||||
POST_LINK_NORMALIZATION = '/(viewtopic.php\?)(?:.*&)?(p=\d+).*/\1\2'
|
POST_LINK_NORMALIZATION = '/(viewtopic.php\?)(?:.*&)?(p=\d+).*/\1\2'
|
||||||
TOPIC_LINK_NORMALIZATION = '/(viewtopic.php\?)(?:.*&)?(t=\d+).*/\1\2'
|
TOPIC_LINK_NORMALIZATION = '/(viewtopic.php\?)(?:.*&)?(t=\d+).*/\1\2'
|
||||||
|
|
||||||
|
@ -12,13 +13,9 @@ module ImportScripts::PhpBB3
|
||||||
normalizations = SiteSetting.permalink_normalizations
|
normalizations = SiteSetting.permalink_normalizations
|
||||||
normalizations = normalizations.blank? ? [] : normalizations.split('|')
|
normalizations = normalizations.blank? ? [] : normalizations.split('|')
|
||||||
|
|
||||||
if @settings.create_post_links && !normalizations.include?(POST_LINK_NORMALIZATION)
|
add_normalization(normalizations, CATEGORY_LINK_NORMALIZATION) if @settings.create_category_links
|
||||||
normalizations << POST_LINK_NORMALIZATION
|
add_normalization(normalizations, POST_LINK_NORMALIZATION) if @settings.create_post_links
|
||||||
end
|
add_normalization(normalizations, TOPIC_LINK_NORMALIZATION) if @settings.create_topic_links
|
||||||
|
|
||||||
if @settings.create_topic_links && !normalizations.include?(TOPIC_LINK_NORMALIZATION)
|
|
||||||
normalizations << TOPIC_LINK_NORMALIZATION
|
|
||||||
end
|
|
||||||
|
|
||||||
SiteSetting.permalink_normalizations = normalizations.join('|')
|
SiteSetting.permalink_normalizations = normalizations.join('|')
|
||||||
end
|
end
|
||||||
|
@ -28,9 +25,7 @@ module ImportScripts::PhpBB3
|
||||||
|
|
||||||
url = "viewforum.php?f=#{import_id}"
|
url = "viewforum.php?f=#{import_id}"
|
||||||
|
|
||||||
if !Permalink.find_by(url: url)
|
Permalink.create(url: url, category_id: category.id) unless permalink_exists(url)
|
||||||
Permalink.create(url: url, category_id: category.id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_for_topic(topic, import_id)
|
def create_for_topic(topic, import_id)
|
||||||
|
@ -38,9 +33,7 @@ module ImportScripts::PhpBB3
|
||||||
|
|
||||||
url = "viewtopic.php?t=#{import_id}"
|
url = "viewtopic.php?t=#{import_id}"
|
||||||
|
|
||||||
if !Permalink.find_by(url: url)
|
Permalink.create(url: url, topic_id: topic.id) unless permalink_exists(url)
|
||||||
Permalink.create(url: url, topic_id: topic.id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_for_post(post, import_id)
|
def create_for_post(post, import_id)
|
||||||
|
@ -48,9 +41,17 @@ module ImportScripts::PhpBB3
|
||||||
|
|
||||||
url = "viewtopic.php?p=#{import_id}"
|
url = "viewtopic.php?p=#{import_id}"
|
||||||
|
|
||||||
if !Permalink.find_by(url: url)
|
Permalink.create(url: url, post_id: post.id) unless permalink_exists(url)
|
||||||
Permalink.create(url: url, post_id: post.id)
|
end
|
||||||
end
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def add_normalization(normalizations, normalization)
|
||||||
|
normalizations << normalization unless normalizations.include?(normalization)
|
||||||
|
end
|
||||||
|
|
||||||
|
def permalink_exists(url)
|
||||||
|
Permalink.find_by(url: url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue