diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-06-30 23:18:41 +0200 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-06-30 23:18:41 +0200 |
commit | ce331bd1d39192d5a062f27c2a63af581063e0b6 (patch) | |
tree | 8c1f4efcdd890a396f745a0ba40cc240321dec9b /apps/calendar | |
parent | a705b19cd598b538d0b82d97166d5d0ba03ff835 (diff) | |
download | nextcloud-server-ce331bd1d39192d5a062f27c2a63af581063e0b6.tar.gz nextcloud-server-ce331bd1d39192d5a062f27c2a63af581063e0b6.zip |
improvements for dropoimport
Diffstat (limited to 'apps/calendar')
-rw-r--r-- | apps/calendar/ajax/import/dropimport.php | 8 | ||||
-rw-r--r-- | apps/calendar/js/calendar.js | 4 | ||||
-rw-r--r-- | apps/calendar/lib/import.php | 20 |
3 files changed, 25 insertions, 7 deletions
diff --git a/apps/calendar/ajax/import/dropimport.php b/apps/calendar/ajax/import/dropimport.php index a3bef1ac294..b58b3f91cc4 100644 --- a/apps/calendar/ajax/import/dropimport.php +++ b/apps/calendar/ajax/import/dropimport.php @@ -23,4 +23,10 @@ $newcalendarname = strip_tags($import->createCalendarName()); $newid = OC_Calendar_Calendar::addCalendar(OCP\User::getUser(),$newcalendarname,'VEVENT,VTODO,VJOURNAL',null,0,$import->createCalendarColor()); $import->setCalendarID($newid); $import->import(); -OCP\JSON::success(array('newcalendarname'=>$newcalendarname, 'count'=>$import->getCount(), 'newcalendarid'=>$newid, 'eventSource'=>OC_Calendar_Calendar::getEventSourceInfo(OC_Calendar_Calendar::find($newid))));
\ No newline at end of file +$count = $import->getCount(); +if($count == 0){ + OC_Calendar_Calendar::deleteCalendar($newid); + OCP\JSON::error(array('message'=>OC_Calendar_App::$l10n->t('The file contained either no events or all events are already saved in your account'))); +}else{ + OCP\JSON::success(array('message'=>$count . ' ' . OC_Calendar_App::$l10n->t('events has been saved in the new calendar') . ' ' . $newcalendarname, 'eventSource'=>OC_Calendar_Calendar::getEventSourceInfo(OC_Calendar_Calendar::find($newid)))); +}
\ No newline at end of file diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index 0c4d44769cd..aaf168844ea 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -635,12 +635,12 @@ Calendar={ $.post(OC.filePath('calendar', 'ajax/import', 'dropimport.php'), {'data':data},function(result) { if(result.status == 'success'){ $('#calendar_holder').fullCalendar('addEventSource', result.eventSource); - $('#notification').html(result.count + ' Events has been saved in the new calendar ' + result.newcalendarname); + $('#notification').html(result.message); $('#notification').slideDown(); window.setTimeout(function(){$('#notification').slideUp();}, 5000); return true; }else{ - $('#notification').html('ownCloud wasn\'t able to import at least one file. File skipped.'); + $('#notification').html(result.message); $('#notification').slideDown(); window.setTimeout(function(){$('#notification').slideUp();}, 5000); } diff --git a/apps/calendar/lib/import.php b/apps/calendar/lib/import.php index 3a7af8e4bfd..dccb8955af8 100644 --- a/apps/calendar/lib/import.php +++ b/apps/calendar/lib/import.php @@ -95,8 +95,12 @@ class OC_Calendar_Import{ $object->DTEND->setDateTime($dtend->getDateTime(), $object->DTSTART->getDateType()); $object->DTEND->getDateTime()->setTimezone(new DateTimeZone($this->tz)); $vcalendar = $this->createVCalendar($object->serialize()); - OC_Calendar_Object::add($this->id, $vcalendar); - $this->count++; + $insertid = OC_Calendar_Object::add($this->id, $vcalendar); + if($this->isDuplicate($insertid)){ + OC_Calendar_Object::delete($insertid); + }else{ + $this->count++; + } } return true; } @@ -240,10 +244,18 @@ class OC_Calendar_Import{ /* * @brief checks if an event already exists in the user's calendars + * @param integer $insertid id of the new object * @return boolean */ - private function isDuplicate(){ - + private function isDuplicate($insertid){ + $newobject = OC_Calendar_Object::find($insertid); + $stmt = OCP\DB::prepare('SELECT COUNT(*) as count FROM *PREFIX*calendar_objects WHERE objecttype=? AND startdate=? AND enddate=? AND repeating=? AND summary=? AND calendardata=?'); + $result = $stmt->execute(array($newobject['objecttype'],$newobject['startdate'],$newobject['enddate'],$newobject['repeating'],$newobject['summary'],$newobject['calendardata'])); + $result = $result->fetchRow(); + if($result['count'] >= 2){ + return true; + } + return false; } /* |