Skip to Content Skip to Menu

🐰 Happy Easter! Great Savings on Professional and Developer Memberships! Get 20% off now with code EASTER-2026!

Auto delete of past events

1 day 17 hours ago #343627 by m.o.skirde
Auto delete of past events was created by m.o.skirde
Hi Kyle,

is there a possibility of auto delete past events in GroupJive? And also the corresponding Activity Stream Items?

I only found an auto delete for entries of deleted users in the settings.

How can I achieve this?

Thx in advance, MO

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 50297
  • Thanks: 8610
  • Karma: 1470
1 day 9 hours ago #343632 by krileon
Replied by krileon on topic Auto delete of past events
Deleting an event should delete the activity automatically as long as it's done through the object and not just a database query. As for automating this it'd depend on when you want this to happen exactly. Do you want this to check for expired events on a schedule (e.g. every day check for expired and delete) or check if a user has expired events when they login for example?


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.

17 hours 10 minutes ago #343638 by m.o.skirde
Replied by m.o.skirde on topic Auto delete of past events
Hi Kyle, an every day check for expired and delete would be great.
Sunny regards, MO

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 50297
  • Thanks: 8610
  • Karma: 1470
9 hours 7 minutes ago #343641 by krileon
Replied by krileon on topic Auto delete of past events
Ok, the below auto action will delete all expired events. This should also delete their activity since it's doing so from their objects. It takes the end date of the event, or the start date if it doesn't have one, and adds 24 hours to it then checks if the current date is greater than that. If it is then it's considered expired.

Global
Triggers: None
Type: Code
User: Automatic
Access: Everybody
Action
Method: PHP
Code:
Code:
global $_CB_database; $query = "SELECT *" . " FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_events' ) . " WHERE ( ( " . $_CB_database->NameQuote( 'end' ) . " = " . $_CB_database->Quote( '0000-00-00 00:00:00' ) . " OR " . $_CB_database->NameQuote( 'end' ) . " IS NULL ) AND DATE_ADD( " . $_CB_database->NameQuote( 'start' ) . ", INTERVAL 24 HOUR ) < NOW() )" . " OR ( ( " . $_CB_database->NameQuote( 'end' ) . " != " . $_CB_database->Quote( '0000-00-00 00:00:00' ) . " AND " . $_CB_database->NameQuote( 'end' ) . " IS NOT NULL ) AND DATE_ADD( " . $_CB_database->NameQuote( 'end' ) . ", INTERVAL 24 HOUR ) < NOW() )"; $_CB_database->setQuery( $query ); foreach ( $_CB_database->loadObjectList( null, '\CB\Plugin\GroupJiveEvents\Table\EventTable', [ $_CB_database ] ) as $event ) { $event->delete(); }

Now comes the part of how you want to run this. You can use a Joomla scheduled task to run it on regular intervals as CB Auto Actions includes a scheduled task for running auto actions or you can setup CRON to access the auto action directly. If you plan to use a Joomla scheduled task then please be sure to set "Allow Direct Access" to "No" under the Global tab otherwise leave it as "Yes" and schedule a wget CRON against the "Internal Action URL".

Also since this is a mass delete operation please be sure you make a backup and test carefully.


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.

Moderators: beatnantkrileon
Powered by Kunena Forum