Skip to content

Commit d42b04f

Browse files
authored
Merge pull request #840 from Codeinwp/bugfix/310
Add custom refresh time support for db chart
2 parents 402f03d + 60e61ed commit d42b04f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

classes/Visualizer/Module/Chart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ public function saveQuery() {
13441344
$hours = filter_input(
13451345
INPUT_POST,
13461346
'refresh',
1347-
FILTER_VALIDATE_INT,
1347+
FILTER_VALIDATE_FLOAT,
13481348
array(
13491349
'options' => array(
13501350
'min_range' => -1,
@@ -1353,7 +1353,7 @@ public function saveQuery() {
13531353
)
13541354
);
13551355

1356-
if ( ! is_int( $hours ) ) {
1356+
if ( ! is_numeric( $hours ) ) {
13571357
$hours = -1;
13581358
}
13591359

classes/Visualizer/Module/Setup.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function activate( $network_wide ) {
207207
*/
208208
private function activate_on_site() {
209209
wp_clear_scheduled_hook( 'visualizer_schedule_refresh_db' );
210-
wp_schedule_event( strtotime( 'midnight' ) - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS, 'hourly', 'visualizer_schedule_refresh_db' );
210+
wp_schedule_event( strtotime( 'midnight' ) - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS, apply_filters( 'visualizer_chart_schedule_interval', 'hourly' ), 'visualizer_schedule_refresh_db' );
211211
add_option( 'visualizer-activated', true );
212212
}
213213

@@ -394,6 +394,11 @@ public function refreshDbChart() {
394394

395395
// if the time is nigh, we force an update.
396396
$this->refresh_db_for_chart( null, $chart_id, true );
397+
// Clear existing chart cache.
398+
$cache_key = Visualizer_Plugin::CF_CHART_CACHE . '_' . $chart_id;
399+
if ( get_transient( $cache_key ) ) {
400+
delete_transient( $cache_key );
401+
}
397402
$hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
398403
$new_schedules[ $chart_id ] = time() + $hours * HOUR_IN_SECONDS;
399404
}

0 commit comments

Comments
 (0)