diff options
author | Bart Visscher <bartv@thisnet.nl> | 2011-11-09 22:17:09 +0100 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2011-11-09 22:17:09 +0100 |
commit | b095859a928a29bcb738dd820fb13dd57495c8d0 (patch) | |
tree | b1af2c528e19fe7b3647d3ed170fc83c8fed4cdb /apps | |
parent | c65e4176662aa989e1444c3c584a9d7846469262 (diff) | |
download | nextcloud-server-b095859a928a29bcb738dd820fb13dd57495c8d0.tar.gz nextcloud-server-b095859a928a29bcb738dd820fb13dd57495c8d0.zip |
Use Last-Modified property to check for changed events
Diffstat (limited to 'apps')
-rw-r--r-- | apps/calendar/ajax/editevent.php | 7 | ||||
-rw-r--r-- | apps/calendar/ajax/editeventform.php | 7 | ||||
-rw-r--r-- | apps/calendar/ajax/events.php | 9 | ||||
-rw-r--r-- | apps/calendar/ajax/moveevent.php | 8 | ||||
-rw-r--r-- | apps/calendar/ajax/resizeevent.php | 8 | ||||
-rw-r--r-- | apps/calendar/js/calendar.js | 8 | ||||
-rw-r--r-- | apps/calendar/lib/object.php | 1 | ||||
-rw-r--r-- | apps/calendar/templates/part.editevent.php | 1 |
8 files changed, 44 insertions, 5 deletions
diff --git a/apps/calendar/ajax/editevent.php b/apps/calendar/ajax/editevent.php index a60b0946ad2..46feb068499 100644 --- a/apps/calendar/ajax/editevent.php +++ b/apps/calendar/ajax/editevent.php @@ -35,6 +35,13 @@ if($errarr){ exit; } $vcalendar = OC_Calendar_Object::parse($data['calendardata']); + + $last_modified = $vcalendar->VEVENT->__get('LAST-MODIFIED'); + if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){ + OC_JSON::error(array('modified'=>true)); + exit; + } + OC_Calendar_Object::updateVCalendarFromRequest($_POST, $vcalendar); $result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); if ($data['calendarid'] != $cal) { diff --git a/apps/calendar/ajax/editeventform.php b/apps/calendar/ajax/editeventform.php index e6dc8136601..63c72934079 100644 --- a/apps/calendar/ajax/editeventform.php +++ b/apps/calendar/ajax/editeventform.php @@ -63,9 +63,16 @@ foreach($categories as $category){ } $repeat = isset($vevent->CATEGORY) ? $vevent->CATEGORY->value : ''; $description = isset($vevent->DESCRIPTION) ? $vevent->DESCRIPTION->value : ''; +$last_modified = $vevent->__get('LAST-MODIFIED'); +if ($last_modified){ + $lastmodified = $last_modified->getDateTime()->format('U'); +}else{ + $lastmodified = 0; +} $tmpl = new OC_Template('calendar', 'part.editevent'); $tmpl->assign('id', $id); +$tmpl->assign('lastmodified', $lastmodified); $tmpl->assign('calendar_options', $calendar_options); $tmpl->assign('category_options', $category_options); $tmpl->assign('repeat_options', $repeat_options); diff --git a/apps/calendar/ajax/events.php b/apps/calendar/ajax/events.php index 5ee2ffb6276..66aeb1a35ba 100644 --- a/apps/calendar/ajax/events.php +++ b/apps/calendar/ajax/events.php @@ -40,9 +40,16 @@ foreach($events as $event) $return_event['end'] = $end_dt->format('Y-m-d H:i:s'); $return_event['allDay'] = false; } - $return_event['id'] = $event['id']; + $return_event['id'] = (int)$event['id']; $return_event['title'] = $event['summary']; $return_event['description'] = isset($vevent->DESCRIPTION)?$vevent->DESCRIPTION->value:''; + $last_modified = $vevent->__get('LAST-MODIFIED'); + if ($last_modified){ + $lastmodified = $last_modified->getDateTime()->format('U'); + }else{ + $lastmodified = 0; + } + $return_event['lastmodified'] = (int)$lastmodified; $return[] = $return_event; } OC_JSON::encodedPrint($return); diff --git a/apps/calendar/ajax/moveevent.php b/apps/calendar/ajax/moveevent.php index 834a454fca2..6b315a39213 100644 --- a/apps/calendar/ajax/moveevent.php +++ b/apps/calendar/ajax/moveevent.php @@ -25,6 +25,12 @@ $delta->i = $_POST['minuteDelta']; $vcalendar = OC_Calendar_Object::parse($data['calendardata']); $vevent = $vcalendar->VEVENT; +$last_modified = $vevent->__get('LAST-MODIFIED'); +if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){ + OC_JSON::error(); + exit; +} + $dtstart = $vevent->DTSTART; $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); $start_type = $dtstart->getDateType(); @@ -50,4 +56,4 @@ $dtstamp->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); $vevent->DTSTAMP = $dtstamp; $result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); -OC_JSON::success(); +OC_JSON::success(array('lastmodified'=>(int)$now->format('U'))); diff --git a/apps/calendar/ajax/resizeevent.php b/apps/calendar/ajax/resizeevent.php index 639ef91ee7c..28a185411e0 100644 --- a/apps/calendar/ajax/resizeevent.php +++ b/apps/calendar/ajax/resizeevent.php @@ -25,6 +25,12 @@ $delta->i = $_POST['minuteDelta']; $vcalendar = OC_Calendar_Object::parse($data['calendardata']); $vevent = $vcalendar->VEVENT; +$last_modified = $vevent->__get('LAST-MODIFIED'); +if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){ + OC_JSON::error(); + exit; +} + $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); $end_type = $dtend->getDateType(); $dtend->setDateTime($dtend->getDateTime()->add($delta), $end_type); @@ -40,4 +46,4 @@ $dtstamp->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); $vevent->DTSTAMP = $dtstamp; $result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); -OC_JSON::success(); +OC_JSON::success(array('lastmodified'=>$now->format('U'))); diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index e943bee7057..af5ecd82816 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -108,23 +108,27 @@ Calendar={ }, moveEvent:function(event, dayDelta, minuteDelta, allDay, revertFunc){ $('.tipsy').remove(); - $.post(OC.filePath('calendar', 'ajax', 'moveevent.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, allDay: allDay?1:0}, + $.post(OC.filePath('calendar', 'ajax', 'moveevent.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, allDay: allDay?1:0, lastmodified: event.lastmodified}, function(data) { if (data.status == 'success'){ + event.lastmodified = data.lastmodified; console.log("Event moved successfully"); }else{ revertFunc(); + $('#calendar_holder').fullCalendar('refetchEvents'); } }); }, resizeEvent:function(event, dayDelta, minuteDelta, revertFunc){ $('.tipsy').remove(); - $.post(OC.filePath('calendar', 'ajax', 'resizeevent.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta}, + $.post(OC.filePath('calendar', 'ajax', 'resizeevent.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, lastmodified: event.lastmodified}, function(data) { if (data.status == 'success'){ + event.lastmodified = data.lastmodified; console.log("Event resized successfully"); }else{ revertFunc(); + $('#calendar_holder').fullCalendar('refetchEvents'); } }); }, diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index 9a343a23764..221df2b3af0 100644 --- a/apps/calendar/lib/object.php +++ b/apps/calendar/lib/object.php @@ -307,6 +307,7 @@ class OC_Calendar_Object{ */ public static function parse($data){ try { + Sabre_VObject_Reader::$elementMap['LAST-MODIFIED'] = 'Sabre_VObject_Element_DateTime'; $calendar = Sabre_VObject_Reader::read($data); return $calendar; } catch (Exception $e) { diff --git a/apps/calendar/templates/part.editevent.php b/apps/calendar/templates/part.editevent.php index ae969f2dc3b..b3acfc4a072 100644 --- a/apps/calendar/templates/part.editevent.php +++ b/apps/calendar/templates/part.editevent.php @@ -1,6 +1,7 @@ <div id="event" title="<?php echo $l->t("Edit an event");?>"> <form id="event_form"> <input type="hidden" name="id" value="<?php echo $_['id'] ?>"> + <input type="hidden" name="lastmodified" value="<?php echo $_['lastmodified'] ?>"> <?php echo $this->inc("part.eventform"); ?> <div style="width: 100%;text-align: center;color: #FF1D1D;" id="errorbox"></div> <span id="actions"> |