/**
  * Tests that, given a channel configured to use the Test parser,
  * the SiSPS can return a list of content items
  */
 public function testFetchContentFromChannelWithTestParser()
 {
     $channel = new \Swiftriver\Core\ObjectModel\Channel();
     $channel->SetType("Test");
     $service = new \Swiftriver\Core\Modules\SiSPS\SwiftriverSourceParsingService();
     $contentItems = $service->FetchContentFromChannel($channel);
     $this->assertEquals(true, is_array($contentItems));
     $this->assertEquals(1, count($contentItems));
     $this->assertEquals("testId", $contentItems[0]->GetId());
 }
コード例 #2
0
 /**
  * This method will take the information prvided in the
  * instance of a Swiftriver\Core\ObjectModel\Channel object
  * and will make a call to the channel to fetch and content
  * that can be fetched and then parse the content into an array
  * of Swiftriver\Core\ObjectModel\Content items
  *
  * @param Swiftriver\Core\ObjectModel\Channel $channel
  * @return Swiftriver\Core\ObjectModel\Content[] $contentItems
  */
 public function FetchContentFromChannel($channel)
 {
     //get the type of the channel
     $channelType = $channel->GetType();
     //Get a Parser from the ParserFactory based on the channel type
     $factory = ParserFactory::GetParser($channelType);
     //Extract the parameters from the channel object
     $parameters = $channel->GetParameters();
     //Get and parse all avaliable content items from the parser
     $contentItems = $factory->GetAndParse($parameters);
     //Return the content items
     return $contentItems;
 }
コード例 #3
0
 /**
  * Parses the json in to a channel object
  *
  * @param string $json
  * @return \Swiftriver\Core\ObjectModel\Channel
  */
 public function ParseJSONToChannel($json)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [Calling json_decode]", \PEAR_LOG_DEBUG);
     $data = json_decode($json);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [Extracting data from the JSON objects]", \PEAR_LOG_DEBUG);
     if (!isset($data) || !$data) {
         $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [ERROR: No objects present at data[0], returning null]", \PEAR_LOG_DEBUG);
         return null;
     }
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [Extracting values from the data]", \PEAR_LOG_DEBUG);
     $type = $data->type;
     $updatePeriod = $data->updatePeriod;
     $active = $data->active;
     $parameters = $data->parameters;
     if (!isset($type) || !isset($updatePeriod) || !isset($parameters) || !is_array($parameters)) {
         $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [ERROR: either the 'type', 'updatePeriod' or 'parameters array' could not be found, returning null]", \PEAR_LOG_DEBUG);
         return null;
     }
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [Constructing Channel object]", \PEAR_LOG_DEBUG);
     $formattedParams = array();
     foreach ($parameters as $params) {
         $formattedParams[$params->key] = $params->value;
     }
     $channel = new \Swiftriver\Core\ObjectModel\Channel();
     $channel->SetType($type);
     $channel->SetUpdatePeriod($updatePeriod);
     $channel->SetActive($active);
     $channel->SetParameters($formattedParams);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ChannelProcessingJobBase::ParseJSONToChannel [Method finished]", \PEAR_LOG_INFO);
     return $channel;
 }
コード例 #4
0
 /**
  * Lists all the current Channel Processing Jobs in the core
  * @return \Swiftriver\Core\ObjectModel\Channel[]
  */
 public static function ListAllChannelProcessingJobs()
 {
     $query = "SELECT * FROM channelprocessingjobs ORDER BY nextrun;";
     $result = self::RunQuery($query);
     if (!$result) {
         return null;
     }
     $channels = array();
     while ($row = mysql_fetch_array($result, \MYSQL_ASSOC)) {
         $type = $row["type"];
         $parameters = $row["parameters"];
         $updatePeriod = $row["updateperiod"];
         $nextrun = strtotime($row["nextrun"]);
         $lastrun = strtotime($row["lastrun"]);
         $lastsucess = strtotime($row["lastsucess"]);
         $timesrun = $row["timesrun"];
         $active = $row["active"];
         $channel = new \Swiftriver\Core\ObjectModel\Channel();
         $channel->SetType($type);
         $channel->SetUpdatePeriod($updatePeriod);
         $channel->SetActive(!isset($active) || $active != 0);
         $params = array();
         foreach (explode("|", $parameters) as $parameter) {
             $pair = explode(",", $parameter);
             $key = urldecode($pair[0]);
             $value = urldecode($pair[1]);
             $params[$key] = $value;
         }
         $channel->SetParameters($params);
         $channels[] = $channel;
     }
     return $channels;
 }