PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 4.0.9
Visualizer – Tables & Charts Manager with Built-in AI Generator v4.0.9
4.0.9 4.0.8 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 All 150 releases
visualizer / classes / Visualizer / Module / Upgrade.php

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

78 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 $upgraded = false;
21
22 if ( version_compare( $last_version, '3.4.3', '<' ) ) {
23 self::makeAllTableChartsTabular();
24 $upgraded = true;
25 }
26
27 if ( ! $upgraded ) {
28 return;
29 }
30
31 update_option( 'visualizer-upgraded', Visualizer_Plugin::VERSION );
32
33 // this will help in debugging to know which version this was upgraded from.
34 update_option( 'visualizer-upgraded-from', $last_version );
35 }
36
37 /**
38 * All 'dataTable' and 'table' charts to become 'tabular'.
39 * All charts that do not have a library, to get the default library.
40 */
41 private static function makeAllTableChartsTabular() {
42 global $wpdb;
43
44 // old table charts may not specify the library.
45 $args = array(
46 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
47 'fields' => 'ids',
48 'post_status' => 'publish',
49 'meta_query' => array(
50 array(
51 'key' => Visualizer_Plugin::CF_CHART_LIBRARY,
52 'compare' => 'NOT EXISTS',
53 ),
54 array(
55 'key' => Visualizer_Plugin::CF_CHART_TYPE,
56 'value' => 'table',
57 ),
58 ),
59 );
60 $query = new WP_Query( $args );
61 while ( $query->have_posts() ) {
62 $id = $query->next_post();
63 add_post_meta( $id, Visualizer_Plugin::CF_CHART_LIBRARY, 'GoogleCharts' );
64 }
65
66 // make all dataTable and table chart types into tabular.
67 // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
68 $wpdb->query(
69 "UPDATE $wpdb->postmeta pm, $wpdb->posts p SET pm.meta_value = 'tabular'
70 WHERE p.post_type = '" . Visualizer_Plugin::CPT_VISUALIZER . "'
71 AND p.id = pm.post_id
72 AND pm.meta_key = '" . Visualizer_Plugin::CF_CHART_TYPE . "'
73 AND pm.meta_value IN ( 'dataTable', 'table' )"
74 );
75 // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
76 }
77 }
78