diff --git a/plugins/calendar/drivers/database/database_driver.php b/plugins/calendar/drivers/database/database_driver.php index e3d9d51e..f136b009 100644 --- a/plugins/calendar/drivers/database/database_driver.php +++ b/plugins/calendar/drivers/database/database_driver.php @@ -277,6 +277,10 @@ class database_driver extends calendar_driver $update_recurring = true; $old = $this->get_event($event); + // increment sequence number + if ($old['sequence']) + $event['sequence'] = max($event['sequence'], $old['sequence']+1); + // modify a recurring event, check submitted savemode to do the right things if ($old['recurrence'] || $old['recurrence_id']) { $master = $old['recurrence_id'] ? $this->get_event(array('id' => $old['recurrence_id'])) : $old; @@ -431,7 +435,7 @@ class database_driver extends calendar_driver { $event = $this->_save_preprocess($event); $sql_set = array(); - $set_cols = array('start', 'end', 'all_day', 'recurrence_id', 'title', 'description', 'location', 'categories', 'free_busy', 'priority', 'sensitivity', 'attendees', 'alarms', 'notifyat'); + $set_cols = array('start', 'end', 'all_day', 'recurrence_id', 'sequence', 'title', 'description', 'location', 'categories', 'free_busy', 'priority', 'sensitivity', 'attendees', 'alarms', 'notifyat'); foreach ($set_cols as $col) { if (is_object($event[$col]) && is_a($event[$col], 'DateTime')) $sql_set[] = $this->rc->db->quote_identifier($col) . '=' . $this->rc->db->quote($event[$col]->format(self::DB_DATE_FORMAT)); @@ -650,8 +654,8 @@ class database_driver extends calendar_driver public function get_event($event, $writeable = null) { $id = is_array($event) ? ($event['id'] ? $event['id'] : $event['uid']) : $event; - $col = $event['id'] && is_numeric($event['id']) ? 'event_id' : 'uid'; - + $col = is_array($event) && is_numeric($id) ? 'event_id' : 'uid'; + if ($this->cache[$id]) return $this->cache[$id]; diff --git a/plugins/calendar/drivers/database/sql/mysql.sql b/plugins/calendar/drivers/database/sql/mysql.sql index d7887a9f..e39acf45 100644 --- a/plugins/calendar/drivers/database/sql/mysql.sql +++ b/plugins/calendar/drivers/database/sql/mysql.sql @@ -31,6 +31,7 @@ CREATE TABLE `events` ( `uid` varchar(255) NOT NULL DEFAULT '', `created` datetime NOT NULL DEFAULT '1000-01-01 00:00:00', `changed` datetime NOT NULL DEFAULT '1000-01-01 00:00:00', + `sequence` int(1) UNSIGNED NOT NULL DEFAULT '0', `start` datetime NOT NULL DEFAULT '1000-01-01 00:00:00', `end` datetime NOT NULL DEFAULT '1000-01-01 00:00:00', `recurrence` varchar(255) DEFAULT NULL, diff --git a/plugins/calendar/drivers/database/sql/postgresql.sql b/plugins/calendar/drivers/database/sql/postgresql.sql index c8f385e1..cff741b3 100644 --- a/plugins/calendar/drivers/database/sql/postgresql.sql +++ b/plugins/calendar/drivers/database/sql/postgresql.sql @@ -47,6 +47,7 @@ CREATE TABLE events ( uid varchar(255) NOT NULL DEFAULT '', created timestamp without time zone DEFAULT now() NOT NULL, changed timestamp without time zone DEFAULT now(), + sequence integer NOT NULL DEFAULT 0, "start" timestamp without time zone DEFAULT now() NOT NULL, "end" timestamp without time zone DEFAULT now() NOT NULL, recurrence varchar(255) DEFAULT NULL, diff --git a/plugins/calendar/drivers/database/sql/sqlite.sql b/plugins/calendar/drivers/database/sql/sqlite.sql index c89de5e4..1debe543 100644 --- a/plugins/calendar/drivers/database/sql/sqlite.sql +++ b/plugins/calendar/drivers/database/sql/sqlite.sql @@ -30,6 +30,7 @@ CREATE TABLE events ( uid varchar(255) NOT NULL default '', created datetime NOT NULL default '1000-01-01 00:00:00', changed datetime NOT NULL default '1000-01-01 00:00:00', + sequence integer NOT NULL default '0', start datetime NOT NULL default '1000-01-01 00:00:00', end datetime NOT NULL default '1000-01-01 00:00:00', recurrence varchar(255) default NULL,