From a46f8bf61377505186c2148546783e165a83519a Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Mon, 20 Sep 2010 12:55:41 +1200 Subject: [PATCH] [collection-edit] Handle duplicate key error properly. Avoid SQL error on new. --- inc/ui/collection-edit.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/inc/ui/collection-edit.php b/inc/ui/collection-edit.php index 9d0ee163..00f6f334 100644 --- a/inc/ui/collection-edit.php +++ b/inc/ui/collection-edit.php @@ -89,8 +89,11 @@ if ( $can_write_collection && $editor->IsSubmit() ) { else { $c->messages[] = i18n("Updating Collection record."); } - $editor->Write(); - if ( isset($_FILES['ics_file']['tmp_name']) && $_FILES['ics_file']['tmp_name'] != '' ) { + if ( !$editor->Write() ) { + $c->messages[] = i18n("Failed to write collection."); + if ( $id > 0 ) $editor->GetRecord(); + } + else if ( isset($_FILES['ics_file']['tmp_name']) && $_FILES['ics_file']['tmp_name'] != '' ) { /** * If the user has uploaded a .ics file as a calendar, we fake this out * as if it were a "PUT" request against a collection. This is something @@ -116,7 +119,7 @@ if ( $can_write_collection && $editor->IsSubmit() ) { } } else { - $editor->GetRecord(); + if ( $id > 0 ) $editor->GetRecord(); if ( $editor->IsSubmit() ) { $c->messages[] = i18n('You do not have permission to modify this record.'); }