CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Bulk Deleting Events?
Pages: [1]

Author Topic: Bulk Deleting Events?  (Read 1012 times)

marqpdx

  • I post occasionally
  • **
  • Posts: 58
  • Karma: 2
Bulk Deleting Events?
February 10, 2010, 03:35:03 pm
Hi,

Is there any way to bulk delete events?

If i were to use SQL in the database, which tables would i need to deal with?

Thanks,
m

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Bulk Deleting Events?
February 10, 2010, 04:39:50 pm

no, but this has come up in the recent past, so might make a good community contrib

the tables to check are:

civicrm_event
civicrm_participant
civicrm_option_group / value (for the amounts)
civicrm_price_* (if using price set)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

marqpdx

  • I post occasionally
  • **
  • Posts: 58
  • Karma: 2
Re: Bulk Deleting Events?
February 11, 2010, 12:01:48 pm
Thanks Lobo,
I found an API call that seems pretty tidy. I don't have time to get a module all rigged up, but here's the money code, in case anyone can use it.

Code: [Select]
/* This functions uses the CiviCRM API to delete multiple events. */
function delete_multiple_events() {
  if (!module_exists('civicrm')) {
    echo 'no CiviCRM found.';
    return FALSE;
  }
  civicrm_initialize(TRUE);
  require_once 'api/v2/Event.php';
  require_once 'CRM/Core/DAO.php';
 
  /* This is where you choose your range of events to delete */
  /* !!CHANGE FOR YOUR OWN SITUATION!! */
  $select1 = "SELECT id from civicrm_event WHERE `start_date` < '2001-12-12' ";
  $params1 = array( );

  /* Run that query against Civi DB */
  $dao1 =& CRM_Core_DAO::executeQuery( $select1, $params1 );
  while ( $dao1->fetch( ) ) {
    //deal with each found row
    echo 'start 1 row processing' . '<br/>';
    echo 'event id to delete: ' . $dao1->id . '<br/>';
    set_time_limit(5);
    $params = array(
      'event_id' => $dao1->id
    );
    /* Civi API call, also deletes participants and options, i believe */
    $result =& civicrm_event_delete($params);
    if ( civicrm_error( $result )) {
      return $result['error_message'];
    } else {
      print_r($result);
    }   
  }
}


Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Bulk Deleting Events?

This forum was archived on 2017-11-26.