-
Notifications
You must be signed in to change notification settings - Fork 6
/
upgrade.php
272 lines (231 loc) · 6.48 KB
/
upgrade.php
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
/*
* Multi-version updates
*/
function qw_upgrade_13_to_current() {
qw_upgrade_13_to_132();
}
function qw_upgrade_132_to_current() {
qw_upgrade_132_to_14();
}
function qw_upgrade_14_to_current() {
qw_upgrade_14_to_15();
}
function qu_upgrade_12_to_current() {
qw_upgrade_12_to_13();
}
/*
* Upgrade from 1.4 to 1.5
*/
function qw_upgrade_14_to_15() {
// set the edit theme
update_option( 'qw_edit_theme', 'views' );
// get all queries
global $wpdb;
$table = $wpdb->prefix . "query_wrangler";
$sql = "SELECT * FROM " . $table;
$rows = $wpdb->get_results( $sql );
// loop through queries
foreach ( $rows as $query ) {
$data = qw_unserialize( $query->data );
// create new sort based on args[orderby], args[order]
if ( isset( $data['args']['orderby'] ) &&
isset( $data['args']['order'] )
) {
$orderby = $data['args']['orderby'];
unset( $data['args']['orderby'] );
$order = $data['args']['order'];
unset( $data['args']['order'] );
$data['args']['sorts'] = array();
$all_sorts = qw_all_sort_options();
// loop and find right of all_sorts to use for data
foreach ( $all_sorts as $hook_key => $sort ) {
if ( $orderby == $sort['type'] ) {
// set old sorting options as a new sort
$data['args']['sorts'][ $sort['type'] ] = array(
'type' => $sort['type'],
'hook_key' => $hook_key,
'name' => $sort['type'],
'weight' => 0,
'order_value' => $order,
);
break;
}
}
}
$path = $query->path;
// remove page path slashes
if ( substr( $path, 0, 1 ) == "/" ) {
$path = ltrim( $path, '/' );
}
// update old page path
$data['display']['page']['path'] = $path;
// save query
$update = array(
'path' => $path,
'data' => qw_serialize( $data ),
);
$where = array(
'id' => $query->id,
);
$wpdb->update( $table, $update, $where );
}
}
/*
* Upgrade from 1.3.2 to 1.4
*/
function qw_upgrade_132_to_14() {
// get all queries
global $wpdb;
$table = $wpdb->prefix . "query_wrangler";
$sql = "SELECT * FROM " . $table;
$rows = $wpdb->get_results( $sql );
// loop through queries
foreach ( $rows as $query ) {
$data = qw_unserialize( $query->data );
// display[type] = display[row_style]
if ( isset( $data['type'] ) ) {
$data['row_style'] = $data['type'];
unset( $data['type'] );
}
// display[full_settings][style] = display[post_settings][size]
if ( isset( $data['full_settings']['style'] ) ) {
$data['post_settings']['size'] = $data['full_settings']['style'];
unset( $data['full_settings']['style'] );
}
// filter post_status = args[post_status]
if ( empty( $data['args']['post_status'] ) ) {
if ( isset( $data['args']['filters']['post_status']['post_status'] ) ) {
$data['args']['post_status'] = $data['args']['filters']['post_status']['post_status'];
} else {
$data['args']['post_status'] = 'publish';
}
}
if ( isset( $data['args']['filters']['post_status'] ) ) {
unset( $data['args']['filters']['post_status'] );
}
// save query
$update = array(
'data' => qw_serialize( $data ),
);
$where = array(
'id' => $query->id,
);
$wpdb->update( $table, $update, $where );
}
// continue upgrade chain
qw_upgrade_14_to_15();
}
/*
* Upgrade from 1.3 to 1.3.2beta
*/
function qw_upgrade_13_to_132() {
// get all queries
global $wpdb;
$table = $wpdb->prefix . "query_wrangler";
$sql = "SELECT * FROM " . $table;
$rows = $wpdb->get_results( $sql );
//adjust arguments to filter values
foreach ( $rows as $query ) {
$data = qw_unserialize( $query->data );
// convert field settings style to style
if ( isset( $data['display']['field_settings']['style'] ) ) {
$data['display']['style'] = $data['display']['field_settings']['style'];
}
// convert 'full' type to 'posts'
if ( $data['display']['type'] == 'full' ) {
$data['display']['type'] = 'posts';
}
$update = array(
'data' => qw_serialize( $data ),
);
$where = array(
'id' => $query->id,
);
$wpdb->update( $table, $update, $where );
}
// next upgrade
qw_upgrade_132_to_14();
}
/*
* Upgrade from 1.2 (pre-plugin version option) to 1.3 (first version option)
*/
function qw_upgrade_12_to_13() {
// get all queries
global $wpdb;
$table = $wpdb->prefix . "query_wrangler";
$sql = "SELECT * FROM " . $table;
$rows = $wpdb->get_results( $sql );
//adjust arguments to filter values
foreach ( $rows as $query ) {
$data = qw_unserialize( $query->data );
$args = $data['args'];
$filter_weight = 0;
// post status
if ( isset( $args['post_status'] ) ) {
$args['filters']['post_status'] = array(
'type' => 'post_status',
'post_status' => $args['post_status'],
'weight' => $filter_weight,
);
$filter_weight ++;
unset( $args['post_status'] );
}
// post parent
if ( isset( $args['post_parent'] ) ) {
if ( $args['post_parent'] != '' ) {
$args['filters']['post_status'] = array(
'type' => 'post_status',
'post_status' => $args['post_status'],
'weight' => $filter_weight,
);
$filter_weight ++;
}
unset( $args['post_parent'] );
}
// categories
if ( isset( $args['cat'] ) ) {
$args['filters']['categories'] = array(
'type' => 'categories',
'cats' => $args['cat'],
'weight' => $filter_weight,
'cat_operator' => $args['cat_operator'],
);
$filter_weight ++;
unset( $args['cat'] );
}
// tags
if ( isset( $args['tag'] ) ) {
$args['filters']['tags'] = array(
'type' => 'tags',
'tags' => $args['tag'],
'weight' => $filter_weight,
'tag_operator' => $args['tag_operator'],
);
$filter_weight ++;
unset( $args['tag'] );
}
// post_types
if ( isset( $args['post_types'] ) ) {
$args['filters']['post_types'] = array(
'type' => 'post_types',
'post_types' => $args['post_types'],
'weight' => $filter_weight,
);
$filter_weight ++;
unset( $args['post_types'] );
}
unset( $args['cat_operator'] );
unset( $args['tag_operator'] );
$data['args'] = $args;
$update = array(
'data' => serialize( $data ),
);
$where = array(
'id' => $query->id,
);
$wpdb->update( $table, $update, $where );
}
// continue upgrading
qw_upgrade_13_to_132();
}