Skip to Content Skip to Menu

🌟Discover the Joomla AI Plugin that wrote its own story! - CB Editor Assistant 1.1now for Joomla 3, 4 & 5!
✍️ 5-Day Free Trial, then 🎯 save up to 30% with our 🛍️ Intro Offer (First 50 users, ends Dec. 25th)
🌲 Merry Christmas! Great savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2024!

Auto action code not firing?

  • rbuelund
  • rbuelund
  • OFFLINE
  • Posts: 565
  • Thanks: 40
  • Karma: 4
4 months 3 weeks ago #338773 by rbuelund
Auto action code not firing? was created by rbuelund
I have a CB auto action which should fire onCPayAfterMailerMessageSent when the condition_ Subscription -> Action user has the plan "Waitinglist" and the state is Expired. The auto action usage count is still = 0, but the mailer has fired 494 times??
The condition for the mailer is set to Subscription -> Action user has the plan "Waitinglist" and the state is Expired - so exactly the same as the auto action - the Mailer fires but the Auto action does not ??

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48616
  • Thanks: 8302
  • Karma: 1446
4 months 2 weeks ago #338778 by krileon
Replied by krileon on topic Auto action code not firing?
Usage count does not increment unless you've usage limits on the auto action. It's not a reliable means of determining if your auto action has executed or not. onCPayAfterMailerMessageSent is fired anytime an CBSubs Mailer email is sent. That's probably not the most ideal location to be doing whatever you're trying to do. Can you better describe what you need your auto action to do?


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 or Create an account to join the conversation.

  • rbuelund
  • rbuelund
  • OFFLINE
  • Posts: 565
  • Thanks: 40
  • Karma: 4
4 months 2 weeks ago - 4 months 2 weeks ago #338779 by rbuelund
Replied by rbuelund on topic Auto action code not firing?
I am triggering code for sending an SMS 20 days after subscription has run out. You told me to use this trigger ( www.joomlapolis.com/forum/professional-members-support/245761-cbsubs-triggering-php-code ). I trusted that the counter had to go up, so then maybe it is the code that has a problem.
Last edit: 4 months 2 weeks ago by rbuelund.

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

  • rbuelund
  • rbuelund
  • OFFLINE
  • Posts: 565
  • Thanks: 40
  • Karma: 4
4 months 2 weeks ago - 4 months 2 weeks ago #338780 by rbuelund
Replied by rbuelund on topic Auto action code not firing?
I am using this as the code to get info from db in the auto action:

// Check automailer id
if ( (int) '[var2]' !== 105) {return};

// Get a db connection.
$db = JFactory::getDbo();

//Get the users e-mail from user table
$query = $db->getQuery(true);
$query->select($db->quoteName(array('id', 'email')));
$query->from($db->quoteName('#__users'));
$query->where($db->quoteName('id') . ' LIKE ' . $db->quote('[var1]'));
// Reset the query using our newly populated query object.
$db->setQuery($query);
$emailresult = $db->loadAssoc();

// Select user record from the comprofiler table.
$query = $db->getQuery(true);
$query->select($db->quoteName(array('user_id', 'firstname', 'cb_phone_1','cb_phone_2','cb_waitingnumber')));
$query->from($db->quoteName('#__comprofiler'));
$query->where($db->quoteName('user_id') . ' LIKE ' . $db->quote('[var1]'));

// Reset the query using our newly populated query object.
$db->setQuery($query);
$result = $db->loadAssoc();
Last edit: 4 months 2 weeks ago by rbuelund.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48616
  • Thanks: 8302
  • Karma: 1446
4 months 2 weeks ago #338782 by krileon
Replied by krileon on topic Auto action code not firing?
That trigger doesn't contain a user object, but it contains a user id. So CB Auto Actions needs to be told what variable is the user id more specifically. That might be where your issue is. The below should get you started.

Global
Triggers: onCPayAfterMailerMessageSent
Type: Code
User: Manually
User Variable: Variable 1
Access: Everybody
Conditions
Field: Custom > Value
Custom Value: [var2]
Operator: Equal To
Value: 105

That should use variable 1 as the user object as variable 1 in that trigger is the user id, which will cause CB Auto Actions to build a user object from that id. I've then moved your PHP condition for the mailer id into the auto action conditions so it can exit early properly.

From there I can't really suggest whether your PHP is working or not, but you won't need to query for the user anymore at least as you can just use substitutions normally now as you've the proper user object already sent to your PHP as $user. So you'd basically be able to replace all your queries with just the following.

FROM
Code:
//Get the users e-mail from user table $query = $db->getQuery(true); $query->select($db->quoteName(array('id', 'email'))); $query->from($db->quoteName('#__users')); $query->where($db->quoteName('id') . ' LIKE ' . $db->quote('[var1]')); // Reset the query using our newly populated query object. $db->setQuery($query); $emailresult = $db->loadAssoc();
TO
Code:
$emailresult = '[email]';

FROM
Code:
// Select user record from the comprofiler table. $query = $db->getQuery(true); $query->select($db->quoteName(array('user_id', 'firstname', 'cb_phone_1','cb_phone_2','cb_waitingnumber'))); $query->from($db->quoteName('#__comprofiler')); $query->where($db->quoteName('user_id') . ' LIKE ' . $db->quote('[var1]')); // Reset the query using our newly populated query object. $db->setQuery($query); $result = $db->loadAssoc();
TO
Code:
$result = $user;

Your code doesn't seam to do anything except query for email address and _comprofiler row data though.


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 or Create an account to join the conversation.

  • rbuelund
  • rbuelund
  • OFFLINE
  • Posts: 565
  • Thanks: 40
  • Karma: 4
4 months 2 weeks ago #338788 by rbuelund
Replied by rbuelund on topic Auto action code not firing?
I did not attach the full code, but with your modifications it looks like this and I also made the changes on Global and Conditions:

// User object
$result = $user;

if($result<>'' || $result<>''){ //Only if number has been entered in phone field
$mode = 'send';
if ($result<>'') {$phone[] = "45" . $result;}
if ($result<>'') {$phone[] = "45" . $result;}

$message = "Hej\n\nDu har stadig ikke betalt dit ventelistegebyr! Du vil blive slettet fra ventelisten inden 5 dage, hvis du ikke betaler! For hjælp skriv til vente@xxxxxx.dk, med dit ventelistenummer (" . $result . ").
\n\nDu kan IKKE svare på denne SMS!";

//set POST variables
$url = ' api.xxxxxx.dk/v2/send ';
//$message = rawurlencode($message);
$fields = array(
        'to' =>  $phone,
    'message' => $message,
    'from' => 'xxxxxx'
    );

$fields_string = $payload = json_encode($fields);
/*
$fields_string="";
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
*/




//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
$headers = array(
"Accept: application/json",
"Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Content-Type: application/json",
);
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_PORT, $serverport);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
                    
//execute post
$response = curl_exec($ch);
//close connection
curl_close($ch);
mail("mail@xxxxxx.dk","Mail fra xxxxxxx - husk at slå fra igen !!",$response);

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

Moderators: beatnantkrileon
Powered by Kunena Forum