From 8103156436173db679dae579a41042eb69313e1e Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 9 Sep 2019 09:16:52 -0400 Subject: [PATCH] when deleting multiple events, each event has to be it's own transaction due to locking --- web/includes/Event.php | 15 +++++++-------- web/includes/actions/events.php | 2 -- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/web/includes/Event.php b/web/includes/Event.php index e8b6d15be..19d28e0ec 100644 --- a/web/includes/Event.php +++ b/web/includes/Event.php @@ -142,16 +142,14 @@ class Event extends ZM_Object { # Assumption: All events have a start time $start_date = date_parse($this->{'StartTime'}); if ( ! $start_date ) { - Error('Unable to parse start time for event ' . $this->{'Id'} . ' not deleting files.'); - return; + throw new Exception('Unable to parse start time for event ' . $this->{'Id'} . ' not deleting files.'); } $start_date['year'] = $start_date['year'] % 100; # So this is because ZM creates a link under the day pointing to the time that the event happened. $link_path = $this->Link_Path(); if ( ! $link_path ) { - Error('Unable to determine link path for event '.$this->{'Id'}.' not deleting files.'); - return; + throw new Exception('Unable to determine link path for event '.$this->{'Id'}.' not deleting files.'); } $Storage = $this->Storage(); @@ -159,8 +157,7 @@ class Event extends ZM_Object { if ( $id_files = glob($eventlink_path) ) { if ( ! $eventPath = readlink($id_files[0]) ) { - Error("Unable to read link at $id_files[0]"); - return; + throw new Exception("Unable to read link at $id_files[0]"); } # I know we are using arrays here, but really there can only ever be 1 in the array $eventPath = preg_replace('/\.'.$this->{'Id'}.'$/', $eventPath, $id_files[0]); @@ -179,8 +176,7 @@ class Event extends ZM_Object { } else { $eventPath = $this->Path(); if ( ! $eventPath ) { - Error('No event Path in Event delete. Not deleting'); - return; + throw new Exception('No event Path in Event delete. Not deleting'); } deletePath($eventPath); if ( $this->SecondaryStorageId() ) { @@ -199,6 +195,9 @@ class Event extends ZM_Object { $dbConn->commit(); } catch (PDOException $e) { $dbConn->rollback(); + } catch (Exception $e) { + Error($e->getMessage()); + $dbConn->rollback(); } } # end Event->delete diff --git a/web/includes/actions/events.php b/web/includes/actions/events.php index 08782a8a2..abea69b60 100644 --- a/web/includes/actions/events.php +++ b/web/includes/actions/events.php @@ -44,11 +44,9 @@ if ( $action == 'archive' ) { $dbConn->commit(); $refreshParent = true; } else if ( $action == 'delete' ) { - $dbConn->beginTransaction(); foreach ( getAffectedIds('eids') as $markEid ) { deleteEvent($markEid); } - $dbConn->commit(); $refreshParent = true; } ?>