Skip to content

Commit

Permalink
Add a workaround for a bug in BackupBuddy that would cause this libra…
Browse files Browse the repository at this point in the history
…ry to run a new update check every few seconds. This affects BackupBuddy 3.2.0.2 and possibly multiple other versions.

Analysis:
- PluginUpdateChecker creates a custom cron schedule by using the cron_schedules filter. This schedule is used to run periodic update checks.
- BackupBuddy also creates a number of custom schedules using the same filter. However, its filter callback throws away any schedules defined by other filters/plugins and re-initializes $schedules with an empty array().
- As a result, if the filter that was added by BackupBuddy runs *after* the filter added by PluginUpdateChecker, our custom schedule is destroyed.
- When WordPress tries to re-schedule our event after a successful Cron run, it discovers that the required schedule no longer exists, and fails. On the next page load, the library detects that the event is not scheduled and schedules it again. Hence infinite loop.
- Fixed by moving our cron_schedules filter to a later priority.

Notes:
This is the *second* time I have to add a workaround for some arrogant oversight perpetrated by BackupBuddy developers. (The first one was the "plugins_api" thing, IIRC).
  • Loading branch information
YahnisElsts committed Feb 22, 2013
1 parent 1fa2770 commit 5aee0d7
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions plugin-update-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function installHooks(){
if ( $this->checkPeriod > 0 ){

//Trigger the check via Cron
add_filter('cron_schedules', array($this, '_addCustomSchedule'));
add_filter('cron_schedules', array($this, '_addCustomSchedule'), 20);
if ( !wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING') ) {
$scheduleName = 'every' . $this->checkPeriod . 'hours';
wp_schedule_event(time(), $scheduleName, $this->cronHook);
Expand Down Expand Up @@ -118,7 +118,7 @@ public function _addCustomSchedule($schedules){
'interval' => $this->checkPeriod * 3600,
'display' => sprintf('Every %d hours', $this->checkPeriod),
);
}
}
return $schedules;
}

Expand Down Expand Up @@ -193,12 +193,12 @@ public function requestInfo($queryArgs = array()){
$pluginInfo = apply_filters('puc_request_info_result-'.$this->slug, $pluginInfo, $result);
return $pluginInfo;
}

/**
* Retrieve the latest update (if any) from the configured API endpoint.
*
*
* @uses PluginUpdateChecker::requestInfo()
*
*
* @return PluginUpdate An instance of PluginUpdate, or NULL when no updates are available.
*/
public function requestUpdate(){
Expand Down Expand Up @@ -237,11 +237,11 @@ public function getInstalledVersion(){
return null;
}
}

/**
* Check for plugin updates.
* Check for plugin updates.
* The results are stored in the DB option specified in $optionName.
*
*
* @return PluginUpdate|null
*/
public function checkForUpdates(){
Expand Down Expand Up @@ -285,12 +285,12 @@ public function maybeCheckForUpdates(){
return;
}
$state = $this->getUpdateState();

$shouldCheck =
empty($state) ||
!isset($state->lastCheck) ||
!isset($state->lastCheck) ||
( (time() - $state->lastCheck) >= $this->checkPeriod*3600 );

if ( $shouldCheck ){
$this->checkForUpdates();
}
Expand Down

0 comments on commit 5aee0d7

Please sign in to comment.