Skip to content

Commit

Permalink
when deleting multiple events, each event has to be it's own transact…
Browse files Browse the repository at this point in the history
…ion due to locking
  • Loading branch information
Isaac Connor committed Sep 9, 2019
1 parent f1cffa6 commit 8103156
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 7 additions & 8 deletions web/includes/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,22 @@ public function delete() {
# 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();
$eventlink_path = $Storage->Path().'/'.$link_path;

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]);
Expand All @@ -179,8 +176,7 @@ public function delete() {
} 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() ) {
Expand All @@ -199,6 +195,9 @@ public function delete() {
$dbConn->commit();
} catch (PDOException $e) {
$dbConn->rollback();
} catch (Exception $e) {
Error($e->getMessage());
$dbConn->rollback();
}
} # end Event->delete

Expand Down
2 changes: 0 additions & 2 deletions web/includes/actions/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@
$dbConn->commit();
$refreshParent = true;
} else if ( $action == 'delete' ) {
$dbConn->beginTransaction();
foreach ( getAffectedIds('eids') as $markEid ) {
deleteEvent($markEid);
}
$dbConn->commit();
$refreshParent = true;
}
?>

0 comments on commit 8103156

Please sign in to comment.