| @@ -153,10 +153,14 @@ | ||
| 153 | 153 | if ( defined( 'TI_UNIT_TESTING' ) ) { |
| 154 | 154 | return; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - if ( $plugin == VISUALIZER_BASENAME ) { | |
| 158 | - wp_redirect( admin_url( 'upload.php?page=' . Visualizer_Plugin::NAME ) ); | |
| 157 | + if ( $plugin === VISUALIZER_BASENAME ) { | |
| 158 | + if ( Visualizer_Module::numberOfCharts() > 0 ) { | |
| 159 | + wp_redirect( admin_url( 'admin.php?page=' . Visualizer_Plugin::NAME ) ); | |
| 160 | + } else { | |
| 161 | + wp_redirect( admin_url( 'admin.php?page=viz-support' ) ); | |
| 162 | + } | |
| 159 | 163 | exit(); |
| 160 | 164 | } |
| 161 | 165 | } |
| 162 | 166 | |
| @@ -191,28 +195,52 @@ | ||
| 191 | 195 | } |
| 192 | 196 | |
| 193 | 197 | // check if the source is correct. |
| 194 | 198 | $source = get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ); |
| 195 | - if ( $source !== 'Visualizer_Source_Query' ) { | |
| 196 | - return $chart; | |
| 197 | - } | |
| 199 | + $load_series = false; | |
| 200 | + switch ( $source ) { | |
| 201 | + case 'Visualizer_Source_Query': | |
| 202 | + // check if its a live-data chart or a cached-data chart. | |
| 203 | + if ( ! $force ) { | |
| 204 | + $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true ); | |
| 205 | + if ( ! empty( $hours ) ) { | |
| 206 | + // cached, bail! | |
| 207 | + return $chart; | |
| 208 | + } | |
| 209 | + } | |
| 198 | 210 | |
| 199 | - // check if its a live-data chart or a cached-data chart. | |
| 200 | - if ( ! $force ) { | |
| 201 | - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true ); | |
| 202 | - if ( ! empty( $hours ) ) { | |
| 203 | - // cached, bail! | |
| 211 | + $params = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY, true ); | |
| 212 | + $source = new Visualizer_Source_Query( $params ); | |
| 213 | + $source->fetch( false ); | |
| 214 | + $load_series = true; | |
| 215 | + break; | |
| 216 | + case 'Visualizer_Source_Json': | |
| 217 | + // check if its a live-data chart or a cached-data chart. | |
| 218 | + if ( ! $force ) { | |
| 219 | + $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true ); | |
| 220 | + if ( ! empty( $hours ) ) { | |
| 221 | + // cached, bail! | |
| 222 | + return $chart; | |
| 223 | + } | |
| 224 | + } | |
| 225 | + | |
| 226 | + $url = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, true ); | |
| 227 | + $root = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_ROOT, true ); | |
| 228 | + $paging = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_PAGING, true ); | |
| 229 | + $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ); | |
| 230 | + $source = new Visualizer_Source_Json( array( 'url' => $url, 'root' => $root, 'paging' => $paging ) ); | |
| 231 | + $source->refresh( $series ); | |
| 232 | + break; | |
| 233 | + default: | |
| 204 | 234 | return $chart; |
| 205 | - } | |
| 206 | 235 | } |
| 207 | 236 | |
| 208 | - $params = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY, true ); | |
| 209 | - $source = new Visualizer_Source_Query( $params ); | |
| 210 | - $source->fetch( false ); | |
| 211 | - | |
| 212 | 237 | $error = $source->get_error(); |
| 213 | 238 | if ( empty( $error ) ) { |
| 214 | - update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); | |
| 239 | + add_filter( 'wp_revisions_to_keep', '__return_false' ); | |
| 240 | + if ( $load_series ) { | |
| 241 | + update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); | |
| 242 | + } | |
| 215 | 243 | |
| 216 | 244 | wp_update_post( |
| 217 | 245 | array( |
| 218 | 246 | 'ID' => $chart_id, |