Use Last-Modified property to check for changed events

This commit is contained in:
Bart Visscher 2011-11-09 22:17:09 +01:00
parent c65e417666
commit b095859a92
8 changed files with 44 additions and 5 deletions

View file

@ -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) {

View file

@ -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);

View file

@ -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);

View file

@ -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')));

View file

@ -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')));

View file

@ -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');
}
});
},

View file

@ -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) {

View file

@ -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">