summaryrefslogtreecommitdiff
path: root/admin
diff options
context:
space:
mode:
Diffstat (limited to 'admin')
-rwxr-xr-xadmin/admin_contact_inc.php5
-rwxr-xr-xadmin/schema_inc.php39
-rw-r--r--admin/upgrades/5.0.3.php112
3 files changed, 138 insertions, 18 deletions
diff --git a/admin/admin_contact_inc.php b/admin/admin_contact_inc.php
index 5ea1ae2..dd47e5d 100755
--- a/admin/admin_contact_inc.php
+++ b/admin/admin_contact_inc.php
@@ -7,8 +7,7 @@
use Bitweaver\Contact\ContactType;
-$mTypes = new ContactType();
-$mTypes->setup();
+$contactTypeMarkers = ContactType::getTypeMarkerList();
$formContactListFeatures = [
"contact_list_id" => [
@@ -41,7 +40,7 @@ $formContactListFeatures = [
];
$gBitSmarty->assign( 'formContactListFeatures',$formContactListFeatures );
-foreach( $mTypes->mContactType as $key => $type ) {
+foreach( $contactTypeMarkers as $key => $type ) {
$option = 'contact_default_'.$key;
$contactChecks[] = $option;
$contactTypeDefaults[$option] = $type;
diff --git a/admin/schema_inc.php b/admin/schema_inc.php
index 50fc188..0fd9ebf 100755
--- a/admin/schema_inc.php
+++ b/admin/schema_inc.php
@@ -64,6 +64,7 @@ $gBitInstaller->registerPackageInfo( CONTACT_PKG_NAME, [
'dependencies' => 'liberty',
] );
+
// ### Indexes
$indices = [
'contact_parent_id_idx' => [ 'table' => 'contact', 'cols' => 'parent_id', 'opts' => null ],
@@ -75,24 +76,32 @@ $gBitInstaller->registerSchemaIndexes( CONTACT_PKG_NAME, $indices );
$gBitInstaller->registerSchemaSequences( CONTACT_PKG_NAME, [] );
// ### Defaults
-// xref configuration now lives in liberty_xref_group and liberty_xref_item (content_type_guid='contact').
-// These replace the old contact_xref_type and contact_xref_source table defaults.
+// Xref schema: shared groups/items at content_type_guid='contact'; type markers split by sub-type.
+// contactperson: 'type' group + $00 item. contactbusiness: 'type' group + $02-$05 items.
$gBitInstaller->registerSchemaDefault( CONTACT_PKG_NAME, [
- // --- liberty_xref_group (formerly contact_xref_type: integer xref_type → sort_order, source text → x_group) ---
- "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_group` (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`) VALUES ('type', 'contact','Contact Type List', 0,3,'')",
- "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_group` (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`) VALUES ('contact','contact','General Contact Details', 1,3,'')",
- "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_group` (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`) VALUES ('links', 'contact','Linked Contact Items', 2,3,'')",
- "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_group` (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`) VALUES ('account','contact','Account Details', 3,3,'')",
+ // --- liberty_content_types — sub-type handlers for person and business ---
+ "INSERT INTO `" . BIT_DB_PREFIX . "liberty_content_types` (`content_type_guid`,`content_name`,`content_name_plural`,`handler_class`,`handler_package`,`handler_file`,`maintainer_url`) VALUES ('contactperson','Person Contact','Person Contacts','ContactPerson','contact','ContactPerson.php','http://lsces.co.uk')",
+ "INSERT INTO `" . BIT_DB_PREFIX . "liberty_content_types` (`content_type_guid`,`content_name`,`content_name_plural`,`handler_class`,`handler_package`,`handler_file`,`maintainer_url`) VALUES ('contactbusiness','Business Contact','Business Contacts','ContactBusiness','contact','ContactBusiness.php','http://lsces.co.uk')",
+
+ // --- liberty_xref_group ---
+ // 'type' group split: one per sub-type (sort_order=0 = type-marker group, excluded from loadXrefInfo display)
+ "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_group` (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`) VALUES ('type','contactperson', 'Person Type', 0,3,'')",
+ "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_group` (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`) VALUES ('type','contactbusiness','Business Type List',0,3,'')",
+ // shared groups stay at 'contact' level (loaded via dual-guid IN filter)
+ "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_group` (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`) VALUES ('contact','contact','General Contact Details',1,3,'')",
+ "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_group` (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`) VALUES ('links', 'contact','Linked Contact Items', 2,3,'')",
+ "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_group` (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`) VALUES ('account','contact','Account Details', 3,3,'')",
- // --- liberty_xref_item (formerly contact_xref_source) ---
- // group: type
- "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('\$00','contact','type','Personal', 0,3,'/contact/?type=0', NULL)",
- "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('\$01','contact','type','Business', 0,3,'/contact/?type=1', NULL)",
- "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('\$02','contact','type','Manufacturer', 0,3,'/contact/?type=2', NULL)",
- "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('\$03','contact','type','Distributor', 0,3,'/contact/?type=3', NULL)",
- "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('\$04','contact','type','Supplier', 0,3,'/contact/?type=4', NULL)",
- "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('\$05','contact','type','MERG Kit Elf', 0,3,'/contact/?type=5', NULL)",
+ // --- liberty_xref_item ---
+ // group: type — person types
+ "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('P01','contactperson','type','Personal', 0,3,'',NULL)",
+ "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('P02','contactperson','type','MERG Kit Elf', 0,3,'',NULL)",
+ // group: type — business subtypes
+ "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('B01','contactbusiness','type','Service', 0,3,'',NULL)",
+ "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('B02','contactbusiness','type','Manufacturer', 0,3,'',NULL)",
+ "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('B03','contactbusiness','type','Distributor', 0,3,'',NULL)",
+ "INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('B04','contactbusiness','type','Supplier', 0,3,'',NULL)",
// group: contact
"INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('#C','contact','contact','Contact Address', 0,3,'../nlpg/?uprn=', 'address')",
"INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`) VALUES ('#E','contact','contact','eMail Address', 1,3,'../contact/?contact_id=','text' )",
diff --git a/admin/upgrades/5.0.3.php b/admin/upgrades/5.0.3.php
new file mode 100644
index 0000000..87c4989
--- /dev/null
+++ b/admin/upgrades/5.0.3.php
@@ -0,0 +1,112 @@
+<?php
+/**
+ * 5.0.3 — Introduce ContactPerson and ContactBusiness subclasses.
+ *
+ * Steps:
+ * 1. Insert liberty_content_types rows for contactperson and contactbusiness.
+ * 2. Insert liberty_xref_group 'type' rows at contactperson and contactbusiness level.
+ * 3. Insert xref_item rows with new P01/P02 and B01-B04 codes.
+ * 4. Delete the now-superseded 'type' group and $0x items from content_type_guid='contact'.
+ * 5. Migrate liberty_content: records with a $00 xref → contactperson; remainder → contactbusiness.
+ * 6. Rename existing liberty_xref type-tag rows from $0x to P0x/B0x.
+ *
+ * @package contact
+ */
+
+global $gBitInstaller;
+
+$X = BIT_DB_PREFIX;
+
+$gBitInstaller->registerPackageUpgrade(
+ [
+ 'package' => 'contact',
+ 'version' => '5.0.3',
+ 'description' => 'Introduce ContactPerson and ContactBusiness content type subclasses.',
+ ],
+ [
+ // --- Step 1: register content types ---
+ [ 'QUERY' => [ 'SQL92' => [
+ "UPDATE OR INSERT INTO `{$X}liberty_content_types`
+ (`content_type_guid`,`content_name`,`content_name_plural`,`handler_class`,`handler_package`,`handler_file`,`maintainer_url`)
+ VALUES ('contactperson','Person Contact','Person Contacts','ContactPerson','contact','ContactPerson.php','http://lsces.co.uk')
+ MATCHING (`content_type_guid`)",
+ "UPDATE OR INSERT INTO `{$X}liberty_content_types`
+ (`content_type_guid`,`content_name`,`content_name_plural`,`handler_class`,`handler_package`,`handler_file`,`maintainer_url`)
+ VALUES ('contactbusiness','Business Contact','Business Contacts','ContactBusiness','contact','ContactBusiness.php','http://lsces.co.uk')
+ MATCHING (`content_type_guid`)",
+ ]]],
+
+ // --- Step 2: xref_group 'type' rows ---
+ [ 'QUERY' => [ 'SQL92' => [
+ "UPDATE OR INSERT INTO `{$X}liberty_xref_group`
+ (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`)
+ VALUES ('type','contactperson','Person Type',0,3,'')
+ MATCHING (`x_group`,`content_type_guid`)",
+ "UPDATE OR INSERT INTO `{$X}liberty_xref_group`
+ (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`)
+ VALUES ('type','contactbusiness','Business Type List',0,3,'')
+ MATCHING (`x_group`,`content_type_guid`)",
+ ]]],
+
+ // --- Step 3: xref_item rows with new codes ---
+ [ 'QUERY' => [ 'SQL92' => [
+ // person types
+ "UPDATE OR INSERT INTO `{$X}liberty_xref_item`
+ (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`)
+ VALUES ('P01','contactperson','type','Personal',0,3,'',NULL)
+ MATCHING (`item`,`content_type_guid`)",
+ "UPDATE OR INSERT INTO `{$X}liberty_xref_item`
+ (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`)
+ VALUES ('P02','contactperson','type','MERG Kit Elf',0,3,'',NULL)
+ MATCHING (`item`,`content_type_guid`)",
+ // business subtypes
+ "UPDATE OR INSERT INTO `{$X}liberty_xref_item`
+ (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`)
+ VALUES ('B01','contactbusiness','type','Service',0,3,'',NULL)
+ MATCHING (`item`,`content_type_guid`)",
+ "UPDATE OR INSERT INTO `{$X}liberty_xref_item`
+ (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`)
+ VALUES ('B02','contactbusiness','type','Manufacturer',0,3,'',NULL)
+ MATCHING (`item`,`content_type_guid`)",
+ "UPDATE OR INSERT INTO `{$X}liberty_xref_item`
+ (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`)
+ VALUES ('B03','contactbusiness','type','Distributor',0,3,'',NULL)
+ MATCHING (`item`,`content_type_guid`)",
+ "UPDATE OR INSERT INTO `{$X}liberty_xref_item`
+ (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`)
+ VALUES ('B04','contactbusiness','type','Supplier',0,3,'',NULL)
+ MATCHING (`item`,`content_type_guid`)",
+ ]]],
+
+ // --- Step 4: remove old 'type' group and $0x items from contact ---
+ [ 'QUERY' => [ 'SQL92' => [
+ "DELETE FROM `{$X}liberty_xref_item` WHERE `content_type_guid` = 'contact' AND `x_group` = 'type'",
+ "DELETE FROM `{$X}liberty_xref_group` WHERE `content_type_guid` = 'contact' AND `x_group` = 'type'",
+ ]]],
+
+ // --- Step 5: migrate liberty_content records ---
+ // Person detection uses old $00 item (still present in liberty_xref at this point)
+ [ 'QUERY' => [ 'SQL92' => [
+ "UPDATE `{$X}liberty_content` SET `content_type_guid` = 'contactperson'
+ WHERE `content_type_guid` = 'contact'
+ AND `content_id` IN (
+ SELECT `content_id` FROM `{$X}liberty_xref` WHERE `item` = '\$00'
+ )",
+ "UPDATE `{$X}liberty_content` SET `content_type_guid` = 'contactbusiness'
+ WHERE `content_type_guid` = 'contact'",
+ ]]],
+
+ // --- Step 6: rename existing liberty_xref type-tag rows ---
+ // $00 (Personal name tag) → P01; $05 (Kit Elf) → P02
+ // $02 (Manufacturer) → B02; $03 (Distributor) → B03; $04 (Supplier) → B04
+ // $01 (deprecated Business) — deleted; B01 (Service) is new, no existing data
+ [ 'QUERY' => [ 'SQL92' => [
+ "UPDATE `{$X}liberty_xref` SET `item` = 'P01' WHERE `item` = '\$00'",
+ "UPDATE `{$X}liberty_xref` SET `item` = 'P02' WHERE `item` = '\$05'",
+ "UPDATE `{$X}liberty_xref` SET `item` = 'B02' WHERE `item` = '\$02'",
+ "UPDATE `{$X}liberty_xref` SET `item` = 'B03' WHERE `item` = '\$03'",
+ "UPDATE `{$X}liberty_xref` SET `item` = 'B04' WHERE `item` = '\$04'",
+ "DELETE FROM `{$X}liberty_xref` WHERE `item` = '\$01'",
+ ]]],
+ ]
+);