/** * Performs ical updates on given events. * * @param array ical and event properties to update. See ical_sync::get_updates(). * @return array List of event ids. */ private function _perform_updates($updates) { $event_ids = array(); $num_created = 0; $num_updated = 0; foreach ($updates as $update) { // local event -> update event if (isset($update["local_event"])) { // let edit_event() do all the magic if (parent::edit_event($update["remote_event"] + (array) $update["local_event"])) { $event_id = $update["local_event"]["id"]; array_push($event_ids, $event_id); $num_updated++; self::debug_log("Updated event \"{$event_id}\"."); } else { self::debug_log("Could not perform event update: " . print_r($update, true)); } } else { $event_id = parent::new_event($update["remote_event"]); if ($event_id) { array_push($event_ids, $event_id); $num_created++; self::debug_log("Created event \"{$event_id}\"."); } else { self::debug_log("Could not perform event creation: " . print_r($update, true)); } } } self::debug_log("Created {$num_created} new events, updated {$num_updated} event."); return $event_ids; }
/** * Add a single event to the database and to the caldav server. * * @param array Hash array with event properties * @return int Event id on success, false otherwise. * @see database_driver::new_event() */ public function new_event($event) { if ($event['_type'] == 'task') { $this->tasks = new tasklist_caldav_driver($this->cal, false); $event['list'] = $event['calendar']; unset($event['calendar']); return $this->tasks->create_task($event); } else { $event_id = parent::new_event($event); $cal_id = $event['calendar']; if ($event_id !== false) { $sync_client = $this->sync_clients[$cal_id]; $event = $this->_save_preprocess($event); $props = $sync_client->create_event($event); if ($props === false) { self::debug_log("Unkown error while creating caldav event, undo creating local event \"{$event_id}\"!"); parent::remove_event($event); return false; } else { self::debug_log("Successfully pushed event \"{$event_id}\" to caldav server."); $this->_set_caldav_props($event_id, self::OBJ_TYPE_VEVENT, $props, 'new_event'); // Trigger calendar sync to update ctags and etags. if ($this->rc->action != 'import_events') { $this->_sync_calendar($cal_id); } return $event_id; } } } return false; }