Skip to content

Commit 4e2c619

Browse files
add library meta key to upgraded old table charts
1 parent 94a680f commit 4e2c619

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

classes/Visualizer/Module/Upgrade.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,34 @@ public static function upgrade() {
3434

3535
/**
3636
* All 'dataTable' and 'table' charts to become 'tabular'.
37+
* All charts that do not have a library, to get the default library.
3738
*/
3839
private static function makeAllTableChartsTabular() {
3940
global $wpdb;
4041

42+
// old table charts may not specify the library.
43+
$args = array(
44+
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
45+
'fields' => 'ids',
46+
'post_status' => 'publish',
47+
'meta_query' => array(
48+
array(
49+
'key' => Visualizer_Plugin::CF_CHART_LIBRARY,
50+
'compare' => 'NOT EXISTS',
51+
),
52+
array(
53+
'key' => Visualizer_Plugin::CF_CHART_TYPE,
54+
'value' => 'table',
55+
),
56+
),
57+
);
58+
$query = new WP_Query( $args );
59+
while ( $query->have_posts() ) {
60+
$id = $query->next_post();
61+
add_post_meta( $id, Visualizer_Plugin::CF_CHART_LIBRARY, 'GoogleCharts' );
62+
}
63+
64+
// make all dataTable and table chart types into tabular.
4165
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
4266
$wpdb->query(
4367
"UPDATE $wpdb->postmeta pm, $wpdb->posts p SET pm.meta_value = 'tabular'
@@ -47,5 +71,6 @@ private static function makeAllTableChartsTabular() {
4771
AND pm.meta_value IN ( 'dataTable', 'table' )"
4872
);
4973
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
74+
5075
}
5176
}

0 commit comments

Comments
 (0)