|
|
| Line 331: |
Line 331: |
|
| |
|
|
| |
|
| ===Customized SQL query to get all Kunena users===
| | The original Discourse's Kunena migration script has been customized to be more aligned with the specific migration needs of the french Dolibarr forum. |
| | It can be retreived here : https://gist.github.com/jtraulle/a8ed0244a2a77498f29ac32fd2bc0f65 |
|
| |
|
| Some old Kunena user that does not have a Joomla! account was not retrieved by the import script.
| | Main differences with original script : |
|
| |
|
| This SQL query use UNION to get the missing users directly from the <code>kunena_messages</code> table.
| | ===Import Users=== |
| | * Retreive old "anonymous" Kunena users that does not have a Joomla! account |
| | * Retreive profile info |
| | * Retreive avatars |
|
| |
|
| | === Import Categories=== |
| | * Import categories hierarchy ignoring main groups (Discourse only has two levels hierarchy) |
| | * Categories are imported preserving the original order |
| | * Categories with no posts (and no subcategories) are ignored/skipped |
|
| |
|
| For use in https://github.com/discourse/discourse/blob/master/script/import_scripts/kunena3.rb script.
| | ===Import Posts=== |
| | * Multiple enhancements on posts text content |
| | ** Escape some commonly used chars (>, -, +, *) to not be wrongly parsed as Markdown |
| | ** Block quote |
| | *** add a line break after [quote] BBCode tag if there is none |
| | *** Replacing old posts reference in quote blocks by new ones |
| | *** Removing remaining posts references in quote blocks for posts that does not exists anymore |
| | ** Unordered lists |
| | *** Break line after [ul] only for lines that starts by [ul] and followed by [li] tag on the same line |
| | ** Strike support |
| | *** Replace [strike][/strike] BBCode tag by <s></s> HTML equivalent for markdown parser |
| | ** Emojis |
| | *** Convert some emojis shortcuts to preserve custom emojis previously used |
|
| |
|
| <source lang="SQL">
| | * Thank you |
| | ** Kunena post's "thank you" are imported as Discourse post's likes (added) |
|
| |
|
| --- Main Joomla! users table
| | ===Import Attachments=== |
| --- (original query in script)
| |
| SELECT
| |
| id,
| |
| username,
| |
| email,
| |
| registerDate,
| |
| signature,
| |
| location,
| |
| websiteurl,
| |
| birthdate,
| |
| avatar,
| |
| moderator
| |
| FROM gvrsi_users
| |
| INNER JOIN gvrsi_kunena_users ON gvrsi_kunena_users.userid = gvrsi_users.id
| |
|
| |
|
| UNION
| | Attachments to import into the new Discourse instance should be present to the local filesystem before running the task (plan about 400M disk space). |
|
| |
|
| --- Query to fetch users not present in main Joomla! table that have an email address defined
| |
| --- Registration date does not exist so we put that most old date (first posted message)
| |
| SELECT
| |
| userid,
| |
| name,
| |
| SUBSTRING_INDEX(GROUP_CONCAT(email), ',',1) AS email,
| |
| FROM_UNIXTIME(MIN(time)) AS registerDate,
| |
| NULL AS signature,
| |
| NULL AS location,
| |
| NULL AS website,
| |
| NULL AS birthdate,
| |
| NULL AS avatar,
| |
| 0 AS moderator
| |
| FROM gvrsi_kunena_messages
| |
| WHERE userid NOT IN(SELECT id FROM gvrsi_users)
| |
| AND email IS NOT NULL AND email <> ''
| |
| GROUP BY userid, name
| |
|
| |
|
| UNION
| | To download attachments from previous forum, start by export the URLs from the Kunena database. |
|
| |
|
| --- Query to fetch users not present in main Joomla! table that does not have an email address defined
| | <source lang="SQL"> |
| --- Email address is set to no_email to allow Discourse account creation
| | SELECT CONCAT('https://www.dolibarr.fr/', folder, '/', filename) AS url FROM gvrsi_kunena_attachments ORDER BY id; |
| --- Registration date does not exist so we put that most old date (first posted message)
| |
| SELECT
| |
| userid,
| |
| name,
| |
| 'no_email' AS email,
| |
| FROM_UNIXTIME(MIN(time)) AS registerDate,
| |
| NULL AS signature,
| |
| NULL AS location,
| |
| NULL AS website,
| |
| NULL AS birthdate,
| |
| NULL AS avatar,
| |
| 0 AS moderator
| |
| FROM gvrsi_kunena_messages | |
| WHERE userid NOT IN(SELECT id FROM gvrsi_users)
| |
| AND (email IS NULL OR email = '')
| |
| AND userid NOT IN(
| |
| SELECT DISTINCT userid
| |
| FROM gvrsi_kunena_messages
| |
| WHERE userid NOT IN(SELECT id FROM gvrsi_users)
| |
| AND email IS NOT NULL AND email <> ''
| |
| GROUP BY userid
| |
| )
| |
| GROUP BY userid, name
| |
| ORDER BY id; | |
| </source> | | </source> |
|
| |
|
| ===PostgreSQL query to fix quote blocks===
| | Put all the URLs into a text file (for example <code>uploads.txt</code>). |
| | |
| After migrating, some quote blocks does not show properly.
| |
|
| |
|
| That is because we must have a blank line after the [quote] BBCode tag.
| | Next, use <code>wget</code> to download all attachment preserving the directory structure (yuuup, file names of multiple distinct attachments can be the same ...) |
|
| |
|
| <source lang="bash"> | | <source lang="bash"> |
| ./launcher enter app | | wget --no-host-directories --force-directories --input-file=uploads.txt |
| sudo -u postgres psql discourse
| |
| </source> | | </source> |
| <source lang="SQL">
| |
| UPDATE posts
| |
| SET raw = regexp_replace(posts.raw, '\[(/)?quote([^]]*)]', E'\n[\\1quote\\2]\n', 'g')
| |
| FROM posts_with_bbcode_quotes
| |
| WHERE posts.id IN (posts_with_bbcode_quotes.targeted_posts)
| |
| RETURNING raw;
| |
|
| |
| UPDATE posts set raw = regexp_replace(raw, '(\[quote=".*").*(])', '\1\2', 'g')';
| |
| </source>
| |
|
| |
| We use the <code>rebake</code> command to rebake HTML formatted texts from '''raw''' column into '''cooked''' column.
| |
|
| |
| <source lang="bash">
| |
| rake posts:rebake
| |
| </source>
| |
|
| |
|
| |
| ===PostgreSQL query to fix custom smileys===
| |
|
| |
| ''To come soon''
| |
|
| |
|
| ==Tentative design== | | ==Tentative design== |