Kunena 7.0.5 & Kunena 6.4.11 – Security Updates Released

The Kunena team has announce the arrival of Kunena 7.0.5 [K 7.0.5] in stable which is now available for download as a native Joomla extension for J! 5.4.x/6.0.x. This version addresses most of the issues that were discovered in K 6.2 / K 6.3 / K 6.4 and issues discovered during the last development stages of K 7.0.

The Kunena team is also pleased to announce the eleventh version of Kunena 6.4, a native Joomla extension for Joomla! 5.0, 5.1, 5.2, 5.3, 5.4 and 6.0.

Question MYSQL Database Insertion

More
15 years 3 months ago - 15 years 3 months ago #84329 by pappabear
So, I've search around and I've seen all the posts asking what I want but with no resolution - but that's okay because I sort of know how to manipulate the database.

What I want is for a user to fill out a form, and have it inserted into the database. This is for a world of warcraft applicant. Ironically, the code works fine. The tables get inserted, the times are correct, even the thread subject shows up on the kunena category display...

but when I view the category, no topic. What's going on? Here's some snippets from my code:

edit: In addition, I've heard about the Kunena 1.6 api supposedly making this whole process easier, but after looking at the rather limited documentation and fishing around the lib-class files for hours, I didn't find what I was looking for. Hopefully someone can help
Code:
///////////////////////////////// //////CREATE TOPIC FOR POST////// ///////////////////////////////// $threadid = mysql_fetch_array(mysql_query("SELECT thread FROM nscms_kunena_messages ORDER BY id DESC LIMIT 1;")); $threadid = $threadid[thread]+1; $mysqlpost1 = mysql_query("INSERT INTO `nsguild_nsjs15`.`nscms_kunena_messages` ( `id` , `parent` , `thread` , `catid` , `name` , `userid` , `email` , `subject` , `time` , `ip` , `topic_emoticon` , `locked` , `hold` , `ordering` , `hits` , `moved` , `modified_by` , `modified_time` , `modified_reason` ) VALUES (NULL , '0', '".$threadid."' , '7' , '".$poster."' , '".$poster_id."', NULL , '".$title."', '".$time."' , NULL , '0' , '0' , '0' , '0' , '0', '0', NULL, NULL, NULL);"); if(!$mysqlpost1){echo("Failed: ".mysql_error(). "<br><br>");} ///////////////////////////////// ////PARSE POST INTO MESSAGES///// ///////////////////////////////// //get message id $tmesid = mysql_fetch_array(mysql_query("SELECT id FROM nsguild_nsjs15.nscms_kunena_messages WHERE subject = '$title'")); $mysqlpost2 = mysql_query("INSERT INTO nsguild_nsjs15.nscms_kunena_messages_text( `mesid` , `message` ) VALUES ('".$tmesid[id]."','".$post."');"); if(!$mysqlpost2){echo("Failed: ".mysql_error());} ///////////////////////////////// /////////UPDATE CATEGORY///////// ///////////////////////////////// $num = mysql_fetch_array(mysql_query("SELECT numTopics FROM `nsguild_nsjs15`.`nscms_kunena_messages` WHERE id = '7'")); $numTopics = $num[numTopics]+1; $num = mysql_fetch_array(mysql_query("SELECT numPosts FROM `nsguild_nsjs15`.`nscms_kunena_messages` WHERE id = '7'")); $numPosts = $num[numPosts]+1; $mysqlpost3 = mysql_query("UPDATE `nsguild_nsjs15`.`nscms_kunena_categories` SET numTopics='".$numTopics."', numPosts='".$numPosts"',time_last_msg='".$time."' WHERE `nscms_kunena_categories`.`id` =7;");
Last edit: 15 years 3 months ago by pappabear.

Please Log in or Create an account to join the conversation.

More
15 years 3 months ago #84345 by Matias
Replied by Matias on topic Re: MYSQL Database Insertion
Please look at how Kunena Discuss plugin does it (there's function to create topic and to post reply)..

In 2.0 creating a new topic will be even easier.

Please Log in or Create an account to join the conversation.

More
15 years 3 months ago #84358 by pappabear
This?
Code:
function createTopic($row, $catid, $subject) { require_once (KPATH_SITE . '/lib/kunena.posting.class.php'); $message = new CKunenaPosting ( $this->params->get ( 'topic_owner', $row->created_by ) ); $options = array(); $fields ['subject'] = $subject; switch ($this->params->get('bbcode')) { case 'full': $fields ['message'] = "[article=full]{$row->id}[/article]"; break; case 'intro': $fields ['message'] = "[article=intro]{$row->id}[/article]"; break; case 'link': $fields ['message'] = "[article=link]{$row->id}[/article]"; break; default: $fields ['message'] = "[article]{$row->id}[/article]"; } $fields ['time'] = JFactory::getDate(isset($row->publish_up) ? $row->publish_up : 'now')->toUnix(); $success = $message->post ( $catid, $fields, $options ); if ($success) { $newMessageId = $message->save (); } // Handle errors if (! $success || ! $newMessageId) { $errors = $message->getErrors (); foreach ( $errors as $field => $error ) { $this->_app->enqueueMessage ( $field . ': ' . $error, 'error' ); } return false; } // Keep a cross reference of Threads we create through this plugin $this->createReference ( $row, $newMessageId ); // We'll need to know about the new Thread id later... $this->debug ( __FUNCTION__ . "() end" ); return $newMessageId; }

Yes of course, except I really don't know much about how you handle the queries or exactly what your doing here. This just sends me on a wild goose chase to /lib/kunena.posting.class.php, which sends me on another goose chase to some other script. I honestly don't care how Kunena handles its data. It all goes back to the database right? So, I'm querying kunena_categories, kunena_messages and kunena_messages_text. Please take 30 seconds and read my script and tell me what I'm missing rather than sending me off to find the holy grail.

Unless kunena hardcodes it's messages somehow - I don't see a reason why it's not adding the topic to the category.

Please Log in or Create an account to join the conversation.

More
15 years 3 months ago #84361 by Matias
Replied by Matias on topic Re: MYSQL Database Insertion
Unless you're outside of Joomla (and PHP) I really do not recommend direct SQL queries. In Kunena 2.0 creating a topic will be much harder as there are a lot of tables that need to be updated.

Even in Kunena 1.6 you need to update other tables to make the topic to show up everywhere.

Your hack:

Do not use $threadid to guess which will be the next id.. Leave thread empty and get the real ID from the database + update message with the right value. And no, not like you're doing now -- there's a PHP function which returns you the last inserted ID.

2) You can do category update by SET numTopics=numTopics+1, numPosts=numPosts+1

3) You need to set also last post information into category table

4) You should also update kunena_users entry: posts=posts+1

Nothing magical in there.. Until you install K2.0, where posting a message will be almost impossible without using our API.

Please Log in or Create an account to join the conversation.

More
15 years 3 months ago - 15 years 3 months ago #84366 by pappabear
Ok, so you observed some sloppy coding on my part. I had split it all up because I was having issues earlier that are now resolved


Regardless, the actual issue was that the NEW message id has to MIRROR the new topic id, meaning if you have 4 topics, but 20 messages, the new topic id must be 21 to match the message id.

Anyway - that solved it. Thanks for taking the time anyway.
Last edit: 15 years 3 months ago by pappabear.

Please Log in or Create an account to join the conversation.

More
15 years 3 months ago #84380 by Matias
Replied by Matias on topic Re: MYSQL Database Insertion
Actually you save your message, get mysql_insert_id() ( php.net/manual/en/function.mysql-insert-id.php ) and update the message by SET thread=id.

Please Log in or Create an account to join the conversation.

Time to create page: 0.223 seconds