素晴らしい!解決してよかったです。コツは何でしたか?
これを必要としないことを願っています Discourse Migration - Literate Computing
素晴らしい!解決してよかったです。コツは何でしたか?
これを必要としないことを願っています Discourse Migration - Literate Computing
すべてのカテゴリがインポートされるまで import_phpbb3.sh を繰り返し実行する必要がありました。スクリプトは一晩実行されましたが、ネットワークの中断により私の側で何らかのエラーが発生しました。スクリプトを再起動したところ、現在機能しているようです。さらに問題がある場合は、MySQL テーブルをクリーンアップする必要があります。
皆さん、こんにちは!フォーラムはほぼ稼働しており、素晴らしい出来栄えです。[/quote]タグを修正するスクリプトを書いています。このボードは2001年からとかなり古く、終了タグの上下にスペースを追加するだけでかなりの問題が解決します。インポートスクリプトで設定を変更できたはずですが、初めての移行なので、試行錯誤しながら学んでいます。
質問: 10年分のデータを修正しており、phpBBボードが稼働中です。時間がかかっています。フォーラムの過去X日間の投稿をインポートするために、import_phpbb3.shスクリプトを使用できますか?スクリプトとしては単なるマージだと思います。MySQLから過去7日間のデータをエクスポートできますが、それが機能するかどうかはわかりません。何か考えはありますか?
スクリプトが機能するかどうかはまだ確認していません。小さな部分でテストしましたが、バッチ処理はしていません。問題は、終了タグの上下のスペースでした。今から芝刈りに行って、後で戻って確認します。
batch_size = 1000
total_processed = 0
# バッチでサイト全体の投稿を処理する
Post.find_in_batches(batch_size: batch_size) do |batch|
updated_posts = []
batch.each do |post|
original_raw = post.raw
# 修正を適用する
new_raw = original_raw.gsub(/\n\n\[\/quote\]\n\n\n/, "\n\n[/quote]\n\n")
if original_raw != new_raw
post.update_column(:raw, new_raw) # コールバックをスキップするために列を直接更新する
updated_posts << post
total_processed += 1
end
end
# 更新された投稿のみを再ベイクして負荷を最小限にする
updated_posts.each(&:rebake!)
puts "バッチ #{batch.size} 件を処理しました。これまでの総処理件数: #{total_processed} 件。"
end
puts "サイト全体で合計 #{total_processed} 件の投稿を処理しました。"
これは個々の投稿で機能しました。
post = Post.find(344572) # 344572 を正しい ID に置き換えてください
post.raw = post.raw.gsub(/\n\\n\[\/quote\]\\n\n\n/, “\n\n[/quote]\n\n”)
データをインポートするときにスクリプトを変更してこれを行うでしょう。すでにそうではないことに驚いています。詳しく調べる価値があります。
私が取り組んできたいくつかのスクリプトでは、IMPORT_AFTER ENV 設定を追加し、クエリを where some_timestamp > import_after_data を含めるように変更しました。これにはそのようなオプションはないと思いますが、注意深く見ていません。
ただし、10年前のデータにあるものは過去2年間のものとは異なる可能性が高いことに注意してください。そのため、最近のデータのみでテストすることは、すべてに存在するものをデバッグするのに役立ちますが、データベース全体でもテストしたいでしょう。
混在しているさまざまなものがあります。インポートは完了まであと 99% です…先週の投稿をすべて取り込む必要があります
改行が追加され、これが修正されればすべて問題なくなるはずです ![]()
インポート後に投稿の大部分をクリーンアップするために行ったことを紹介します。PhpBBからの移行者向けの説明をAIに提供してもらいました。それを機能させるために午前5時までかかりました:rofl:![]()
![]()
Discourse環境内でRubyスクリプトを実行し、トピックを1000件ずつのバッチで処理し、それらのトピック内の各投稿に特定の変換を適用するには、サーバーにアクセスし、適切な環境に入り、スクリプトを実行するための一連の手順に従います。以下に、スクリプト自体を含む詳細なガイドを示します。
Windows用のPuTTYのようなセキュアシェル(SSH)クライアントを使用して、Discourseフォーラムがホストされているサーバーに接続します。サーバーのIPアドレスまたはドメイン名、および認証情報(ユーザー名とパスワードまたはSSHキー)が必要です。
サーバーにログインしたら、Discourseのインストールディレクトリ(通常は/var/discourse)に移動し、次のコマンドを使用してDiscourseを実行しているDockerコンテナに入ります。
bash
cd /var/discourse
./launcher enter app
Dockerコンテナ内では、Railsコンソールを介してDiscourseアプリケーションと対話できます。これは、Discourseデータベースとアプリケーションロジックに対してRubyコードを直接実行できるRuby on Rails環境です。コンソールを次のように開始します。
bash
rails c
Railsコンソールが開いたら、Rubyスクリプトを実行する準備ができました。スクリプトは事前に準備しておき、クリップボードにコピーしておく必要があります。PuTTYでは、右クリックするか、Shift + Insertを押すことでスクリプトを貼り付けることができます。
以下は、使用する完全なスクリプトです。
code
# すべてのトピックIDの配列を取得します
topic_ids = Topic.pluck(:id)
# バッチサイズを定義します
batch_size = 1000
current_batch_start = 0
while current_batch_start < topic_ids.length
# 一度に1000件のトピックのバッチを処理します
topic_ids[current_batch_start, batch_size].each do |topic_id|
# IDでトピックを取得します
topic = Topic.find(topic_id)
# トピックがnilの場合はスキップします
next if topic.nil?
# このトピックの変換済み投稿数を初期化します
transformed_count = 0
# トピック内の各投稿を反復処理します
topic.posts.each do |post|
# 変換が行われたかどうかを追跡するフラグ
transformed = false
# 変換を適用します
transformed |= post.raw.gsub!(/\u003c\\/?r\u003e/, '').present?
transformed |= post.raw.gsub!(/\u003c\\/?s\u003e/, '').present?
transformed |= post.raw.gsub!(/\u003c\\/?e\u003e/, '').present?
transformed |= post.raw.gsub!(/\u003c\\/?QUOTE[^\u003e]*\u003e/, '').present?
transformed |= post.raw.gsub!(/\\[quote=““([^”]+)””\\]/, '[quote=\"\\1\"]').present?
transformed |= post.raw.gsub!(/\\\\n/, "\\n").present?
transformed |= post.raw.gsub!(/\\[quote=([^\\s]+)\\s+post_id=\\d+\\s+time=\\d+\\s+user_id=\\d+\\]/, '[quote=\"\\1\"]').present?
transformed |= post.raw.gsub!(/\u003cURL url=\"([^\"]+)\"\u003e.*?\u003cLINK_TEXT text=\"[^\"]+\"\u003e[^\u003c]+\u003c\\/LINK_TEXT\u003e.*?\u003c\\/URL\u003e/, '\\1').present?
transformed |= post.raw.gsub!(/\\[\\/quote\\]/, "\\n[/quote]\\n").present?
transformed |= post.raw.gsub!(/\\A\\n/, '').present?
# 変換が行われた場合は、投稿を保存して再ベイクします
if transformed
post.save!
post.rebake!
transformed_count += 1
end
end
# 現在のトピックの結果を出力します
if transformed_count > 0
puts "Transformed #{transformed_count} posts in topic #{topic_id}."
else
puts "No transformations were necessary for topic #{topic_id}."
end
end
# 次のバッチの開始インデックスを更新します
current_batch_start += batch_size
# 処理するトピックがさらにあるかどうかを確認します
if current_batch_start < topic_ids.length
puts "Completed a batch of #{batch_size} topics. Do you want to continue to the next batch? (yes/no)"
response = gets.strip.downcase
break unless response == 'yes'
end
end
実行中の様子は次のようになります。
No transformations were necessary for topic 19556.
No transformations were necessary for topic 35766.
No transformations were necessary for topic 35783.
No transformations were necessary for topic 35778.
No transformations were necessary for topic 35774.
No transformations were necessary for topic 35770.
Transformed 292 posts in topic 20234.
No transformations were necessary for topic 35781.
No transformations were necessary for topic 35779.
Transformed 242 posts in topic 20218.
Transformed 22 posts in topic 19522.
No transformations were necessary for topic 35771.
No transformations were necessary for topic 35767.
Transformed 2 posts in topic 22560.
No transformations were necessary for topic 35797.
No transformations were necessary for topic 35789.
No transformations were necessary for topic 35785.
No transformations were necessary for topic 31889.
Transformed 1 posts in topic 31831.
No transformations were necessary for topic 31792.
No transformations were necessary for topic 35794.
No transformations were necessary for topic 35815.
このエラー(マイグレーション後、正常に機能している標準インストールで)が、ユーザーの表示名(ユーザー名ではなく)に特殊文字を含めようとしたときに発生します。試すと internal server error というポップアップが表示され、ログには @DDo と同じエラーが表示されます。
特筆すべきは、他のユーザーは同じ文字(™)を含む表示名を変更できることです。関連する違いは、マイグレーション後にログインしたユーザーはUTF-8文字を含めることができるのに対し、ログインしていないユーザーはASCII-8BITしか含めることができないようです。
このエラーは discourse-migratepassword を削除することで解決されるとも推測されますが、テストはしていません。
これはバグですか、それともそのプラグインを機能させるために固有のものですか?もし前者であれば、GitHubに問題を報告するのが最善でしょうか?
インポートコンテナを(再)構築しようとしていますが、失敗します。
FAILED
--------------------
Errno::ENOENT: No such file or directory @ rb_sysopen - /etc/service/unicorn/run
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/replace_command.rb:11:in `read'
replace failed with the params {"tag"=>"precompile", "filename"=>"/etc/service/unicorn/run", "from"=>"PRECOMPILE_ON_BOOT=1", "to"=>"PRECOMPILE_ON_BOOT=0"}
bootstrap failed with exit code 1
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
すでにすべてのプラグインを無効にしましたが、変更はありません。
何かアイデアはありますか?
それが最初のアイデアです。
何かエラーを示しているものは見つかりませんでした。もう一度探してみます…
hooks:
after_web_config:
- exec:
cd: /etc/service
cmd:
# - rm -R unicorn
- rm -R nginx
- rm -R cron
templates/import/phpbb3.template.yml の - rm -R unicorn の行をコメントアウトしたところ、ビルドはエラーなしで完了しました。
これはどういうことでしょうか? phpbb3.template.yml は2年前のGithubのバージョンです。ということは、どこか別の場所で変更があったはずです?!?
UbuntuからDebianに切り替える前のものかもしれません。これらは、誰かが動作しなくなったことに気づくまで更新されない可能性が高いです。
rmが問題だったというのはあまり意味がありませんが、誰かに報酬を払われていない限り、あまり気にかけていません。そして、そのことにもあまり注意を払った記憶がありません。 ![]()
ビルダーが /etc/service/unicorn/run がないことを訴え、まさにそれが削除された場合、この削除コマンドをコメントアウトすることを考えました。
うまくいきました。
おそらく、すべてについてより多くの知識を持つ誰かが確認し、スクリプトをGitHubで更新したいと思うでしょう。私もPRを作成できますが、すべてについて知識がないため、したくありません。
しかし、UbuntuからDebianに変更すると、多くのことが変わります。本当です。
まず、私はDocker初心者なので、何か間違ったことをしている可能性が高いです。
DigitalOcean DropletにUbuntu 22.04を搭載し、プリビルドアプリを使用してDiscourseをクリーンインストールしました。フォーラムは正常に構築され、標準構成で実行されています。
/var/discourse/launcher rebuild import を実行すると、ビルドの最後に以下のメッセージが表示されます。
Errno::ENOENT: No such file or directory @ rb_sysopen - /etc/service/unicorn/run
Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups/replace_command.rb:11:in `read'
replace failed with the params {"tag"=>"precompile", "filename"=>"/etc/service/unicorn/run", "from"=>"PRECOMPILE_ON_BOOT=1", "to"=>"PRECOMPILE_ON_BOOT=0"}
bootstrap failed with exit code 1
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
/var/discourse/launcher enter import を実行すると、以下のメッセージが表示されます。
86_64 arch detected.
Error response from daemon: No such container: import
これは、この投稿の冒頭のエラー(もしそうなら、どうすれば修正できますか)のせいですか、それとも私が何か間違っていますか?
import.yml を作成し、(指示にそう書いてあったと確信していますが) そのコンテナをブートストラップしましたか?
指示では、app.yml を import.yml にコピーし、「templates/import/phpbb3.template.yml」を import.yml に追加する(これは実行しました)と示されています。その後、import を再構築すると、私の OP にあるエラーが発生します。ブートストラップを作成する指示のどこにも見当たりません(?)。
指示は非常に単純なので、何がうまくいかないのか混乱しています。
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
81a2f335fd01 local_discourse/app “/sbin/boot” 14 hours ago Up 11 hours 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp app
申し訳ありません。Rebuildはブートストラップを実行します。完了すると、インポートコンテナが実行されていました。
おお。大変申し訳ありません。以前何が起こっていたのか把握できませんでした。phpbb3テンプレートがdiscourse_dockerの最近の変更と互換性がない可能性があります。しかし、それが携帯電話でわかるすべてです。
phpbb3テンプレートで「/etc/service/unicorn/run」を削除する行を削除すると、ビルドが完了する可能性があると思います。
Jay、この問題への回答ありがとうございます。ビルドが正常に完了しました。
次の問題です。import_phpbb3.sh を実行すると、次のエラーが表示されます。
The phpBB3 import is starting...
/usr/local/lib/ruby/3.3.0/psych/parser.rb:62:in `_native_parse': (unknown): did not find expected key while parsing a block mapping at line 3 column 1 (Psych::SyntaxError)
from /usr/local/lib/ruby/3.3.0/psych/parser.rb:62:in `parse'
from /usr/local/lib/ruby/3.3.0/psych.rb:455:in `parse_stream'
from /usr/local/lib/ruby/3.3.0/psych.rb:399:in `parse'
from /var/www/discourse/vendor/bundle/ruby/3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/compile_cache/yaml.rb:129:in `strict_load'
from /var/www/discourse/vendor/bundle/ruby/3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/compile_cache/yaml.rb:186:in `input_to_storage'
from /var/www/discourse/vendor/bundle/ruby/3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/compile_cache/yaml.rb:232:in `fetch'
from /var/www/discourse/vendor/bundle/ruby/3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/compile_cache/yaml.rb:232:in `load_file'
from /var/www/discourse/script/import_scripts/phpbb3/support/settings.rb:10:in `load'
from script/import_scripts/phpbb3.rb:20:in `<module:PhpBB3>'
from script/import_scripts/phpbb3.rb:16:in `<module:ImportScripts>'
from script/import_scripts/phpbb3.rb:15:in `<main>'
settings.yml ファイルの何かが気に入らないのだと思いますが、何が原因かどうすればわかりますか?
database:
type: MySQL # currently only MySQL is supported
host: localhost
port: 3306
username:
password:
schema: phpbb
table_prefix: phpbb_ # Change this, if your forum is using a different prefix. Usually all table names start wi
th phpbb_
batch_size: 1000 # Don't change this unless you know what you're doing. The default (1000) should work just fin
e.
import:
# Set this if you import multiple phpBB forums into a single Discourse forum.
#
# For example, when importing multiple sites, prefix all imported IDs
# with 'first' to avoid conflicts. Subsequent import runs must have a
# different 'site_name'.
#
# site_name: first
#
site_name: Freedom Owners Forum
# Create new categories
#
# For example, to create a parent category and a subcategory.
#
# new_categories:
# - forum_id: foo
# name: Foo Category
# - forum_id: bar
# name: Bar Category
# parent_id: foo
#
new_categories:
- forum_id: general
name: General
- forum_id: systems
name: Boat Systems
- forum_id: photos
name: Photos
- forum_id: docs
name: Manuals and Documentation
- forum_id: buy
name: Buy/Sell/Trade
- forum_id: site
name: Site Usage
- forum_id: archives
name: Archives
# Category mappings
#
# * "source_category_id" is the forum ID in phpBB3
# * "target_category_id" is either a forum ID from phpBB3 or a "forum_id"
# from the "new_categories" setting (see above)
# * "discourse_category_id" is a category ID from Discourse
# * "skip" allows you to ignore a category during import
#
# Use "target_category_id" if you want to merge categories and use
# "discourse_category_id" if you want to import a forum into an existing
# category in Discourse.
#
# category_mappings:
# - source_category_id: 1
# target_category_id: foo
# - source_category_id: 2
# discourse_category_id: 42
# - source_category_id: 6
# skip: true
#
category_mappings:
- source_category_id: 8
target_category_id: systems
- source_category_id: 7
target_category_id: systems
- source_category_id: 9
target_category_id: systems
- source_category_id: 10
target_category_id: buy
- source_category_id: 11
target_category_id: general
- source_category_id: 12
target_category_id: general
- source_category_id: 13
target_category_id: general
- source_category_id: 14
target_category_id: general
- source_category_id: 16
target_category_id: docs
- source_category_id: 17
target_category_id: docs
- source_category_id: 18
target_category_id: general
- source_category_id: 19
target_category_id: general
- source_category_id: 20
target_category_id: general
- source_category_id: 21
target_category_id: docs
- source_category_id: 22
target_category_id: general
- source_category_id: 23
target_category_id: site
- source_category_id: 24
target_category_id: general
- source_category_id: 25
target_category_id: site
- source_category_id: 42
target_category_id: systems
- source_category_id: 43
target_category_id: docs
- source_category_id: 44
target_category_id: general
- source_category_id: 45
target_category_id: general
- source_category_id: 46
target_category_id: site
- source_category_id: 48
target_category_id: general
- source_category_id: 56
target_category_id: general
- source_category_id: 58
target_category_id: systems
- source_category_id: 59
skip: true
- source_category_id: 60
target_category_id: archives
- source_category_id: 61
target_category_id: archives
- source_category_id: 62
target_category_id: archives
- source_category_id: 63
target_category_id: archives
- source_category_id: 64
target_category_id: general
- source_category_id: 65
target_category_id: site
# Tag mappings
#
# For example, imported topics from phpBB category 1 will be tagged
# with 'first-category', etc.
#
# tag_mappings:
# 1:
# - first-category
# 2:
# - second-category
# 3:
# - third-category
#
tag_mappings: {}
# Rank to trust level mapping
#
# Map phpBB 3.x rank levels to trust level
# Users with rank at least 3000 will have TL3, etc.
#
rank_mapping:
trust_level_1: 200
trust_level_2: 1000
trust_level_3: 3000
# rank_mapping: {}
# WARNING: Do not activate this option unless you know what you are doing.
# It will probably break the BBCode to Markdown conversion and slows down your import.
use_bbcode_to_md: false
# This is the path to the root directory of your current phpBB installation (or a copy of it).
# The importer expects to find the /files and /images directories within the base directory.
# You need to change this to something like /var/www/phpbb if you are not using the Docker based importer.
# This is only needed if you want to import avatars, attachments or custom smilies.
phpbb_base_dir: /shared/import/data
site_prefix:
# this is needed for rewriting internal links in posts
original: freedomyachts.org # without http(s)://
new: https://test.freedomyachts.org # with http:// or https://
# Enable this, if you want to redirect old forum links to the new locations.
permalinks:
categories: true # redirects /viewforum.php?f=1 to /c/category-name
topics: true # redirects /viewtopic.php?f=6&t=43 to /t/topic-name/81
posts: false # redirects /viewtopic.php?p=2455#p2455 to /t/topic-name/81/4
# Append a prefix to each type of link, e.g. 'forum' to redirect /forum/viewtopic.php?f=6&t=43 to /t/topic-na
me/81
# Leave it empty if your forum wasn't installed in a subfolder.
prefix:
avatars:
uploaded: true # import uploaded avatars
gallery: true # import the predefined avatars phpBB offers
remote: false # WARNING: This can considerably slow down your import. It will try to download remote avatar
s.
# When true: Anonymous users are imported as suspended users. They can't login and have no email address.
# When false: The system user will be used for all anonymous users.
anonymous_users: true
# Enable this, if you want import password hashes in order to use the "migratepassword" plugin.
# This will allow users to login with their current password.
# The plugin is available at: https://github.com/discoursehosting/discourse-migratepassword
passwords: true
# By default all the following things get imported. You can disable them by setting them to false.
bookmarks: true
attachments: true
private_messages: true
polls: true
# Import likes from the phpBB's "Thanks for posts" extension
likes: false
# When true: each imported user will have the original username from phpBB as its name
# When false: the name of each imported user will be blank unless the username was changed during import
username_as_name: false
# Map Emojis to smilies used in phpBB. Most of the default smilies already have a mapping, but you can override
# the mappings here, if you don't like some of them.
# The mapping syntax is: emoji_name: 'smiley_in_phpbb'
# Or map multiple smilies to one Emoji: emoji_name: ['smiley1', 'smiley2']
emojis:
# here are two example mappings...
smiley: [':D', ':-D', ':grin:']
heart: ':love:'
# Map custom profile fields from phpBB to custom user fields in Discourse (works for phpBB 3.1+)
#
# custom_fields:
# - phpbb_field_name: "company_name"
# discourse_field_name: "Company"
# - phpbb_field_name: "facebook"
# discourse_field_name: "Facebook"
custom_fields: []
ユーザー名とパスワードがありません。