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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • civicrm_event_delete deletes too many events
Pages: [1]

Author Topic: civicrm_event_delete deletes too many events  (Read 2285 times)

Matt2000

  • I post frequently
  • ***
  • Posts: 288
  • Karma: 27
    • http://www.ninjitsuweb.com
civicrm_event_delete deletes too many events
May 10, 2008, 11:44:48 am
civicrm_event_delete($params) seems to trigger an error no mater what is fed in $params, and it deletes more than it's told to.

Can anyone else confirm this?

Note that I am working with an UNmodified version of Event.php (regarding my patch at http://forum.civicrm.org/index.php/topic,3325.0.html ).

Thanks.
Drupal/CiviCRM micro-blogging http://twitter.com/matt2000

Ninjitsu Web Development http://www.NinjitsuWeb.com/

Matt2000

  • I post frequently
  • ***
  • Posts: 288
  • Karma: 27
    • http://www.ninjitsuweb.com
Re: civicrm_event_delete deletes too many events
May 12, 2008, 09:35:20 pm
OK, this may not be an API issue only, because I just deleted one event from the UI, and *ALL* of my events were deleted.

However, all the events were created by the API, but they definitely had different event IDs, which should be the only factor passed to the delete function?

I also had some tricks going where multiple records in the events table were sharing the same record in other tables (i.e., location, tell-a-friend). So I wonder if this is some kind of MySQL cascading delete issue? I.e., I deleted the one event, but it caused items in other tables to be deleted, which were shared by other events, which were then, therefore, deleted.

This is difficult to verify on the sandbox, since there are so many events there, and no API access.

Drupal/CiviCRM micro-blogging http://twitter.com/matt2000

Ninjitsu Web Development http://www.NinjitsuWeb.com/

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: civicrm_event_delete deletes too many events
May 13, 2008, 07:18:36 am
By default in Event Selector, CiviCRM displays current and upcoming events. So can you check your database if civicrm_event table is empty.

Quote
OK, this may not be an API issue only, because I just deleted one event from the UI, and *ALL* of my events were deleted.
Can you replicate this on http://demo.civicrm.org

kurund
Found this reply helpful? Support CiviCRM

Matt2000

  • I post frequently
  • ***
  • Posts: 288
  • Karma: 27
    • http://www.ninjitsuweb.com
Re: civicrm_event_delete deletes too many events
May 13, 2008, 11:05:59 am
Yes, the _event table is empty.

As I said, I cannot replicate on the sandbox/demo. But I can't recreate the exact conditions either, since I can't create events via API on the demo.
Drupal/CiviCRM micro-blogging http://twitter.com/matt2000

Ninjitsu Web Development http://www.NinjitsuWeb.com/

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: civicrm_event_delete deletes too many events
May 13, 2008, 11:41:40 am

hey matt:

1. i looked at the delete code and did not see how it could delete all events (this does not mean that it works)

2. can u give us an api snippet which demonstrates the issues. i.e. code that both creates multiple events and deletes one event

3. the delete code presumes no sharing. so it will delete the location blocks. not sure if/how cascading has any effect. i'm pretty sure cascading does not effect "join" tables for the most part

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

Matt2000

  • I post frequently
  • ***
  • Posts: 288
  • Karma: 27
    • http://www.ninjitsuweb.com
Re: civicrm_event_delete deletes too many events
May 13, 2008, 04:51:09 pm
OK,

First I create an event with the UI, filling in only the required fields and using defaults otherwise.

Then I run this code twice to make two more event with roughly the same parameters:


Code: [Select]

$event_id = 1;  //This is the event I created with the UI

  civicrm_initialize();
  require_once('api/v2/Event.php');

  $toFind = array('id' => $event_id);
  $event = civicrm_event_get($toFind);

    $cloned_event = $event;

    unset($cloned_event['id']);
    $cloned_event['start_date'] = '20090513';
    $cloned_event['title'] = $cloned_event['title'] . " COPY";

    $new = civicrm_event_create($cloned_event);

I verify that the new events have unique IDs, but then, if I delete the original (ID=1) or a copy (ID=2 or ID=3), all the events are deleted.
Drupal/CiviCRM micro-blogging http://twitter.com/matt2000

Ninjitsu Web Development http://www.NinjitsuWeb.com/

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: civicrm_event_delete deletes too many events
May 13, 2008, 06:47:14 pm

This is happening because of the following constraint in civicrm_event

     CONSTRAINT FK_civicrm_event_loc_block_id FOREIGN KEY (loc_block_id) REFERENCES civicrm_loc_block(id) ON DELETE CASCADE

Since we did not expect to share location blocks, the above constraint made sense when we did the schema. At some point in time we might enable location block sharing in which case we'll need to fix the constraint.

for your current use case, you might want to alter the constraint to: ON DELETE SET NULL

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

Matt2000

  • I post frequently
  • ***
  • Posts: 288
  • Karma: 27
    • http://www.ninjitsuweb.com
Re: civicrm_event_delete deletes too many events
May 13, 2008, 08:48:13 pm
Well, +1 to my previous complaint: http://forum.civicrm.org/index.php/topic,3114.msg13674.html#msg13674

and...

Quote
I'd rather err on the side of leaving an unused record in the database than being over aggressive with FK constraints and cascading deletes

i.e., when given the choice between 'keep possibly unneeded data' and 'delete possibly unneeded data', the answer for automated processes (e.g., cascading FKs), is always 'KEEP'.

This should be standard best practice for database schema design, IMO.
Drupal/CiviCRM micro-blogging http://twitter.com/matt2000

Ninjitsu Web Development http://www.NinjitsuWeb.com/

Matt2000

  • I post frequently
  • ***
  • Posts: 288
  • Karma: 27
    • http://www.ninjitsuweb.com
Re: civicrm_event_delete deletes too many events
May 14, 2008, 12:05:47 am
By the way, I can verify that changing this FK as suggested does resolve the problem. Thanks!
Drupal/CiviCRM micro-blogging http://twitter.com/matt2000

Ninjitsu Web Development http://www.NinjitsuWeb.com/

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • civicrm_event_delete deletes too many events

This forum was archived on 2017-11-26.