summaryrefslogtreecommitdiff
path: root/admin/upgrade_inc.php
blob: 5586d524c8dbfb2666b76c004c277f48dc6edf30 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php

global $gBitSystem, $gUpgradeFrom, $gUpgradeTo;

$upgrades = array(

	'BWR1' => array(
		'BWR2' => array(
			// STEP 1
array( 'QUERY' =>
array( 'PGSQL' => array(
	"ALTER TABLE `".BIT_DB_PREFIX."tiki_content` ADD `last_hit` INT8 NOT NULL DEFAULT 0,",
	"ALTER TABLE `".BIT_DB_PREFIX."tiki_content` ADD `event_time` INT8 NOT NULL DEFAULT 0,",
	"UPDATE `tiki_content` SET `last_hit` = `last_modified` ,`event_time` = 0;"
)),
),
		)
	),

'BONNIE' => array(
	'BWR1' => array(

// Step 0
array( 'QUERY' =>
array( 'PGSQL' => array(
	"ALTER TABLE `".BIT_DB_PREFIX."tiki_files_pkey` RENAME TO `".BIT_DB_PREFIX."tiki_old_files_pkey`",
)),
),

// Step 1
array( 'DATADICT' => array(
array( 'DROPTABLE' => array(
	'tiki_content'
)),
array( 'RENAMETABLE' => array(
		'tiki_files' => 'tiki_old_files',
)),

array( 'CREATE' => array (
	'tiki_plugins' => "
		plugin_guid C(16) PRIMARY,
		plugin_type C(16) NOTNULL,
		is_active C(1) NOTNULL DEFAULT 'y',
		plugin_description C(250),
		maintainer_url C(250)
	",

	'tiki_content_types' => "
		content_type_guid C(16) PRIMARY,
		content_description C(250) NOTNULL,
		maintainer_url C(250),
		handler_class C(128),
		handler_package C(128),
		handler_file C(128)
	",

	'tiki_content' => "
		content_id I4 PRIMARY,
		user_id I4 NOTNULL,
		modifier_user_id I4 NOTNULL,
		created I8 NOTNULL,
		last_modified I8 NOTNULL,
		content_type_guid C(16) NOTNULL,
		format_guid C(16) NOTNULL,
		hits I4 NOTNULL DEFAULT 0,
		language C(4),
		title C(160),
		ip C(39),
		data X
	",

	'tiki_attachments' => "
		attachment_id I4 PRIMARY,
		attachment_plugin_guid C(16) NOTNULL,
		content_id I4 NOTNULL,
		foreign_id I4 NOTNULL,
		user_id I4 NOTNULL,
		pos I4,
		hits I4,
		error_code I4,
		caption C(250)
		CONSTRAINTS ', CONSTRAINT `tiki_attachment_content_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."tiki_content`( `content_id` )
					  , CONSTRAINT `tiki_attachment_type_ref` FOREIGN KEY (`attachment_plugin_guid`) REFERENCES `".BIT_DB_PREFIX."tiki_plugins`( `plugin_guid` )'
	",

	'tiki_blobs' => "
		blob_id I4 PRIMARY,
		user_id I4 NOTNULL,
		blob_size I8 NOTNULL,
		blob_name C(250) NOTNULL,
		blob_data_type C(100) NOTNULL,
		blob_data B NOTNULL
	",

	'tiki_files' => "
		file_id I4 PRIMARY,
		user_id I4 NOTNULL,
		storage_path C(250),
		size I4,
		mime_type C(64)
	",
)),
array( 'RENAMECOLUMN' => array(
	'tiki_structures' => array(
		'`page_ref_id`' => 'structure_id I4 AUTO'
	),
	'tiki_link_cache' => array(
		'`cacheId`' => 'cache_id I4 AUTO'
	),
	'tiki_comments' => array(
		'`threadId`' => 'comment_id I4 AUTO',
		'`parentId`' => 'parent_id I4',
	)
)),

array( 'ALTER' => array(
	'tiki_structures' => array(
		'user_id' => array( 'user_id', 'I4' ),
		'content_id' => array( 'content_id', 'I4' ),
		'root_structure_id' => array( 'root_structure_id', 'I4' ),
	),
	'tiki_comments' => array(
		'content_id' => array( 'content_id', 'I4' ), // , 'NOTNULL' ),
	),

)),
)),

// Step 2
array( 'QUERY' =>
array( 'SQL92' => array(
	"UPDATE `".BIT_DB_PREFIX."tiki_structures` SET user_id=1",
	"INSERT INTO `".BIT_DB_PREFIX."tiki_preferences` ( `name`, `value`, `package` ) VALUES ( 'liberty_auto_display_attachment_thumbs', 'y', 'liberty' )",
	)),
/*
array( 'PGSQL' => array(
	"ALTER TABLE `".BIT_DB_PREFIX."tiki_structures` ALTER user_id SET NOT NULL"
	"ALTER TABLE `".BIT_DB_PREFIX."tiki_comments_content_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."tiki_content`( `content_id` )
	"ALTER TABLE `".BIT_DB_PREFIX."tiki_comments_parent_ref` FOREIGN KEY (`parent_id`) REFERENCES `".BIT_DB_PREFIX."tiki_content`( `content_id` )'
	"ALTER TABLE `".BIT_DB_PREFIX."tiki_content` ADD CONSTRAINT `tiki_content_guid_ref`  FOREIGN KEY (`format_guid`) REFERENCES ".BIT_DB_PREFIX."tiki_plugins( `plugin_guid` )"
	"ALTER TABLE `".BIT_DB_PREFIX."tiki_content` ADD CONSTRAINT `tiki_content_type_ref` FOREIGN KEY (`content_type_guid`) REFERENCES `".BIT_DB_PREFIX."tiki_content_types`( `content_type_guid` )" ),
)),

threadId
object
objectType
parentId
userName
type
points
votes
average
hash
summary
smiley
message_id
in_reply_to
comment_rating

commentDate
hits
data
title
user_ip

*/
),

// STEP 2
array( 'PHP' => '
	global $gBitSystem;
	$gBitSystem->mDb->CreateSequence( "tiki_attachments_id_seq", 1 );
	$gBitSystem->mDb->CreateSequence( "tiki_content_id_seq", 1 );
	$gBitSystem->mDb->CreateSequence( "tiki_files_file_id_seq", 1 );
	$max = $gBitSystem->mDb->getOne( "SELECT MAX(`comment_id`) FROM `'.BIT_DB_PREFIX.'tiki_comments`" );
	$gBitSystem->mDb->CreateSequence( "tiki_comments_comment_id_seq", $max + 1 );
	$max = $gBitSystem->mDb->getOne( "SELECT MAX(`structure_id`) FROM `'.BIT_DB_PREFIX.'tiki_structures`" );
	$gBitSystem->mDb->CreateSequence( "tiki_structures_id_seq", $max + 1 );

	$query = "SELECT `comment_id`, uu.`user_id`, uu.`user_id` AS `modifier_user_id`, `commentDate` AS `created`, `commentDate` AS `last_modified`, `hits`, `data`, `title`, `user_ip` AS `ip`
			  FROM `'.BIT_DB_PREFIX.'tiki_comments` tc INNER JOIN `'.BIT_DB_PREFIX.'users_users` uu ON( tc.`userName`=uu.`login` )";
	if( $rs = $gBitSystem->mDb->query( $query ) ) {
		while( !$rs->EOF ) {
			$commentId = $rs->fields["comment_id"]; unset( $rs->fields["comment_id"] );
			$conId = $gBitSystem->mDb->GenID( "tiki_content_id_seq" );
			$rs->fields["content_id"] = $conId;
			$rs->fields["content_type_guid"] = BITCOMMENT_CONTENT_TYPE_GUID;
			$rs->fields["format_guid"] = PLUGIN_GUID_TIKIWIKI;
			$gBitSystem->mDb->associateInsert( "tiki_content", $rs->fields );
			$gBitSystem->mDb->query( "UPDATE `'.BIT_DB_PREFIX.'tiki_comments` SET `content_id`=? WHERE `comment_id`=?", array( $conId, $commentId ) );
			$rs->MoveNext();
		}
	}


' ),

// STEP 3
array( 'DATADICT' => array(
	array( 'DROPCOLUMN' => array(
		'tiki_comments' => array( '`userName`', '`commentDate`','`hits`','`data`','`title`','`user_ip`' ),
	)),
	array( 'CREATEINDEX' => array(
		'tiki_content_title_idx' => array( 'tiki_content', '`title`', array() ),
		'tiki_content_user_idx' => array( 'tiki_content', '`user_id`', array() ),
		'tiki_content_moduser_idx' => array( 'tiki_content', '`modifier_user_id`', array() ),
		'tiki_content_hits_idx' => array( 'tiki_content', '`hits`', array() ),
		'tiki_comments_content_idx' => array( 'tiki_comments', '`content_id`', array() ),
		'tiki_struct_user_idx' => array( 'tiki_structures', '`user_id`', array() ),
		'tiki_struct_root_idx' => array( 'tiki_structures', '`root_structure_id`', array() ),
		'tiki_struct_content_idx' => array( 'tiki_structures', '`content_id`', array() ),
	)),
)),
	)
)

);

if( isset( $upgrades[$gUpgradeFrom][$gUpgradeTo] ) ) {
	$gBitSystem->registerUpgrade( LIBERTY_PKG_NAME, $upgrades[$gUpgradeFrom][$gUpgradeTo] );
}


?>