| 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 |
|