diff --git a/Core/Distrib.php b/Core/Distrib.php index 157b8f0..ebd9c76 100644 --- a/Core/Distrib.php +++ b/Core/Distrib.php @@ -24,5 +24,5 @@ # This copyright notice MUST APPEAR in all copies of the script! ################################################################# -define("BAIKAL_VERSION", "0.5.0"); +define("BAIKAL_VERSION", "0.5.1"); define("BAIKAL_HOMEPAGE", "http://sabre.io/baikal/"); diff --git a/Core/Frameworks/Baikal/Model/Calendar.php b/Core/Frameworks/Baikal/Model/Calendar.php index 9634655..0d22b32 100644 --- a/Core/Frameworks/Baikal/Model/Calendar.php +++ b/Core/Frameworks/Baikal/Model/Calendar.php @@ -28,7 +28,7 @@ namespace Baikal\Model; class Calendar extends \Flake\Core\Model\Db { - const DATATABLE = "calendars"; + const DATATABLE = "calendarinstances"; const PRIMARYKEY = "id"; const LABELFIELD = "displayname"; @@ -40,8 +40,25 @@ class Calendar extends \Flake\Core\Model\Db { "calendarorder" => 0, "calendarcolor" => "", "timezone" => "", - "components" => "", + "calendarid" => 0 ]; + protected $oCalendar; # Baikal\Model\Calendar\Calendar + + protected function initFloating() { + parent::initFloating(); + $this->oCalendar = new Calendar\Calendar(); + } + + protected function initByPrimary($sPrimary) { + parent::initByPrimary($sPrimary); + $this->oCalendar = new Calendar\Calendar($this->get("calendarid")); + } + + function persist() { + $this->oCalendar->persist(); + $this->aData["calendarid"] = $this->oCalendar->get("id"); + parent::persist(); + } static function icon() { return "icon-calendar"; @@ -67,6 +84,10 @@ class Calendar extends \Flake\Core\Model\Db { function get($sPropName) { + if ($sPropName === "components") { + return $this->oCalendar->get($sPropName); + } + if ($sPropName === "todos") { # TRUE if components contains VTODO, FALSE otherwise if (($sComponents = $this->get("components")) !== "") { @@ -94,6 +115,10 @@ class Calendar extends \Flake\Core\Model\Db { function set($sPropName, $sValue) { + if ($sPropName === "components") { + return $this->oCalendar->set($sPropName, $sValue); + } + if ($sPropName === "todos") { if (($sComponents = $this->get("components")) !== "") { @@ -112,7 +137,7 @@ class Calendar extends \Flake\Core\Model\Db { } } - return parent::set("components", implode(",", $aComponents)); + return $this->set("components", implode(",", $aComponents)); } if ($sPropName === "notes") { @@ -133,7 +158,7 @@ class Calendar extends \Flake\Core\Model\Db { } } - return parent::set("components", implode(",", $aComponents)); + return $this->set("components", implode(",", $aComponents)); } return parent::set($sPropName, $sValue); @@ -215,5 +240,6 @@ class Calendar extends \Flake\Core\Model\Db { } parent::destroy(); + $this->oCalendar->destroy(); } } diff --git a/Core/Frameworks/Baikal/Model/Calendar/Calendar.php b/Core/Frameworks/Baikal/Model/Calendar/Calendar.php new file mode 100644 index 0000000..a92b775 --- /dev/null +++ b/Core/Frameworks/Baikal/Model/Calendar/Calendar.php @@ -0,0 +1,60 @@ + +# All rights reserved +# +# http://baikal-server.com +# +# This script is part of the Baïkal Server project. The Baïkal +# Server project is free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# The GNU General Public License can be found at +# http://www.gnu.org/copyleft/gpl.html. +# +# This script is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# This copyright notice MUST APPEAR in all copies of the script! +################################################################# + + +namespace Baikal\Model\Calendar; + +class Calendar extends \Flake\Core\Model\Db { + const DATATABLE = "calendars"; + const PRIMARYKEY = "id"; + const LABELFIELD = "components"; + + protected $aData = [ + "synctoken" => "", + "components" => "" + ]; + + function hasInstances() { + $rSql = $GLOBALS["DB"]->exec_SELECTquery( + "*", + "calendarinstances", + "calendarid" . "='" . $this->aData["id"] . "'" + ); + + if (($aRs = $rSql->fetch()) === false) { + return false; + } else { + reset($aRs); + return true; + } + } + + function destroy() { + if (!$this->hasInstances()) { + parent::destroy(); + } + } +} diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php b/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php index 2783bda..7ac1b2c 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php @@ -377,6 +377,141 @@ CREATE TABLE addressbooks ( } } + if (version_compare($sVersionFrom, '0.5.1', '<')) { + if (!defined("PROJECT_DB_MYSQL") || PROJECT_DB_MYSQL === false) { + $pdo->exec(<<aSuccess[] = 'Created calendarinstances table'; + $pdo->exec(' +INSERT INTO calendarinstances + ( + calendarid, + principaluri, + access, + displayname, + uri, + description, + calendarorder, + calendarcolor, + transparent + ) +SELECT + id, + principaluri, + 1, + displayname, + uri, + description, + calendarorder, + calendarcolor, + transparent +FROM calendars +'); + $this->aSuccess[] = 'Migrated calendarinstances table'; + $calendarBackup = 'calendars_3_1'; + $pdo->exec('ALTER TABLE calendars RENAME TO ' . $calendarBackup); + $this->aSuccess[] = 'Did calendars backup'; + + $pdo->exec(<<aSuccess[] = 'Created new calendars table'; + } else { // mysql + $pdo->exec(<<aSuccess[] = 'Created calendarinstances table'; + $pdo->exec(' +INSERT INTO calendarinstances + ( + calendarid, + principaluri, + access, + displayname, + uri, + description, + calendarorder, + calendarcolor, + transparent + ) +SELECT + id, + principaluri, + 1, + displayname, + uri, + description, + calendarorder, + calendarcolor, + transparent +FROM calendars +'); + $this->aSuccess[] = 'Migrated calendarinstances table'; + $calendarBackup = 'calendars_3_1'; + $pdo->exec('RENAME TABLE calendars TO ' . $calendarBackup); + $this->aSuccess[] = 'Did calendars backup'; + + $pdo->exec(<<aSuccess[] = 'Created new calendars table'; + } + + $pdo->exec(<<aSuccess[] = 'Migrated calendars table'; + } $this->updateConfiguredVersion($sVersionTo); diff --git a/Core/Resources/Db/MySQL/db.sql b/Core/Resources/Db/MySQL/db.sql index 6dc4e23..e572c5b 100644 --- a/Core/Resources/Db/MySQL/db.sql +++ b/Core/Resources/Db/MySQL/db.sql @@ -26,6 +26,7 @@ CREATE TABLE addressbookchanges ( operation TINYINT(1) NOT NULL, INDEX addressbookid_synctoken (addressbookid, synctoken) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + CREATE TABLE calendarobjects ( id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, calendardata MEDIUMBLOB, @@ -43,17 +44,28 @@ CREATE TABLE calendarobjects ( CREATE TABLE calendars ( id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + synctoken INTEGER UNSIGNED NOT NULL DEFAULT '1', + components VARBINARY(21) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE calendarinstances ( + id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + calendarid INTEGER UNSIGNED NOT NULL, principaluri VARBINARY(100), + access TINYINT(1) NOT NULL DEFAULT '1', displayname VARCHAR(100), uri VARBINARY(200), - synctoken INTEGER UNSIGNED NOT NULL DEFAULT '1', description TEXT, calendarorder INT(11) UNSIGNED NOT NULL DEFAULT '0', calendarcolor VARBINARY(10), timezone TEXT, - components VARBINARY(21), transparent TINYINT(1) NOT NULL DEFAULT '0', - UNIQUE(principaluri, uri) + share_href VARBINARY(100), + share_displayname VARCHAR(100), + share_invitestatus TINYINT(1) NOT NULL DEFAULT '2', + UNIQUE(principaluri, uri), + UNIQUE(calendarid, principaluri), + UNIQUE(calendarid, share_href) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; CREATE TABLE calendarchanges ( diff --git a/Core/Resources/Db/SQLite/db.sql b/Core/Resources/Db/SQLite/db.sql index e8b8d55..6d3bf7c 100644 --- a/Core/Resources/Db/SQLite/db.sql +++ b/Core/Resources/Db/SQLite/db.sql @@ -42,16 +42,28 @@ CREATE TABLE calendarobjects ( CREATE TABLE calendars ( id integer primary key asc NOT NULL, - principaluri text NOT NULL, + synctoken integer DEFAULT 1 NOT NULL, + components text NOT NULL +); + +CREATE TABLE calendarinstances ( + id integer primary key asc NOT NULL, + calendarid integer, + principaluri text, + access integer, displayname text, uri text NOT NULL, - synctoken integer DEFAULT 1 NOT NULL, description text, calendarorder integer, calendarcolor text, timezone text, - components text NOT NULL, - transparent bool + transparent bool, + share_href text, + share_displayname text, + share_invitestatus integer DEFAULT '2', + UNIQUE (principaluri, uri), + UNIQUE (calendarid, principaluri), + UNIQUE (calendarid, share_href) ); CREATE TABLE calendarchanges ( diff --git a/composer.json b/composer.json index dc35613..8c2d1ba 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ ], "require": { "php" : ">=5.5", - "sabre/dav" : "~3.1.2", + "sabre/dav" : "~3.2.3", "twig/twig" : "~1.8.0" }, "require-dev" : {