PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.10.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.10.2
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
visualizer / classes / Visualizer / Module / Upgrade.php

Upgrade.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.10.2, at classes/Visualizer/Module/Upgrade.php

77 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * General module to upgrade configuration/charts.
5 *
6 * @category Visualizer
7 * @package Module
8 *
9 * @since 3.4.3
10 */
11 class Visualizer_Module_Upgrade extends Visualizer_Module {
12
13 const NAME = __CLASS__;
14
15 /**
16 * Upgrades the configuration of charts, if required.
17 */
18 public static function upgrade() {
19 $last_version = get_option( 'visualizer-upgraded', '0.0.0' );
20
21 switch ( $last_version ) {
22 case '0.0.0':
23 self::makeAllTableChartsTabular();
24 break;
25 default:
26 return;
27 }
28
29 update_option( 'visualizer-upgraded', Visualizer_Plugin::VERSION );
30
31 // this will help in debugging to know which version this was upgraded from.
32 update_option( 'visualizer-upgraded-from', $last_version );
33 }
34
35 /**
36 * All 'dataTable' and 'table' charts to become 'tabular'.
37 * All charts that do not have a library, to get the default library.
38 */
39 private static function makeAllTableChartsTabular() {
40 global $wpdb;
41
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.
65 // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
66 $wpdb->query(
67 "UPDATE $wpdb->postmeta pm, $wpdb->posts p SET pm.meta_value = 'tabular'
68 WHERE p.post_type = '" . Visualizer_Plugin::CPT_VISUALIZER . "'
69 AND p.id = pm.post_id
70 AND pm.meta_key = '" . Visualizer_Plugin::CF_CHART_TYPE . "'
71 AND pm.meta_value IN ( 'dataTable', 'table' )"
72 );
73 // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
74
75 }
76 }
77