Founder and Lead Developer of Macrotone Consulting Ltd.

Converting Joomla Forum from Discussions to Kunena

b2ap3 icon joomlaI recently looked at the possibility of converting from using the Discussions component to using Kunena.  I will not go into the reasons why this may or may not be required or whether it is a good or bad thing to do.

Looking on the web, for the best method, it was a topic that several others have looked into, but there were no solutions offered. We therefore post this information which others may find useful.

There is a ‘Kunena Importer’ but according to the Kunena documentation this doesn’t work with Kunena 2.0.x or above. We were thus left trying to see how difficult it would be. The following describes the mechanism we used to get our ‘old’ posts transferred over to Kunena 3.0.0. It is possibly not the most efficient but given that it is likely to be a ‘one-off’ conversion, performance is not the prime criteria.

To convert Discussions v1.6.1 to Kunena 3.0.0

We are assuming that the work would be performed ‘off line’ or on a development site running Joomla 2.5.11.

  1. Before we start it is a good idea to take a system backup, just in case.
  2. On your site download Kunena 2.0.4 (which was/is the latest 2.0.x version available) and install it.
  3. Download and install the Kunena Importer component and install it. [The docs say this does work with Kunena 2.0.4 but we still proceed. It was not the easiest component to install, but for a competent administrator it will not prove too much of a challenge.]
  4. Run the Kunena Importer, selecting the Discussions component as the source.
  5. Now we have transferred the information from Discussions, we can uninstall the Kunena Importer since we do not desire it anymore.
  6. Download and install the latest version of Kunena 3.0.0.
  7. At this stage it is probably a good idea to take another system backup.

Now we have the basic structure in our Kunena forum but there are several important pieces of information that are missing. We therefore open a database session using a SQL tool such as phpadmin and prepare to run a few SQL commands.

We next create a view, which is a convenience running one of the following SQL commands. Note that you have to change the table suffices as appropriate for your specific configuration.

-- The view makes it easy to view the information of the last post to a topic (or category).
CREATE VIEW v1 AS
SELECT m2.thread, m2.id, m2.catid, m2.subject, t2.message, m2.userid, m2.time, m2.name
FROM #__kunena_messages m2
LEFT JOIN #__kunena_messages_text t2 ON (m2.id = t2.mesid)
WHERE (m2.id, m2.thread) IN (SELECT max(id), thread FROM #__kunena_messages GROUP BY by thread);

We can now start populating the Kunena topics table by running following SQL:

INSERT IGNORE INTO #__kunena_topics
(id, category_id, subject,
first_post_message, first_post_id, first_post_userid, first_post_time, first_post_guest_name,
last_post_message, last_post_id, last_post_userid, last_post_time, last_post_guest_name)
SELECT m1.id, m1.catid, m1.subject, t1.message, m1.id, m1.userid, m1.time, m1.name,
       m2.message, m2.id, m2.userid, m2.time, m2.name
FROM #__kunena_messages AS m1
LEFT JOIN v1 AS m2 ON (m1.thread = m2.thread)
LEFT JOIN #__kunena_messages_text t1 ON (m1.id = t1.mesid)
WHERE m1.parent = 0 AND m1.thread = m1.id;

We now have the topic structure in place.

We now run the ‘Recount statistics’ within the Administrator Kunena Tools.

The following SQL will update the Kunena categories table with the correct number of posts.

UPDATE #__kunena_categories AS c
SET numTopics = (SELECT count(*) FROM #__kunena_messages WHERE parent=0 AND catid = c.id GROUP BY catid);

We now choose the edit the Kunena categories in the Back end to populate aliases etc. It is only necessary to open the editor and save to get the alias populated automatically. Note that if you have sub categories of identical names in different sections you have to slightly modify the category name, perhaps by adding a suffix.

The next step is to populate the last post time, last_topic_id and last_post_id for the various Kunena categories:

(This SQL is not particularly pretty but it works and is a one off. We could produce another view for the subquery if we desired but it is a little academic)

UPDATE #__kunena_categories AS c
SET last_topic_id = (SELECT m.thread FROM #__kunena_messages AS m
WHERE id = (SELECT MAX(id) FROM #__kunena_messages AS m2 WHERE catid = c.id GROUP BY catid)),
last_post_id= (SELECT m.id FROM #__kunena_messages AS m
WHERE id = (SELECT MAX(id) FROM #__kunena_messages AS m2 WHERE catid = c.id  GROUP BY catid)),
last_post_time= (SELECT m.time FROM #__kunena_messages AS m
WHERE id = (SELECT MAX(id) FROM #__kunena_messages AS m2 WHERE catid = c.id  GROUP BY catid));

The next step populates the number of replies in the Kunena categories:

UPDATE #__kunena_categories AS c
SET hits = (SELECT COUNT(*) FROM #__kunena_messages WHERE parent != 0 AND catid = c.id GROUP BY catid);

Rerun the ‘Recount statistics’ within the Administrator Kunena Tools.

We can also now remove our view (v1) that we created above.

That is virtually all the work complete. Certain field are not filled in, notably the number of hits etc., but this is mainly because the information was not present in the original Discussions component to start with.

We are now in a situation where we can prepare an export of the main Kunena tables ready to load into our ‘live’ site and after satisfying ourselves that it is configured correctly consider making it available to our users.

Reclaiming a disk'€™s recover partition space.
Implementing Smart Search
 

By accepting you will be accessing a service provided by a third-party external to https://macrotoneconsulting.co.uk/

Go To Top

The Macrotone Consulting Web site would like to use cookies to store information on your computer, to improve our website. Cookies used for the essential operation of the site have already been set. To find out more about the cookies we use and how to delete them, see our Privacy Policy.

I accept cookies from this site.