Skip to Content Skip to Menu

[SOLVED] SQL Query between plans

  • wjgadmin
  • wjgadmin
  • OFFLINE
  • Posts: 489
  • Thanks: 28
  • Karma: 4
5 years 11 months ago - 5 years 11 months ago #309300 by wjgadmin
[SOLVED] SQL Query between plans was created by wjgadmin
Hi,
The following SQL Action is used for each plan (only on activation) to generate an encrypted license key which is then used for external server licensing.

UPDATE `#__comprofiler` SET `field_name` = MD5( '[user_id]_[plan_id]_[subscription_id]_ENCRYPT' ) WHERE `id` = '[user_id]'

The issue is; if a user upgrades from one plan to another, the key will change due to their user_id, subscription_id changing so it generates a new license key.
My question; can you please advise if it is possible to generate a query that will do exactly what the above is doing, however NOT if a key (field_name) already exists, it would not make any change and the users license key would remain the same?

Basically I am trying to find a way to have CBSubs generate the license key and not change it if the user upgrades their plan to a different one. Thank you kindly in advance!
Last edit: 5 years 11 months ago by krileon. Reason: Added [SOLVED] tag to subject

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

  • krileon
  • krileon
  • OFFLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
5 years 11 months ago #309309 by krileon
Replied by krileon on topic SQL Query between plans
Add to the WHERE statement of your query to check that the field is empty. That should prevent it from changing when they update. Example as follows.

Code:
UPDATE `#__comprofiler` SET `field_name` = MD5( '[user_id]_[plan_id]_[subscription_id]_ENCRYPT' ) WHERE `id` = '[user_id]' AND ( `field_name` = '' OR `field_name` IS NULL )


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.

  • wjgadmin
  • wjgadmin
  • OFFLINE
  • Posts: 489
  • Thanks: 28
  • Karma: 4
5 years 11 months ago #309312 by wjgadmin
Replied by wjgadmin on topic SQL Query between plans
You rock Kyle, thank you!
The following user(s) said Thank You: krileon

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

Moderators: beatnantkrileon
Powered by Kunena Forum