From b92f26e88bff6d1d7d0044b2792b428751a654eb Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Thu, 28 Nov 2013 20:03:56 +0400 Subject: [PATCH] Update contacts schema --- .../PersonalAddressBook/Classes/Contact.php | 35 ++++------- .../PersonalAddressBook/Classes/Property.php | 2 +- .../PersonalAddressBook/mysql-schema.sql | 61 ++++++++++++------- 3 files changed, 52 insertions(+), 46 deletions(-) diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/Classes/Contact.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/Classes/Contact.php index 32e5bea0d..7681906b0 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/Classes/Contact.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/Classes/Contact.php @@ -13,16 +13,6 @@ class Contact * @var int */ public $IdUser; - - /** - * @var string - */ - public $DisplayName; - - /** - * @var string - */ - public $DisplayEmail; /** * @var string @@ -39,6 +29,11 @@ class Contact */ public $IsShare; + /** + * @var bool + */ + public $CanBeChanged; + /** * @var int */ @@ -68,17 +63,16 @@ class Contact { $this->IdContact = 0; $this->IdUser = 0; - $this->DisplayName = ''; - $this->DisplayEmail = ''; $this->DisplayInList = ''; $this->IsAuto = false; $this->IsShare = false; + $this->CanBeChanged = false; $this->Changed = \time(); $this->Tags = array(); $this->Properties = array(); } - public function InitBeforeWrite() + public function UpdateDependentValues() { $sDisplayName = ''; $sDisplayEmail = ''; @@ -87,24 +81,21 @@ class Contact { if ($oProperty) { - $oProperty->InitBeforeWrite(); + $oProperty->UpdateDependentValues(); - if ('' === $sDisplayName && \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType::FULLNAME === $oProperty->Type) + if ('' === $sDisplayName && \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType::FULLNAME === $oProperty->Type && + 0 < \strlen($oProperty->Value)) { $sDisplayName = $oProperty->Value; } - - if ('' === $sDisplayEmail && $oProperty->IsEmail()) + else if ('' === $sDisplayEmail && $oProperty->IsEmail() && + 0 < \strlen($oProperty->Value)) { $sDisplayEmail = $oProperty->Value; } } } - $this->DisplayName = $sDisplayName; - $this->DisplayEmail = $sDisplayEmail; - $this->DisplayInList = 0 < \strlen($this->DisplayName) ? $this->DisplayName : (!empty($this->DisplayEmail) ? $this->DisplayEmail : ''); - - $this->Changed = \time(); + $this->DisplayInList = 0 < \strlen($sDisplayName) ? $sDisplayName : (!empty($sDisplayEmail) ? $sDisplayEmail : ''); } } diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/Classes/Property.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/Classes/Property.php index 59e5d43ee..a41d1eeb2 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/Classes/Property.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/Classes/Property.php @@ -82,7 +82,7 @@ class Property )); } - public function InitBeforeWrite() + public function UpdateDependentValues() { // trimer $this->Value = \trim($this->Value); diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/mysql-schema.sql b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/mysql-schema.sql index 6e6b8856c..1c2f1b139 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/mysql-schema.sql +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/PersonalAddressBook/mysql-schema.sql @@ -5,13 +5,13 @@ -- Table structure for table `rainloop_system` CREATE TABLE IF NOT EXISTS `rainloop_system` ( `name` varchar(50) NOT NULL, - `value_int` int(10) UNSIGNED NOT NULL DEFAULT '0', + `value_int` int(11) UNSIGNED NOT NULL DEFAULT '0', `value_str` varchar(255) NOT NULL DEFAULT '' ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; --- Table structure for table `rainloop_pab_users` -CREATE TABLE IF NOT EXISTS `rainloop_pab_users` ( - `id_user` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, +-- Table structure for table `rainloop_users` +CREATE TABLE IF NOT EXISTS `rainloop_users` ( + `id_user` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `email` varchar(255) /*!40101 CHARACTER SET ascii COLLATE ascii_general_ci */ NOT NULL, UNIQUE `email_unique` (`email`), @@ -20,43 +20,57 @@ CREATE TABLE IF NOT EXISTS `rainloop_pab_users` ( -- Table structure for table `rainloop_pab_contacts` CREATE TABLE IF NOT EXISTS `rainloop_pab_contacts` ( - `id_contact` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `id_user` int(10) UNSIGNED NOT NULL, - `display_name` varchar(255) NOT NULL DEFAULT '', - `display_email` varchar(255) /*!40101 CHARACTER SET ascii COLLATE ascii_general_ci */ NOT NULL DEFAULT '', + `id_contact` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `id_user` int(11) UNSIGNED NOT NULL, `display_in_list` varchar(255) NOT NULL DEFAULT '', `is_auto` tinyint(1) NOT NULL DEFAULT '0', `is_share` tinyint(1) NOT NULL DEFAULT '0', - `changed` int(10) UNSIGNED NOT NULL DEFAULT '0', + `changed` int(11) UNSIGNED NOT NULL DEFAULT '0', CONSTRAINT `id_user_fk_rainloop_pab_contacts` FOREIGN KEY (`id_user`) - REFERENCES `rainloop_pab_users` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE, + REFERENCES `rainloop_users` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE, PRIMARY KEY(`id_contact`) ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; -- Table structure for table `rainloop_pab_prop` CREATE TABLE IF NOT EXISTS `rainloop_pab_prop` ( - `id_contact` int(10) UNSIGNED NOT NULL, - `id_user` int(10) UNSIGNED NOT NULL, - `type` int(10) UNSIGNED NOT NULL, + `id_contact` int(11) UNSIGNED NOT NULL, + `id_user` int(11) UNSIGNED NOT NULL, + `type` int(11) UNSIGNED NOT NULL, `type_custom` varchar(50) /*!40101 CHARACTER SET ascii COLLATE ascii_general_ci */ NOT NULL DEFAULT '', `value` varchar(255) NOT NULL DEFAULT '', `value_custom` varchar(255) NOT NULL DEFAULT '', - `frec` int(10) UNSIGNED NOT NULL DEFAULT '0', + `frec` int(11) UNSIGNED NOT NULL DEFAULT '0', + INDEX `id_user_id_contact_index` (`id_user`, `id_contact`), + INDEX `id_user_value_index` (`id_user`, `value`), CONSTRAINT `id_contact_fk_rainloop_pab_prop` FOREIGN KEY (`id_contact`) REFERENCES `rainloop_pab_contacts` (`id_contact`) ON DELETE CASCADE ON UPDATE CASCADE ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; -- Table structure for table `rainloop_pab_tags` CREATE TABLE IF NOT EXISTS `rainloop_pab_tags` ( - `id_user` int(10) UNSIGNED NOT NULL, - `id_contact` int(10) UNSIGNED NOT NULL, + `id_tag` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `id_contact` int(11) UNSIGNED NOT NULL, + `id_user` int(11) UNSIGNED NOT NULL, `name` varchar(255) NOT NULL, UNIQUE `id_user_name_unique` (`id_user`, `name`), - CONSTRAINT `id_contact_fk_rainloop_pab_tags` FOREIGN KEY (`id_contact`) - REFERENCES `rainloop_pab_contacts` (`id_contact`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `id_user_fk_rainloop_pab_tags` FOREIGN KEY (`id_user`) + REFERENCES `rainloop_users` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE, + PRIMARY KEY(`id_tag`) +) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; + +-- Table structure for table `rainloop_pab_tags_contacts` +CREATE TABLE IF NOT EXISTS `rainloop_pab_tags_contacts` ( + `id_tag` int(11) UNSIGNED NOT NULL, + `id_contact` int(11) UNSIGNED NOT NULL, + + UNIQUE `id_user_name_unique` (`id_user`, `name`), + CONSTRAINT `id_contact_fk_rainloop_tags_contacts` FOREIGN KEY (`id_contact`) + REFERENCES `rainloop_pab_contacts` (`id_contact`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `id_tag_fk_rainloop_tags_contacts` FOREIGN KEY (`id_tag`) + REFERENCES `rainloop_pab_tags` (`id_tag`) ON DELETE CASCADE ON UPDATE CASCADE ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; -- RainLoop Webmail update contacts database structure @@ -71,12 +85,12 @@ BEGIN DECLARE current_version INT DEFAULT 0; SELECT IFNULL(MAX(`value_int`), 0) INTO current_version FROM `rainloop_system` WHERE `name` = 'rainloop-pab-db-version'; - IF current_version < 1 THEN - ALTER TABLE `rainloop_pab_prop` ADD INDEX `id_user_id_contact_index` (`id_user`, `id_contact`); - END IF; - -- TODO -- +-- IF current_version < 1 THEN +-- ALTER TABLE `rainloop_pab_prop` ADD INDEX `id_user_id_contact_index` (`id_user`, `id_contact`); +-- END IF; +-- -- IF current_version < 2 THEN -- ALTER TABLE `rainloop_pab_prop` ADD INDEX `id_user_id_contact_index` (`id_user`, `id_contact`); -- END IF; @@ -85,7 +99,8 @@ BEGIN INSERT INTO `rainloop_system` (`name`, `value_int`) VALUES ('rainloop-pab-db-version', new_version); END$$ -CALL rainloop_pab_upgrade_database() $$ +-- TODO +-- CALL rainloop_pab_upgrade_database() $$ DROP PROCEDURE IF EXISTS rainloop_pab_upgrade_database $$