Esempio n. 1
0
 function mainwp_cronstats_action()
 {
     MainWP_Logger::Instance()->info('CRON :: stats');
     MainWP_Utility::update_option('mainwp_cron_last_stats', time());
     if (get_option('mainwp_seo') != 1) {
         return;
     }
     $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getWebsitesStatsUpdateSQL());
     $start = time();
     while ($websites && ($website = @MainWP_DB::fetch_object($websites))) {
         if ($start - time() > 60 * 60 * 2) {
             //two hours passed, next cron will start!
             break;
         }
         $errors = false;
         if (!$errors) {
             $indexed = MainWP_Utility::getGoogleCount($website->url);
             if ($indexed == NULL) {
                 $errors = true;
             }
         }
         if (!$errors) {
             $alexia = MainWP_Utility::getAlexaRank($website->url);
             if ($alexia == NULL) {
                 $errors = true;
             }
         }
         $pageRank = 0;
         //MainWP_Utility::getPagerank($website->url);
         $newIndexed = $errors ? $website->indexed : $indexed;
         $oldIndexed = $errors ? $website->indexed_old : $website->indexed;
         $newAlexia = $errors ? $website->alexia : $alexia;
         $oldAlexia = $errors ? $website->alexia_old : $website->alexia;
         $statsUpdated = $errors ? $website->statsUpdate : time();
         MainWP_DB::Instance()->updateWebsiteStats($website->id, $pageRank, $newIndexed, $newAlexia, $website->pagerank, $oldIndexed, $oldAlexia, $statsUpdated);
         if ($website->sync_errors != '') {
             //Try reconnecting
             MainWP_Logger::Instance()->infoForWebsite($website, 'reconnect', 'Trying to reconnect');
             try {
                 if (MainWP_Manage_Sites::_reconnectSite($website)) {
                     //Reconnected
                     MainWP_Logger::Instance()->infoForWebsite($website, 'reconnect', 'Reconnected successfully');
                 }
             } catch (Exception $e) {
                 //Still something wrong
                 MainWP_Logger::Instance()->warningForWebsite($website, 'reconnect', $e->getMessage());
             }
         }
         sleep(3);
     }
     @MainWP_DB::free_result($websites);
 }