MichaelBelgium / mybb_to_flarum

A Flarum extension to convert a mybb forum to a fresh flarum install
MIT License
26 stars 15 forks source link

Fix user avatar migration #16

Closed Vaalyn closed 5 years ago

Vaalyn commented 5 years ago

The migration of user avatars is not working correctly due to the path of the avatar containing a . at the beginning.

This is the path of an avatar in myBB: ./uploads/avatars/avatar_1.png?dateline=1419957458. When that is added to the mybb_path this would look like this: /var/www/forum./uploads/avatars/avatar_1.png and the file_exists($fullpath) will fail. By checking for the . and removing it if necessary this is fixed.

MichaelBelgium commented 5 years ago

It's not really because the dot, it is due no slash at the end in the when the user inputs the path, in this case: /var/www/forum, it would be fixed if you did /var/www/forum/ but yeah there's no validation on that.

If you would edit your PR so that it adds a slash at the end if there isn't, I would merge it! In the javascript function onsubmitu could add it.

Vaalyn commented 5 years ago

@MichaelBelgium Thanks for the correction. I've edited the PR to check for this on the server side.

MichaelBelgium commented 5 years ago

Actually, can you do it clientside, in javascript? And compile with npm? So then u dont need to check anymore serverside, and it will be saved the right way with a slash at the end in the flarum settings table.

Vaalyn commented 5 years ago

@MichaelBelgium I've moved it to the client side but I can't build it with webpack. I don't have that installed on my web server.

Also I've added a fix for the issue I mentioned in #17. I hope that it's okay to combine these 2 things in one PR.

MichaelBelgium commented 5 years ago

@Vaalyn Alright, no problem. I'll build it after the merge then! And yeah I'm surprised I forgot to assign the user id to the mybb user id ...

EDIT: and thank you!

Vaalyn commented 5 years ago

@MichaelBelgium I've also encountered a problem with the migration that is not a bug in this extension but more something that flarum doesn't handle by default I think. When a post in myBB is migrated to flarum but that post is from an unregistered user then the migration will fail because user id 0 does not exists. Do you have an idea how that could be handled?

MichaelBelgium commented 5 years ago

@Vaalyn Mhmm so the post from mybb is made by a guest? Thats actually possible in MyBB? And the user id equals 0 as the author?

You could maybe create a new user on your mybb installation named "Guest" so it has a valid user id (not zero) and then update all mybb posts/threads with author id 0 to that new user id. Afterwards migrate and it should be fine I assume

Vaalyn commented 5 years ago

@MichaelBelgium Yep, that's possible and yep the id is just 0 in myBB and I think that posts from users that were deleted also get set to 0. This may be something that the extension could take care of since deleting users is a lot more common than guest users posting something.

MichaelBelgium commented 5 years ago

Then we should find out how Flarum handles deleting a user, which id it generates/updates everything when removing a user that has posts etc

Vaalyn commented 5 years ago

@MichaelBelgium Discussions and Posts will be set to user_id NULL when deleting a user in Flarum. The forum displays the posts/discussions as created by [deleted] on the page then. So if the user_id from myBB is 0 or does not exist in Flarum the user_id of posts / discussions need to be set to NULL.