Exemplo n.º 1
0
 /**
  * Data sync cron job. Replaces the background sync non blocking HTTP request
  * that doesn't halt page loading.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.1.7.3
  */
 function _sync_cron()
 {
     $this->_logger->entrance();
     // Store the last time data sync was executed.
     $this->_storage->sync_timestamp = time();
     // Check if API is temporary down.
     if (FS_Api::is_temporary_down()) {
         return;
     }
     // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
     if ($this->is_registered()) {
         if ($this->has_paid_plan()) {
             // Initiate background plan sync.
             $this->_sync_license(true);
             if ($this->is_paying()) {
                 // Check for premium plugin updates.
                 $this->_check_updates(true);
             }
         } else {
             // Sync install (only if something changed locally).
             $this->sync_install();
         }
     }
     $this->do_action('after_sync_cron');
 }
Exemplo n.º 2
0
 /**
  * Background sync every 24 hours.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.0.4
  *
  * @return bool If function actually executed the sync in this iteration.
  */
 private function _background_sync()
 {
     $this->_logger->entrance();
     // Don't sync license on AJAX calls.
     if ($this->is_ajax()) {
         return false;
     }
     // Asked to sync explicitly, no need for background sync.
     if (fs_request_is_action($this->_slug . '_sync_license')) {
         return false;
     }
     // Check if API is not down.
     if (FS_Api::is_temporary_down()) {
         return false;
     }
     $sync_timestamp = $this->_storage->get('sync_timestamp');
     if (!is_numeric($sync_timestamp) || $sync_timestamp >= time()) {
         // If updated not set or happens to be in the future, set as if was 24 hours earlier.
         $sync_timestamp = time() - WP_FS__TIME_24_HOURS_IN_SEC;
         $this->_storage->sync_timestamp = $sync_timestamp;
     }
     if (defined('WP_FS__DEV_MODE') && WP_FS__DEV_MODE && fs_request_has('background_sync') || $sync_timestamp <= time() - WP_FS__TIME_24_HOURS_IN_SEC) {
         if ($this->is_registered()) {
             // Initiate background plan sync.
             $this->_sync_license(true);
             if ($this->is_paying()) {
                 // Check for plugin updates.
                 $this->_check_updates(true);
             }
         }
         if (!$this->is_addon()) {
             if ($this->is_registered() || $this->_has_addons) {
                 // Try to fetch add-ons if registered or if plugin
                 // declared that it has add-ons.
                 $this->_sync_addons();
             }
         }
         // Update last sync timestamp.
         $this->_storage->sync_timestamp = time();
         return true;
     }
     return false;
 }