Esempio n. 1
0
 /**
  * @test
  * @depends getPlatforms
  */
 public function getFeed(array $platforms = [])
 {
     $failures = 0;
     try {
         foreach ($platforms as $p) {
             $rss = $p->meta['rss'];
             if (!$rss['parsing']) {
                 continue;
             }
             $result = \Shared\Rss::getFeed($rss['url'], $rss['lastCrawled']);
             if ($result['lastCrawled'] === $rss['lastCrawled']) {
                 $this->assertEquals(0, count($result['urls']));
             } else {
                 $this->assertNotEquals(0, count($result['urls']));
             }
         }
     } catch (\Exception $e) {
         $failures++;
     }
     $this->assertEquals(0, $failures, "Failed to crawl some Rss URL's");
 }
Esempio n. 2
0
 /**
  * @before _secure
  */
 public function import()
 {
     $this->seo(['title' => 'Campaign Import', 'description' => 'Create a new campaign']);
     $view = $this->getActionView();
     $org = $this->org;
     $advertisers = \User::all(["org_id = ?" => $this->org->_id, 'type = ?' => 'advertiser'], ['_id', 'name']);
     if (count($advertisers) === 0) {
         $this->redirect('/advertiser/add.html');
     }
     $platforms = \Platform::rssFeeds($this->org);
     $view->set('advertiser', $advertisers);
     $action = RM::post('action', '');
     switch ($action) {
         case 'campImport':
             $this->_import($org, $advertisers, $view);
             break;
         case 'platform':
             $pid = RM::post('pid');
             $p = $platforms[$pid];
             $meta = $p->meta;
             $meta['rss']['url'] = RM::post('url');
             $parsing = (bool) (int) RM::post('parsing', "1");
             $meta['rss']['parsing'] = $parsing;
             $p->meta = $meta;
             $p->save();
             $view->set('message', 'Updated Rss feed');
             break;
         case 'newRss':
             $url = RM::post('rss_link');
             $a = array_values($advertisers)[0];
             $advert_id = RM::post('advert_id', $a->getMongoID());
             $advert = \User::first(['_id = ?' => $advert_id, 'type = ?' => 'advertiser']);
             if (!$advert) {
                 return $view->set('message', 'Invalid Request!!');
             }
             // try to find a platform for the given advertiser
             $domain = parse_url($url, PHP_URL_HOST);
             $regex = preg_quote($domain);
             $p = \Platform::first(['user_id' => $advert_id, 'url' => Utils::mongoRegex($regex)]);
             $msg = "RSS Feed Added. Campaigns Will be imported within an hour";
             try {
                 // Now schedule importing of campaigns
                 $result = \Shared\Rss::getFeed($url);
                 $rate = RM::post('rate', 0.2);
                 $revenue = RM::post('revenue', 0.25);
                 $rss = ['url' => $url, 'parsing' => true, 'lastCrawled' => $result['lastCrawled'], 'campaign' => ['model' => RM::post('model', 'cpc'), 'rate' => $this->currency($rate), 'revenue' => $this->currency($rate)]];
                 // if platform not found then add new
                 if (!$p) {
                     $p = new \Platform(['url' => $domain, 'user_id' => $advert_id]);
                 }
                 $meta = $p->meta;
                 $meta['rss'] = $rss;
                 $p->meta = $meta;
                 $p->save();
                 \Meta::campImport($this->user->_id, $advert_id, $result['urls'], $rss['campaign']);
             } catch (\Exception $e) {
                 $msg = "Internal Server Error!!";
             }
             $view->set('message', $msg);
             break;
     }
     $platforms = \Platform::rssFeeds($this->org);
     $view->set('platforms', $platforms);
 }
Esempio n. 3
0
 /**
  * Process the RSS Feed Urls from Platforms Table and queue the AD
  * urls in the Meta Table for campaign importing
  */
 protected function _rssFeed()
 {
     // find all the platforms for the advertisers
     $orgs = \Organization::all([], ['_id']);
     foreach ($orgs as $o) {
         $platforms = \Platform::rssFeeds($o);
         // get feed for each platform
         foreach ($platforms as $p) {
             $meta = $p->meta;
             $rss = $meta['rss'];
             // parsing is stopped
             if (!$rss['parsing']) {
                 continue;
             }
             $lastCrawled = null;
             if (isset($rss['lastCrawled'])) {
                 $lastCrawled = $rss['lastCrawled'];
             }
             $result = \Shared\Rss::getFeed($rss['url'], $lastCrawled);
             $urls = $result['urls'];
             $rss['lastCrawled'] = $result['lastCrawled'];
             $meta['rss'] = $rss;
             $p->meta = $meta;
             $p->save();
             // save the lastCrawled time
             $user = \User::first(['org_id' => $o->_id, 'type' => 'admin'], ['_id']);
             \Meta::campImport($user->_id, $p->user_id, $result['urls'], $rss['campaign']);
         }
     }
 }