Enhancement request to phpBB3 import script

In phpBB, it’s possible to add comments to uploaded attachments:

These then appear under the image in the post:


It would be useful if the phpBB3 import script could take these comments and assign them as alt text to the image they are paired with, which would then appear as you hover over the image in Discourse.

Thanks
Dan

2 Likes

Ah! Since I know nothing about Ruby on Rails - and, I’m requesting an enhancement to the phpBB import script - I’d like to request an additional enhancement as described here. It would be useful if, when the script reports a date/time error with a post, that it also reports the phpBB post_id for debugging purposes.

Thanks
Dan

1 Like

It’s not immediately clear how to go about doing what you ask, but I spent a few minutes and there isn’t a very satisfactory solution that seems feasible.

There’s nowhere in the upload record for the caption, and I don’t see an obvious way to go backward from the Upload. . . a possibility might be to put the comment in as the filename and then somehow later pull that back out as the caption. Yeah. That’s about the best you could do, encode that caption as the filename, which would make it show up on mouseover and such. If you wanted, you could then do something else, like get filenames that include a caption and then stick that into the html somehow.

1 Like

Admittedly, I know nothing about RoR, or even about postgres. But, when you markup an image with alt text, it’s stored in the postgres database in association with that image. What is it about the import script, that prevents that assignment? Certainly, the comment is accessible in MySQL.

1 Like

Looks tricky, but you may have success by modifying this method here:

Instead of this:

text.gsub!(attachment_regexp) do
        index = $1.to_i
        real_filename = $2
        unreferenced_attachments[index] = nil
        attachments.fetch(index, real_filename)
end

You would like something like this:

text.gsub!(attachment_regexp) do
        index = $1.to_i
        description = $2.strip
        unreferenced_attachments[index] = nil

        url = attachments.fetch(index, description)

        "![#{description}](#{url})"
end

This is an untested example just to show you where it needs to be modified. I can be wrong.

If I have time Tomorrow I may open a PR with a real solution. :grinning_face_with_smiling_eyes:

5 Likes

Thank you! Do you want to qualify the assignment based on MIME type? (I was unable to attach a phpBB comment to a .mp4; while I was able to a .gif, it did not appear on hover.)

1 Like

This could be useful, but I worked on a new way of adding the comment directly to the post’s raw. I believe it’s safer that way to handle all types of files.

Would you be able to test these changes with your dataset? I tested locally but would love your feedback before moving forward with a PR.

3 Likes

I’d be happy to test, but… Do I have to purge my test environment and repeat? Claude.ai walked my through the installation process, I’m a docker Newbie - and even so, there was a lot of errors along the way.

If you can outline a way for me to readily test, I’d be happy to give it a go.

1 Like

Nice work! I poked at the code and couldn’t find that.

Yes. You’ll need to wipe the database and run again. The importer skips already-imported data, so you’ll need to re-import everything to try it out. Looks like it should work, though!

OK - well, the attachments are still in place, as is the MySQL database. It took several hours to run, but I’ll have Claude walk me through it and report back.

Sure, I can help you. No need to change your installation. The easy way:

  1. Take a backup of your site and store it safely. This will protect you from losing your work.
  2. Reset your site:
# Enter the site’s container
cd /var/discourse
./launcher enter <your-container-name>

# Reset database
bundle exec rake db:drop
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:seed

# Exit the container
exit

# Rebuild the container just to be sure everything is in place
./launcher rebuild <your-container-name>
  1. Modify the files with the new code. You can use a cli text editor or open your container using ssh in your favorite text editor.
  2. Setup the settings.yml and run the importer again.

To get back to your previous state, you simply restore the backup you took at the beginning:

./launcher enter <your-container-name>
discourse enable restore
discourse restore <your-backup-filename>
4 Likes

Oh yeah! While we’re at it, is it easy enough to modify the script to report the phpBB post_id that’s being processed, when the date/time issue is reported?

2 Likes

Seems simple enough! I will give it a go as soon as Rosie :dog: takes me for my walk.

2 Likes

I’m adding it here using the existing gsub:

But thank you for taking a look, this made me realize I didn’t considered the unreferenced attachments that phpbb also has:

2 Likes

OK, backup is underway. I expect that could take a while…

Do I need to edit? Can’t I just do a docker cp into the script path(s) of the files in your git repo?

1 Like

That works too. Alternatively you can set the container.yml to use my repo and branch and rebuild.

2 Likes

Well, that didn’t go well.

reset_log.txt (16.6 KB)

1 Like

I think you may need to run the commands as the discourse user:

su discourse

or

su discourse -c “bundle exec rake db:drop”
1 Like

Oops. Newbie mistake, didn’t mean to close the thread - just to acknowledge, that seems to have solved that particular problem.

“Seems to.” Still waiting for the db:drop to complete. Onward…

1 Like

Still no love.

reset_log2.txt (1.7 KB)