summaryrefslogtreecommitdiff
path: root/admin/upgrades/5.0.1.php
blob: b40ddc95e28c2f6fc1596c9f7e1b9e971aca008b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
 * @package contact
 */

global $gBitInstaller;

$gBitInstaller->registerPackageUpgrade(
	[
		'package'     => 'contact',
		'version'     => '5.0.1',
		'description' => 'Migrate contact_xref_type, contact_xref_source and contact_xref data into liberty_xref tables with content_type_guid=\'contact\'.',
	],
	[
		[ 'QUERY' => [
			'SQL92' => [
				// contact_xref_type: integer xref_type becomes sort_order; text source becomes the xref_type key
				"INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_group`
					(`x_group`, `content_type_guid`, `title`, `sort_order`, `role_id`, `type_href`)
				SELECT
					`source`, 'contact', `title`, `xref_type`, `role_id`, `type_href`
				FROM `" . BIT_DB_PREFIX . "contact_xref_type`",

				// contact_xref_source: integer xref_type joined to get the text key
				"INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref_item`
					(`item`, `content_type_guid`, `x_group`, `cross_ref_title`, `multiple`, `role_id`, `cross_ref_href`, `template`, `data`)
				SELECT
					cs.`source`, 'contact', ct.`source`, cs.`cross_ref_title`, cs.`multi`, cs.`role_id`, cs.`cross_ref_href`, cs.`template`, cs.`data`
				FROM `" . BIT_DB_PREFIX . "contact_xref_source` cs
				JOIN `" . BIT_DB_PREFIX . "contact_xref_type` ct ON cs.`xref_type` = ct.`xref_type`",

				// contact_xref: direct column mapping, xref_id preserved
				"INSERT INTO `" . BIT_DB_PREFIX . "liberty_xref`
					(`xref_id`, `content_id`, `item`, `xorder`, `xref`, `xkey`, `xkey_ext`, `data`, `start_date`, `last_update_date`, `entry_date`, `end_date`)
				SELECT
					`xref_id`, `content_id`, `source`, `xorder`, `xref`, `xkey`, `xkey_ext`, `data`, `start_date`, `last_update_date`, `entry_date`, `end_date`
				FROM `" . BIT_DB_PREFIX . "contact_xref`",
			],
		]],
	]
);