Skip to content

Commit 26165de

Browse files
chart does not update as per schedule
1 parent dfbe94c commit 26165de

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

classes/Visualizer/Module/Setup.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,11 @@ public function deactivate() {
165165
}
166166

167167
/**
168-
* Refresh the specific chart from the db. This is mostly for charts that have 0 refresh time i.e. live data.
168+
* Refresh the specific chart from the db.
169169
*
170170
* @param WP_Post $chart The chart object.
171171
* @param int $chart_id The chart id.
172-
* @param bool $force If this is true, then the chart data will be refreshed no matter if the chart requests live data or cached data.
173-
* If false, data will be refreshed only if the chart requests live data.
172+
* @param bool $force If this is true, then the chart data will be force refreshed. If false, data will be refreshed only if the chart requests live data.
174173
*
175174
* @access public
176175
*/
@@ -183,6 +182,16 @@ public function refresh_db_for_chart( $chart, $chart_id, $force = false ) {
183182
$chart = get_post( $chart_id );
184183
}
185184

185+
if ( ! $chart ) {
186+
return $chart;
187+
}
188+
189+
// check if the source is correct.
190+
$source = get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true );
191+
if ( $source !== 'Visualizer_Source_Query' ) {
192+
return $chart;
193+
}
194+
186195
// check if its a live-data chart or a cached-data chart.
187196
if ( ! $force ) {
188197
$hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
@@ -192,15 +201,11 @@ public function refresh_db_for_chart( $chart, $chart_id, $force = false ) {
192201
}
193202
}
194203

195-
// check if the source is correct.
196-
$source = get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true );
197-
if ( $source !== 'Visualizer_Source_Query_Params' ) {
198-
return $chart;
199-
}
200204

201205
$params = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY, true );
202206
$source = new Visualizer_Source_Query( $params );
203207
$source->fetch( false );
208+
204209
$error = $source->get_error();
205210
if ( empty( $error ) ) {
206211
update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
@@ -242,7 +247,8 @@ public function refreshDbChart() {
242247
continue;
243248
}
244249

245-
$this->refresh_db_for_chart( null, $chart_id, false );
250+
// if the time is nigh, we force an update.
251+
$this->refresh_db_for_chart( null, $chart_id, true );
246252
$hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
247253
$new_schedules[ $chart_id ] = time() + $hours * HOUR_IN_SECONDS;
248254
}

0 commit comments

Comments
 (0)