mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
Merge pull request #4998 from gschlager/phpbb3
phpBB3 importer: Fix permalink generation
This commit is contained in:
commit
3d330f8c5e
@ -1,5 +1,6 @@
|
||||
module ImportScripts::PhpBB3
|
||||
class PermalinkImporter
|
||||
CATEGORY_LINK_NORMALIZATION = '/(viewforum.php\?)(?:.*&)?(f=\d+).*/\1\2'
|
||||
POST_LINK_NORMALIZATION = '/(viewtopic.php\?)(?:.*&)?(p=\d+).*/\1\2'
|
||||
TOPIC_LINK_NORMALIZATION = '/(viewtopic.php\?)(?:.*&)?(t=\d+).*/\1\2'
|
||||
|
||||
@ -12,13 +13,9 @@ module ImportScripts::PhpBB3
|
||||
normalizations = SiteSetting.permalink_normalizations
|
||||
normalizations = normalizations.blank? ? [] : normalizations.split('|')
|
||||
|
||||
if @settings.create_post_links && !normalizations.include?(POST_LINK_NORMALIZATION)
|
||||
normalizations << POST_LINK_NORMALIZATION
|
||||
end
|
||||
|
||||
if @settings.create_topic_links && !normalizations.include?(TOPIC_LINK_NORMALIZATION)
|
||||
normalizations << TOPIC_LINK_NORMALIZATION
|
||||
end
|
||||
add_normalization(normalizations, CATEGORY_LINK_NORMALIZATION) if @settings.create_category_links
|
||||
add_normalization(normalizations, POST_LINK_NORMALIZATION) if @settings.create_post_links
|
||||
add_normalization(normalizations, TOPIC_LINK_NORMALIZATION) if @settings.create_topic_links
|
||||
|
||||
SiteSetting.permalink_normalizations = normalizations.join('|')
|
||||
end
|
||||
@ -28,9 +25,7 @@ module ImportScripts::PhpBB3
|
||||
|
||||
url = "viewforum.php?f=#{import_id}"
|
||||
|
||||
if !Permalink.find_by(url: url)
|
||||
Permalink.create(url: url, category_id: category.id)
|
||||
end
|
||||
Permalink.create(url: url, category_id: category.id) unless permalink_exists(url)
|
||||
end
|
||||
|
||||
def create_for_topic(topic, import_id)
|
||||
@ -38,9 +33,7 @@ module ImportScripts::PhpBB3
|
||||
|
||||
url = "viewtopic.php?t=#{import_id}"
|
||||
|
||||
if !Permalink.find_by(url: url)
|
||||
Permalink.create(url: url, topic_id: topic.id)
|
||||
end
|
||||
Permalink.create(url: url, topic_id: topic.id) unless permalink_exists(url)
|
||||
end
|
||||
|
||||
def create_for_post(post, import_id)
|
||||
@ -48,9 +41,17 @@ module ImportScripts::PhpBB3
|
||||
|
||||
url = "viewtopic.php?p=#{import_id}"
|
||||
|
||||
if !Permalink.find_by(url: url)
|
||||
Permalink.create(url: url, post_id: post.id)
|
||||
end
|
||||
Permalink.create(url: url, post_id: post.id) unless permalink_exists(url)
|
||||
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
|
||||
|
@ -56,6 +56,7 @@ module ImportScripts::PhpBB3
|
||||
mapped[:pinned_globally] = row[:topic_type] == Constants::POST_GLOBAL
|
||||
mapped[:post_create_action] = proc do |post|
|
||||
@permalink_importer.create_for_topic(post.topic, row[:topic_id])
|
||||
@permalink_importer.create_for_post(post, row[:post_id])
|
||||
end
|
||||
|
||||
add_poll(row, mapped) if @settings.import_polls
|
||||
|
Loading…
Reference in New Issue
Block a user