Save to another table

1 year 8 months ago - 1 year 8 months ago #330202 by activha
Save to another table was created by activha
Hello
I have a question concerning CB Autoaction and CB activity
As you advised some months ago we use this code in an anautoaction to save data in CB activity :
//todo find group for any activation
//default cat to pro 0 group 55 and event to negopack 26 group 26
$v_cat = $user->cb_activ_cats != 0 ? $user->cb_activ_cats : 0;
$v_event = $user->cb_marketevents > 0 ? $user->cb_marketevents : 26;
$v_group = $v_event != 26 ? 56 : 55;
$variables['var3']->params()->set( 'activ', htmlspecialchars($input->getString( 'activ' )) );
$locationId = '1';
$locationPlace = htmlspecialchars($input->getString( 'si_place' ));
$lat = htmlspecialchars($input->getString( 'si_lat' ));
$long = htmlspecialchars($input->getString( 'si_long' ));
$locationAddress = $lat . ',' . $long;
$newLocation =	array('id' => $locationId,'place' => ( $locationId ? $locationPlace : '' ),'address' =>	( $locationId ? $locationAddress : '' ));
$variables['var3']->params()->set( 'location', $newLocation );
$variables['var3']->params()->set( 'data-company-id', htmlspecialchars($input->getString( 'si_company_id' )) );
$variables['var3']->params()->set( 'category', $v_cat  );
$variables['var3']->params()->set( 'event',$v_event);
$variables['var3']->set( 'asset', 'activha.group.' . $v_group . '.event.' . $v_event . '.activation.[var3_user_id]' );

The code works fine but we would like to save the data si_company_id to another table than #_comprofiler_plugin_activity for our needs, say the table #__activations in the field company_number

The issue is that whatever php code we insert in the above auto action in a new line, this code does not save the data.
we tried in a new php line :
$company_number = 'test';
$enrich_company = 'test';
$values = array($db->quote($company_number),$db->quote($enrich_company) );
            $query->insert($db->quoteName('#__activations'));
            $query->columns($db->quoteName($columns));
            $query->values(implode(',', $values));
            $db->setQuery($query);
            $db->execute();
or
$si_company_id = 'test';
$enrich_datas = 'test';
$query = "INSERT INTO #__activations(company_number, enrich_company) VALUES(\"".$db->quote($si_company_id)."\",\"".$db->quote($enrich_datas)."\")";
       $db->setQuery( $query);
       $db->Query();

But both codes do nothing nor return any error.

Is there a specific way with CB autoaction to save to another table ?

Please Log in to join the conversation.

1 year 8 months ago #330203 by krileon
Replied by krileon on topic Save to another table
I cannot help you with custom coding. There is nothing specific in CB Auto Actions to prevent saving to external databases. Most likely your code is not valid if it's not running. You're calling $db, but it's not defined anywhere in your code. Same with $query.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

1 year 8 months ago #330204 by activha
Replied by activha on topic Save to another table
yes of course we defined it but no results :
$db = JFactory::getDBO();

$si_company_id = 'test';
$enrich_datas = 'test';
$query = "SELECT `company_number` FROM #__activations where `company_number` = ".$si_company_id;
$db->setQuery( $query );
$resultRow = $db->loadResult();
 if (!$resultRow) {
       $query = "INSERT INTO #__activations(`company_number`, `enrich_company`) VALUES(\"".$db->quote($si_company_id)."\",\"".$db->quote($enrich_datas)."\")";
       $db->setQuery( $query);
       $db->Query();
else {
       $query = "UPDATE #__activations SET `enrich_company` = \"".$db->quote($enrich_datas)."\" where `company_number` =\"".$db->quote($si_company_id)."\" ";
       $db->setQuery( $query);
       $db->Query();
  }

This code is standard to joomla so what did we miss with CB ?

Please Log in to join the conversation.

1 year 8 months ago #330205 by krileon
Replied by krileon on topic Save to another table
Again, nothing in CB is going to prevent it from running. Be sure your code is completely functional before running it through CB Auto Actions. You can also try turning on debug mode, but it's only going to catch top level fatal errors as it's not meant to debug your custom code. I would start by making sure your queries work by testing them manually in phpmyadmin.

It seams like you can also replace your custom PHP with a Query action and just directly doing your query there by consolidating your INSERT/UPDATE if statement into an ON DUPLICATE query as described below.

dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.190 seconds

Facebook Twitter LinkedIn