public function setUp()
 {
     parent::setUp();
     SocialQueue::queueURL($this->testURL);
     // now setup a statistics for the URL
     foreach ($this->services as $service) {
         $countService = new $service();
         if (is_array($countService->statistic)) {
             foreach ($countService->statistic as $statistic) {
                 $stat = URLStatistics::create();
                 $stat->Service = $countService->service;
                 $stat->Action = $statistic;
                 $stat->Count = 50;
                 $stat->URL = $this->testURL;
                 $stat->write();
             }
         } else {
             $stat = URLStatistics::create();
             $stat->Service = $countService->service;
             $stat->Action = $countService->statistic;
             $stat->Count = 50;
             $stat->URL = $this->testURL;
             $stat->write();
             unset($stat);
         }
     }
 }
コード例 #2
0
 public function countsFor()
 {
     $urls = explode(',', $this->request->getVar('urls'));
     // queue all urls to be checked
     foreach ($urls as $url) {
         $result = SocialQueue::queueURL($url);
     }
     $urlObjs = URLStatistics::get()->filter(array('URL' => $urls));
     if (!$urlObjs->count()) {
         return json_encode(array());
     }
     $results = array();
     // do we need to filter the results any further
     $service = $this->getRequest()->param('SERVICE');
     $filter = null;
     if ($service && $service == 'service') {
         $filter = $this->getRequest()->param('FILTER');
     }
     foreach ($urlObjs as $urlObj) {
         if ($filter) {
             if (strtoupper($urlObj->Service) == strtoupper($filter)) {
                 $results['results'][$urlObj->URL][$urlObj->Service][] = array($urlObj->Action => $urlObj->Count);
             }
         } else {
             $results['results'][$urlObj->URL][$urlObj->Service][] = array($urlObj->Action => $urlObj->Count);
         }
     }
     return json_encode($results);
 }
コード例 #3
0
 public function process()
 {
     $services = array();
     foreach (Config::inst()->get('UpdateSocialStatsJob', 'services') as $service) {
         $services[] = $service::create();
     }
     $requeue = array();
     foreach ($services as $service) {
         $errors = $service->processQueue($this->URLs);
         foreach ($errors as $error) {
             if (!in_array($error, $requeue)) {
                 $requeue[] = $error;
             }
         }
     }
     foreach ($requeue as $queue) {
         SocialQueue::queueURL($queue);
     }
     $this->currentStep = count($this->URLs);
     $this->completeJob();
 }