From 05caac511b414f55b77e39dba29dabcfb53009dd Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Tue, 3 Dec 2019 23:52:19 +0100 Subject: [PATCH] FEAT #12509 TIME 4:30 migrateContacts --- migration/19.12/1912-postScript.sql | 35 ++-- migration/19.12/1912.sql | 21 ++ migration/19.12/migrateContacts.php | 305 +++++++++++++++++++++++++++- sql/structure.sql | 202 +++--------------- 4 files changed, 358 insertions(+), 205 deletions(-) diff --git a/migration/19.12/1912-postScript.sql b/migration/19.12/1912-postScript.sql index cd3de87035c..eff13d1a4cf 100644 --- a/migration/19.12/1912-postScript.sql +++ b/migration/19.12/1912-postScript.sql @@ -12,12 +12,29 @@ DROP VIEW IF EXISTS view_contacts; DROP TABLE IF EXISTS cases; DROP TABLE IF EXISTS cases_res; +DROP TABLE IF EXISTS contacts_res; DROP TABLE IF EXISTS contact_addresses; DROP TABLE IF EXISTS contact_communication; DROP TABLE IF EXISTS contact_purposes; DROP TABLE IF EXISTS contact_types; DROP TABLE IF EXISTS contacts_v2; +ALTER TABLE acknowledgement_receipts ALTER COLUMN contact_id set not null; +ALTER TABLE acknowledgement_receipts DROP COLUMN IF EXISTS contact_address_id; +ALTER TABLE contacts_groups_lists ALTER COLUMN contact_id set not null; +ALTER TABLE contacts_groups_lists DROP COLUMN IF EXISTS contact_address_id; +ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_contact_id; +ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_address_id; +ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_user; +ALTER TABLE contacts_filling DROP COLUMN IF EXISTS rating_columns; + +ALTER TABLE res_letterbox DROP COLUMN IF EXISTS exp_contact_id; +ALTER TABLE res_letterbox DROP COLUMN IF EXISTS exp_user_id; +ALTER TABLE res_letterbox DROP COLUMN IF EXISTS dest_contact_id; +ALTER TABLE res_letterbox DROP COLUMN IF EXISTS dest_user_id; +ALTER TABLE res_letterbox DROP COLUMN IF EXISTS address_id; +ALTER TABLE res_letterbox DROP COLUMN IF EXISTS is_multicontacts; + DROP TABLE IF EXISTS fp_fileplan; DROP TABLE IF EXISTS fp_fileplan_positions; DROP TABLE IF EXISTS fp_res_fileplan_positions; @@ -121,11 +138,6 @@ SELECT r.res_id, r.dest_user, r.confidentiality, r.category_id, - r.exp_contact_id, - r.exp_user_id, - r.dest_user_id, - r.dest_contact_id, - r.address_id, r.alt_identifier, r.admission_date, r.process_limit_date, @@ -134,24 +146,15 @@ SELECT r.res_id, r.alarm2_date, r.flag_alarm1, r.flag_alarm2, - r.is_multicontacts, r.subject, r.priority, r.locker_user_id, r.locker_time, en.entity_label, - en.entity_type AS entitytype, - cont.contact_id, - cont.firstname AS contact_firstname, - cont.lastname AS contact_lastname, - cont.society AS contact_society, - u.lastname AS user_lastname, - u.firstname AS user_firstname + en.entity_type AS entitytype FROM doctypes d, doctypes_first_level dfl, doctypes_second_level dsl, res_letterbox r - LEFT JOIN entities en ON r.destination::text = en.entity_id::text - LEFT JOIN contacts_v2 cont ON r.exp_contact_id = cont.contact_id OR r.dest_contact_id = cont.contact_id - LEFT JOIN users u ON r.exp_user_id::text = u.user_id::text OR r.dest_user_id::text = u.user_id::text + LEFT JOIN entities en ON r.destination::text = en.entity_id::text WHERE r.type_id = d.type_id AND d.doctypes_first_level_id = dfl.doctypes_first_level_id AND d.doctypes_second_level_id = dsl.doctypes_second_level_id; diff --git a/migration/19.12/1912.sql b/migration/19.12/1912.sql index 8fbe6318ad4..de334a1fafa 100644 --- a/migration/19.12/1912.sql +++ b/migration/19.12/1912.sql @@ -426,6 +426,27 @@ CREATE TABLE contacts ) WITH (OIDS=FALSE); +DROP TABLE IF EXISTS contacts_parameters; +CREATE TABLE contacts_parameters +( + id SERIAL NOT NULL, + identifier text NOT NULL, + mandatory boolean NOT NULL DEFAULT FALSE, + filling boolean NOT NULL DEFAULT FALSE, + searchable boolean NOT NULL DEFAULT FALSE, + displayable boolean NOT NULL DEFAULT FALSE, + CONSTRAINT contacts_parameters_pkey PRIMARY KEY (id) +) +WITH (OIDS=FALSE); + +ALTER TABLE acknowledgement_receipts DROP COLUMN IF EXISTS contact_id; +ALTER TABLE acknowledgement_receipts ADD COLUMN contact_id integer; +ALTER TABLE contacts_groups_lists DROP COLUMN IF EXISTS contact_id; +ALTER TABLE contacts_groups_lists ADD COLUMN contact_id integer; +ALTER TABLE res_attachments DROP COLUMN IF EXISTS contact_id; +ALTER TABLE res_attachments ADD COLUMN contact_id integer; +ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_user_id; +ALTER TABLE res_attachments ADD COLUMN dest_user_id integer; /* REFACTORING DATA */ DO $$ BEGIN diff --git a/migration/19.12/migrateContacts.php b/migration/19.12/migrateContacts.php index 26f09cb6c2b..7e03726b0f5 100644 --- a/migration/19.12/migrateContacts.php +++ b/migration/19.12/migrateContacts.php @@ -27,6 +27,10 @@ foreach ($customs as $custom) { 'table' => 'contacts_custom_fields_list', 'where' => ['id > 0'] ]); + \SrcCore\models\DatabaseModel::delete([ + 'table' => 'contacts_parameters', + 'where' => ['id > 0'] + ]); $migrated = 0; $contactsInfo = \SrcCore\models\DatabaseModel::select([ @@ -38,7 +42,7 @@ foreach ($customs as $custom) { 'table' => ['view_contacts'] ]); - //RM + // Fields not migrated //contact_user_id, contact_enabled, contact_entity_id, entity_id, is_private, is_corporate_person, contact_type, contact_purpose_id $contactTypes = \SrcCore\models\DatabaseModel::select([ @@ -58,12 +62,14 @@ foreach ($customs as $custom) { ['oldId' => 'salutation_footer', 'label' => 'Formule de politesse (Fin)', 'type' => 'string', 'value' => ['']], ['oldId' => 'website', 'label' => 'Site internet', 'type' => 'string', 'value' => ['']], ['oldId' => 'contact_type_label', 'label' => 'Type de contact', 'type' => 'select', 'value' => $contactTypes], - ['oldId' => 'contact_purpose_label', 'label' => 'Dénomination', 'type' => 'string', 'value' => $contactPurposes], + ['oldId' => 'contact_purpose_label', 'label' => 'Dénomination', 'type' => 'select', 'value' => $contactPurposes], ['oldId' => 'society_short', 'label' => 'Sigle de la structure', 'type' => 'string', 'value' => ['']], ]; $newCustomFields = addCustomFields(['customFields' => $customFields]); + $firstMan = \User\models\UserModel::get(['select' => ['id'], 'orderBy' => ['id'], 'limit' => 1, 'where' => ['status = ?'], 'data' => ['OK']]); + foreach ($contactsInfo as $contactInfo) { $oldContactId = $contactInfo['contact_id']; $oldAddressId = $contactInfo['ca_id']; @@ -125,7 +131,6 @@ foreach ($customs as $custom) { // Creator $creator = \User\models\UserModel::getByLogin(['select' => ['id'], 'login' => $contactInfo['user_id']]); if (empty($creator)) { - $firstMan = \User\models\UserModel::get(['select' => ['id'], 'orderBy' => ['id'], 'limit' => 1, 'where' => ['status = ?'], 'data' => ['OK']]); $contactInfo['creator'] = $firstMan[0]['id']; } else { $contactInfo['creator'] = $creator['id']; @@ -139,13 +144,13 @@ foreach ($customs as $custom) { // Enabled $contactInfo['enabled'] = $contactInfo['enabled'] == 'Y' ? 'true' : 'false'; - $contactCustomInfo= [ - 'salutation_header' => $contactInfo['salutation_header'], - 'salutation_footer' => $contactInfo['salutation_footer'], - 'website' => $contactInfo['website'], - 'contact_type_label' => $contactInfo['contact_type_label'], + $contactCustomInfo = [ + 'salutation_header' => $contactInfo['salutation_header'], + 'salutation_footer' => $contactInfo['salutation_footer'], + 'website' => $contactInfo['website'], + 'contact_type_label' => $contactInfo['contact_type_label'], 'contact_purpose_label' => $contactInfo['contact_purpose_label'], - 'society_short' => $contactInfo['society_short'], + 'society_short' => $contactInfo['society_short'], ]; unset($contactInfo['salutation_header']); @@ -157,15 +162,39 @@ foreach ($customs as $custom) { $id = \Contact\models\ContactModel::create($contactInfo); migrateCustomField(['newContactId' => $id, 'contactCustomInfo' => $contactCustomInfo, 'newCustomFields' => $newCustomFields]); + migrateAcknowledgementReceipt(['oldAddressId' => $oldAddressId, 'newContactId' => $id]); + migrateContactGroupsLists(['oldAddressId' => $oldAddressId, 'newContactId' => $id]); + migrateContactRes(['oldAddressId' => $oldAddressId, 'oldContactId' => $oldContactId, 'newContactId' => $id]); + migrateResourceContacts(['oldAddressId' => $oldAddressId, 'newContactId' => $id]); + migrateResAttachments(['oldAddressId' => $oldAddressId, 'oldContactId' => $oldContactId, 'newContactId' => $id]); + migrateResletterbox(['oldAddressId' => $oldAddressId, 'newContactId' => $id]); $migrated++; } - printf("Migration version attachement (CUSTOM {$custom}) : " . $migrated . " Version(s) trouvée(s) et migrée(s).\n"); + migrateContactRes_Users(); + migrateResletterbox_Users(); + migrateResattachments_Users(); + migrateContactParameters(); + \SrcCore\models\DatabaseModel::update([ + 'set' => ['type' => 'contact'], + 'table' => 'resource_contacts', + 'where' => ['type = ?'], + 'data' => ['contact_v3'] + ]); + + printf("Migration version attachement (CUSTOM {$custom}) : " . $migrated . " Contact(s) trouvée(s) et migrée(s).\n"); } function addCustomFields($args = []) { + $fillingValues = \SrcCore\models\DatabaseModel::select([ + 'select' => ['rating_columns'], + 'table' => ['contacts_filling'] + ]); + + $fillingValues = json_decode($fillingValues[0]['rating_columns']); + $customFields = []; foreach ($args['customFields'] as $value) { $customFieldId = \Contact\models\ContactCustomFieldListModel::create([ @@ -173,6 +202,21 @@ function addCustomFields($args = []) 'type' => $value['type'], 'values' => json_encode($value['value']) ]); + + $filling = 'false'; + if (in_array($value['oldId'], $fillingValues)) { + $filling = 'true'; + } + \SrcCore\models\DatabaseModel::insert([ + 'table' => 'contacts_parameters', + 'columnsValues' => [ + 'identifier' => 'contactCustomField_' . $customFieldId, + 'mandatory' => 'false', + 'filling' => $filling, + 'searchable' => 'false', + 'displayable' => 'false', + ] + ]); $customFields[$value['oldId']] = $customFieldId; } @@ -181,13 +225,252 @@ function addCustomFields($args = []) function migrateCustomField($args = []) { + $customFields = []; foreach ($args['contactCustomInfo'] as $key => $value) { if (!empty($value)) { - \Contact\models\ContactCustomFieldModel::create([ + $id = \Contact\models\ContactCustomFieldModel::create([ 'contact_id' => $args['newContactId'], 'custom_field_id' => $args['newCustomFields'][$key], 'value' => json_encode($value) ]); + $customFields[$key] = $id; + } + } +} + +function migrateAcknowledgementReceipt($args = []) +{ + \SrcCore\models\DatabaseModel::update([ + 'set' => ['contact_id' => $args['newContactId']], + 'table' => 'acknowledgement_receipts', + 'where' => ['contact_address_id = ?'], + 'data' => [$args['oldAddressId']] + ]); +} + +function migrateContactGroupsLists($args = []) +{ + \SrcCore\models\DatabaseModel::update([ + 'set' => ['contact_id' => $args['newContactId']], + 'table' => 'contacts_groups_lists', + 'where' => ['contact_addresses_id = ?'], + 'data' => [$args['oldAddressId']] + ]); +} + +function migrateContactRes($args = []) +{ + $contactRes = \SrcCore\models\DatabaseModel::select([ + 'select' => ['res_id'], + 'table' => ['contacts_res'], + 'where' => ['contact_id = ?', 'address_id = ?'], + 'data' => [$args['oldContactId'], $args['oldAddressId']], + ]); + + foreach ($contactRes as $value) { + $resInfo = \SrcCore\models\DatabaseModel::select([ + 'select' => ['category_id'], + 'table' => ['res_letterbox'], + 'where' => ['res_id = ?'], + 'data' => [$value['res_id']] + ]); + + $mode = 'sender'; + if ($resInfo[0]['category_id'] == 'outgoing') { + $mode = 'recipient'; + } + + \Resource\models\ResourceContactModel::create([ + 'res_id' => $value['res_id'], + 'item_id' => $args['newContactId'], + 'type' => 'contact_v3', + 'mode' => $mode + ]); + } +} + +function migrateResourceContacts($args = []) +{ + \SrcCore\models\DatabaseModel::update([ + 'set' => ['item_id' => $args['newContactId'], 'type' => 'contact_v3'], + 'table' => 'resource_contacts', + 'where' => ['item_id = ?', 'type = ?'], + 'data' => [$args['oldAddressId'], 'contact'] + ]); +} + +function migrateResAttachments($args = []) +{ + \SrcCore\models\DatabaseModel::update([ + 'set' => ['contact_id' => $args['newContactId']], + 'table' => 'res_attachments', + 'where' => ['dest_contact_id = ?', 'dest_address_id = ?'], + 'data' => [$args['oldContactId'], $args['oldAddressId']], + ]); +} + +function migrateResletterbox($args = []) +{ + $resInfo = \SrcCore\models\DatabaseModel::select([ + 'select' => ['res_id', 'category_id'], + 'table' => ['res_letterbox'], + 'where' => ['address_id = ?'], + 'data' => [$args['oldAddressId']], + ]); + + foreach ($resInfo as $value) { + $mode = 'sender'; + if ($value['category_id'] == 'outgoing') { + $mode = 'recipient'; } + + \Resource\models\ResourceContactModel::create([ + 'res_id' => $value['res_id'], + 'item_id' => $args['newContactId'], + 'type' => 'contact_v3', + 'mode' => $mode + ]); + } +} + +function migrateContactRes_Users() +{ + $userContactRes = \SrcCore\models\DatabaseModel::select([ + 'select' => ['res_id', 'contact_id'], + 'table' => ['contacts_res'], + 'where' => ['address_id = 0'] + ]); + + $firstMan = \User\models\UserModel::get(['select' => ['id'], 'orderBy' => ['id'], 'limit' => 1, 'where' => ['status = ?'], 'data' => ['OK']]); + foreach ($userContactRes as $value) { + $resInfo = \SrcCore\models\DatabaseModel::select([ + 'select' => ['category_id'], + 'table' => ['res_letterbox'], + 'where' => ['res_id = ?'], + 'data' => [$value['res_id']] + ]); + + $user = \User\models\UserModel::getByLogin(['login' => $value['contact_id'], 'select' => ['id']]); + if (empty($user)) { + $user = $firstMan[0]['id']; + } else { + $user = $user['id']; + } + + $mode = 'sender'; + if ($resInfo[0]['category_id'] == 'outgoing') { + $mode = 'recipient'; + } + + \Resource\models\ResourceContactModel::create([ + 'res_id' => $value['res_id'], + 'item_id' => $user, + 'type' => 'user', + 'mode' => $mode + ]); + } +} + +function migrateResletterbox_Users() +{ + $userContact = \SrcCore\models\DatabaseModel::select([ + 'select' => ['res_id', 'exp_user_id', 'dest_user_id'], + 'table' => ['res_letterbox'], + 'where' => ['(exp_user_id != \'\' and exp_user_id is not null) or (dest_user_id != \'\' and dest_user_id is not null)'] + ]); + + $firstMan = \User\models\UserModel::get(['select' => ['id'], 'orderBy' => ['id'], 'limit' => 1, 'where' => ['status = ?'], 'data' => ['OK']]); + foreach ($userContact as $value) { + if (!empty($value['exp_user_id'])) { + $login = $value['exp_user_id']; + $mode = 'sender'; + } else { + $login = $value['dest_user_id']; + $mode = 'recipient'; + } + $user = \User\models\UserModel::getByLogin(['login' => $login, 'select' => ['id']]); + if (empty($user)) { + $user = $firstMan[0]['id']; + } else { + $user = $user['id']; + } + + \Resource\models\ResourceContactModel::create([ + 'res_id' => $value['res_id'], + 'item_id' => $user, + 'type' => 'user', + 'mode' => $mode + ]); + } +} + +function migrateResattachments_Users() +{ + $attachments = \SrcCore\models\DatabaseModel::select([ + 'select' => ['dest_user', 'res_id'], + 'table' => ['res_attachments'], + 'where' => ['dest_user != \'\' and dest_user is not null'] + ]); + + $firstMan = \User\models\UserModel::get(['select' => ['id'], 'orderBy' => ['id'], 'limit' => 1, 'where' => ['status = ?'], 'data' => ['OK']]); + foreach ($attachments as $value) { + $user = \User\models\UserModel::getByLogin(['login' => $value['dest_user'], 'select' => ['id']]); + if (empty($user)) { + $user = $firstMan[0]['id']; + } else { + $user = $user['id']; + } + + \SrcCore\models\DatabaseModel::update([ + 'set' => ['dest_user_id' => $user], + 'table' => 'res_attachments', + 'where' => ['res_id = ?'], + 'data' => [$value['res_id']], + ]); + } +} + +function migrateContactParameters() +{ + $fillingValues = \SrcCore\models\DatabaseModel::select([ + 'select' => ['rating_columns'], + 'table' => ['contacts_filling'] + ]); + + $fillingValues = json_decode($fillingValues[0]['rating_columns']); + + $contactParameters = [ + ['oldIdentifier' => 'title', 'identifier' => 'civility', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'false', 'displayable' => 'false'], + ['oldIdentifier' => 'firstname', 'identifier' => 'firstname', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'true', 'displayable' => 'true'], + ['oldIdentifier' => 'lastname', 'identifier' => 'lastname', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'true', 'displayable' => 'true'], + ['oldIdentifier' => 'society', 'identifier' => 'company', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'true', 'displayable' => 'true'], + ['oldIdentifier' => 'departement', 'identifier' => 'department', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'false', 'displayable' => 'false'], + ['oldIdentifier' => 'function', 'identifier' => 'function', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'false', 'displayable' => 'false'], + ['oldIdentifier' => 'address_num', 'identifier' => 'address_number', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'true', 'displayable' => 'true'], + ['oldIdentifier' => 'address_street', 'identifier' => 'address_street', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'true', 'displayable' => 'true'], + ['oldIdentifier' => 'occupancy', 'identifier' => 'address_additional1', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'false', 'displayable' => 'false'], + ['oldIdentifier' => 'address_complement', 'identifier' => 'address_additional2', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'false', 'displayable' => 'false'], + ['oldIdentifier' => 'address_postal_code', 'identifier' => 'address_postcode', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'false', 'displayable' => 'false'], + ['oldIdentifier' => 'address_town', 'identifier' => 'address_town', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'true', 'displayable' => 'true'], + ['oldIdentifier' => 'address_country', 'identifier' => 'address_country', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'false', 'displayable' => 'false'], + ['oldIdentifier' => 'email', 'identifier' => 'email', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'false', 'displayable' => 'false'], + ['oldIdentifier' => 'phone', 'identifier' => 'phone', 'mandatory' => 'false', 'filling' => 'false', 'searchable' => 'false', 'displayable' => 'false'], + ]; + + foreach ($contactParameters as $value) { + $filling = 'false'; + if (in_array($value['oldIdentifier'], $fillingValues)) { + $filling = 'true'; + } + \SrcCore\models\DatabaseModel::insert([ + 'table' => 'contacts_parameters', + 'columnsValues' => [ + 'identifier' => $value['identifier'], + 'mandatory' => $value['mandatory'], + 'filling' => $filling, + 'searchable' => $value['searchable'], + 'displayable' => $value['displayable'], + ] + ]); } } diff --git a/sql/structure.sql b/sql/structure.sql index ba4efe2d2f0..03288718408 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -264,12 +264,11 @@ CREATE TABLE res_attachments effective_date timestamp without time zone, work_batch bigint, origin character varying(50) DEFAULT NULL::character varying, - dest_user character varying(128) DEFAULT NULL::character varying, + dest_user_id INTEGER, res_id_master bigint, origin_id INTEGER, attachment_type character varying(255) DEFAULT NULL::character varying, - dest_contact_id bigint, - dest_address_id bigint, + contact_id integer, in_signature_book boolean DEFAULT FALSE, in_send_attach boolean DEFAULT FALSE, signatory_user_serial_id int, @@ -834,122 +833,18 @@ CREATE TABLE contacts ) WITH (OIDS=FALSE); -CREATE SEQUENCE query_id_seq - INCREMENT 1 - MINVALUE 1 - MAXVALUE 9223372036854775807 - START 10 - CACHE 1; - - -- multicontacts -CREATE TABLE contacts_res -( - coll_id character varying(32) NOT NULL, - res_id bigint NOT NULL, - contact_id character varying(128) NOT NULL, - address_id bigint NOT NULL, - mode character varying NOT NULL DEFAULT 'multi'::character varying - ); - --- contacts v2 -CREATE SEQUENCE contact_types_id_seq - INCREMENT 1 - MINVALUE 1 - MAXVALUE 9223372036854775807 - START 200 - CACHE 1; - -CREATE TABLE contact_types -( - id bigint NOT NULL DEFAULT nextval('contact_types_id_seq'::regclass), - label character varying(255) NOT NULL, - can_add_contact character varying(1) NOT NULL DEFAULT 'Y'::character varying, - contact_target character varying(50), - CONSTRAINT contact_types_pkey PRIMARY KEY (id) -) WITH (OIDS=FALSE); - -CREATE SEQUENCE contact_v2_id_seq - INCREMENT 1 - MINVALUE 1 - MAXVALUE 9223372036854775807 - START 100 - CACHE 1; - -CREATE TABLE contacts_v2 -( - contact_id bigint NOT NULL DEFAULT nextval('contact_v2_id_seq'::regclass), - contact_type bigint NOT NULL, - is_corporate_person character(1) DEFAULT 'Y'::bpchar, - is_external_contact character(1) DEFAULT 'N'::bpchar, - society character varying(255), - society_short character varying(32), - firstname character varying(255), - lastname character varying(255), - title character varying(255), - function character varying(255), - other_data text, - user_id character varying(255) NOT NULL, - entity_id character varying(32) NOT NULL, - creation_date timestamp without time zone NOT NULL, - update_date timestamp without time zone, - enabled character varying(1) NOT NULL DEFAULT 'Y'::bpchar, - CONSTRAINT contacts_v2_pkey PRIMARY KEY (contact_id) -) WITH (OIDS=FALSE); - -CREATE SEQUENCE contact_purposes_id_seq - INCREMENT 1 - MINVALUE 1 - MAXVALUE 9223372036854775807 - START 100 - CACHE 1; - -CREATE TABLE contact_purposes -( - id bigint NOT NULL DEFAULT nextval('contact_purposes_id_seq'::regclass), - label character varying(255) NOT NULL, - CONSTRAINT contact_purposes_pkey PRIMARY KEY (id) -) WITH (OIDS=FALSE); - -CREATE SEQUENCE contact_addresses_id_seq - INCREMENT 1 - MINVALUE 1 - MAXVALUE 9223372036854775807 - START 100 - CACHE 1; - -CREATE TABLE contact_addresses +CREATE TABLE contacts_parameters ( - id bigint NOT NULL DEFAULT nextval('contact_addresses_id_seq'::regclass), - contact_id bigint NOT NULL, - contact_purpose_id bigint DEFAULT 1, - departement character varying(255), - firstname character varying(255), - lastname character varying(255), - title character varying(255), - function character varying(255), - occupancy character varying(1024), - address_num character varying(32) , - address_street character varying(255), - address_complement character varying(255), - address_town character varying(255), - address_postal_code character varying(255), - address_country character varying(255), - phone character varying(20), - email character varying(255), - website character varying(255), - salutation_header character varying(255), - salutation_footer character varying(255), - other_data character varying(255), - user_id character varying(255) NOT NULL, - entity_id character varying(32) NOT NULL, - is_private character(1) NOT NULL DEFAULT 'N'::bpchar, - enabled character varying(1) NOT NULL DEFAULT 'Y'::bpchar, - external_id jsonb DEFAULT '{}', - ban_id character varying(128), - CONSTRAINT contact_addresses_pkey PRIMARY KEY (id) -) WITH (OIDS=FALSE); + id SERIAL NOT NULL, + identifier text NOT NULL, + mandatory boolean NOT NULL DEFAULT FALSE, + filling boolean NOT NULL DEFAULT FALSE, + searchable boolean NOT NULL DEFAULT FALSE, + displayable boolean NOT NULL DEFAULT FALSE, + CONSTRAINT contacts_parameters_pkey PRIMARY KEY (id) +) +WITH (OIDS=FALSE); -DROP TABLE IF EXISTS contacts_groups; CREATE TABLE contacts_groups ( id serial, @@ -963,17 +858,23 @@ CREATE TABLE contacts_groups ) WITH (OIDS=FALSE); -DROP TABLE IF EXISTS contacts_groups_lists; CREATE TABLE contacts_groups_lists ( id serial, contacts_groups_id integer NOT NULL, - contact_addresses_id integer NOT NULL, + contact_id integer NOT NULL, CONSTRAINT contacts_groups_lists_pkey PRIMARY KEY (id), - CONSTRAINT contacts_groups_lists_key UNIQUE (contacts_groups_id, contact_addresses_id) + CONSTRAINT contacts_groups_lists_key UNIQUE (contacts_groups_id, contact_id) ) WITH (OIDS=FALSE); +CREATE SEQUENCE query_id_seq + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 10 + CACHE 1; + CREATE TABLE saved_queries ( query_id bigint NOT NULL DEFAULT nextval('query_id_seq'::regclass), user_id character varying(128) default NULL, @@ -986,25 +887,6 @@ CREATE TABLE saved_queries ( CONSTRAINT saved_queries_pkey PRIMARY KEY (query_id) ) WITH (OIDS=FALSE); -DROP SEQUENCE IF EXISTS contact_communication_id_seq CASCADE; -CREATE SEQUENCE contact_communication_id_seq -INCREMENT 1 -MINVALUE 1 -MAXVALUE 9223372036854775807 -START 1 -CACHE 1; - -DROP TABLE IF EXISTS contact_communication; -CREATE TABLE contact_communication -( - id bigint NOT NULL DEFAULT nextval('contact_communication_id_seq'::regclass), - contact_id bigint NOT NULL, - type character varying(255) NOT NULL, - value character varying(255) NOT NULL, - CONSTRAINT contact_communication_pkey PRIMARY KEY (id) -) WITH (OIDS=FALSE); - - CREATE SEQUENCE doctypes_first_level_id_seq INCREMENT 1 MINVALUE 1 @@ -1112,10 +994,6 @@ CREATE TABLE res_letterbox barcode text, external_signatory_book_id integer, category_id character varying(32) NOT NULL, - exp_contact_id integer, - exp_user_id character varying(128), - dest_contact_id integer, - dest_user_id character varying(128), alt_identifier character varying(255), admission_date timestamp without time zone, process_limit_date timestamp without time zone, @@ -1124,7 +1002,6 @@ CREATE TABLE res_letterbox alarm2_date timestamp without time zone, flag_alarm1 char(1) default 'N'::character varying, flag_alarm2 char(1) default 'N'::character varying, - is_multicontacts char(1), address_id bigint, model_id integer NOT NULL, CONSTRAINT res_letterbox_pkey PRIMARY KEY (res_id) @@ -1321,11 +1198,6 @@ SELECT r.res_id, r.dest_user, r.confidentiality, r.category_id, - r.exp_contact_id, - r.exp_user_id, - r.dest_user_id, - r.dest_contact_id, - r.address_id, r.alt_identifier, r.admission_date, r.process_limit_date, @@ -1334,43 +1206,18 @@ SELECT r.res_id, r.alarm2_date, r.flag_alarm1, r.flag_alarm2, - r.is_multicontacts, r.subject, r.priority, r.locker_user_id, r.locker_time, en.entity_label, - en.entity_type AS entitytype, - cont.contact_id, - cont.firstname AS contact_firstname, - cont.lastname AS contact_lastname, - cont.society AS contact_society, - u.lastname AS user_lastname, - u.firstname AS user_firstname + en.entity_type AS entitytype FROM doctypes d, doctypes_first_level dfl, doctypes_second_level dsl, res_letterbox r - LEFT JOIN entities en ON r.destination::text = en.entity_id::text - LEFT JOIN contacts_v2 cont ON r.exp_contact_id = cont.contact_id OR r.dest_contact_id = cont.contact_id - LEFT JOIN users u ON r.exp_user_id::text = u.user_id::text OR r.dest_user_id::text = u.user_id::text + LEFT JOIN entities en ON r.destination::text = en.entity_id::text WHERE r.type_id = d.type_id AND d.doctypes_first_level_id = dfl.doctypes_first_level_id AND d.doctypes_second_level_id = dsl.doctypes_second_level_id; - - ---view for contacts_v2 -DROP VIEW IF EXISTS view_contacts; -CREATE OR REPLACE VIEW view_contacts AS - SELECT c.contact_id, c.contact_type, c.is_corporate_person, c.society, c.society_short, c.firstname AS contact_firstname -, c.lastname AS contact_lastname, c.title AS contact_title, c.function AS contact_function, c.other_data AS contact_other_data -, c.user_id AS contact_user_id, c.entity_id AS contact_entity_id, c.creation_date, c.update_date, c.enabled AS contact_enabled, ca.id AS ca_id -, ca.contact_purpose_id, ca.departement, ca.firstname, ca.lastname, ca.title, ca.function, ca.occupancy -, ca.address_num, ca.address_street, ca.address_complement, ca.address_town, ca.address_postal_code, ca.address_country -, ca.phone, ca.email, ca.website, ca.salutation_header, ca.salutation_footer, ca.other_data, ca.user_id, ca.entity_id, ca.is_private, ca.enabled, ca.external_id -, cp.label as contact_purpose_label, ct.label as contact_type_label - FROM contacts_v2 c - RIGHT JOIN contact_addresses ca ON c.contact_id = ca.contact_id - LEFT JOIN contact_purposes cp ON ca.contact_purpose_id = cp.id - LEFT JOIN contact_types ct ON c.contact_type = ct.id; CREATE FUNCTION order_alphanum(text) RETURNS text AS $$ SELECT regexp_replace(regexp_replace(regexp_replace(regexp_replace($1, @@ -1492,7 +1339,6 @@ CREATE TABLE contacts_filling ( id serial NOT NULL, enable boolean NOT NULL, - rating_columns text NOT NULL, first_threshold int NOT NULL, second_threshold int NOT NULL, CONSTRAINT contacts_filling_pkey PRIMARY KEY (id) @@ -1561,7 +1407,7 @@ res_id INTEGER NOT NULL, type CHARACTER VARYING(16) NOT NULL, format CHARACTER VARYING(8) NOT NULL, user_id INTEGER NOT NULL, -contact_address_id INTEGER NOT NULL, +contact_id INTEGER NOT NULL, creation_date timestamp without time zone NOT NULL, send_date timestamp without time zone, docserver_id CHARACTER VARYING(128) NOT NULL, -- GitLab