/**
  * 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::ChannelProcessingJobs::ChannelProcessingJobBase::ParseJSONToChannel [Method invoked]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobs::ChannelProcessingJobBase::ParseJSONToChannel [START: Creating new Channel from the ChannelFactory]", \PEAR_LOG_DEBUG);
     try {
         //Try and get a channel from the factory
         $channel = \Swiftriver\Core\ObjectModel\ObjectFactories\ChannelFactory::CreateChannel($json);
     } catch (\Exception $e) {
         //If exception, get the mesasge
         $message = $e->getMessage();
         //and log it
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::ChannelProcessingJobBase::ParseJSONToChannel [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::ChannelProcessingJobBase::ParseJSONToChannel [Method finished]", \PEAR_LOG_INFO);
         throw new \InvalidArgumentException("The JSON passed to this method did not contain data required to construct a channel object: {$message}");
     }
     $logger->log("Core::ServiceAPI::ChannelProcessingJobs::ChannelProcessingJobBase::ParseJSONToChannel [END: Creating new Channel from the ChannelFactory]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobs::ChannelProcessingJobBase::ParseJSONToChannel [Method finished]", \PEAR_LOG_DEBUG);
     return $channel;
 }
Ejemplo n.º 2
0
 /**
  * Lists all the current Channel Processing Jobs in the core
  * @return \Swiftriver\Core\ObjectModel\Channel[]
  */
 public static function ListAllChannelProcessingJobs()
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannelProcessingJobs [Method invoked]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannelProcessingJobs [START: Get all channel processing jobs fro the data store.]", \PEAR_LOG_DEBUG);
     //get the db objects
     $cs = RedBeanController::Finder()->where("channelprocessingjobs");
     $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannelProcessingJobs [END: Get all channel processing jobs fro the data store.]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannelProcessingJobs [START: Create Channel object from data store objects.]", \PEAR_LOG_DEBUG);
     //create the array to return
     $channels = array();
     //loop through the DB objects
     if (isset($cs) && is_array($cs)) {
         foreach ($cs as $c) {
             $channels[] = \Swiftriver\Core\ObjectModel\ObjectFactories\ChannelFactory::CreateChannel($c->json);
         }
     }
     $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannelProcessingJobs [START: Create Channel object from data store objects.]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannelProcessingJobs [Method finished]", \PEAR_LOG_DEBUG);
     //return the channels
     return $channels;
     /*
     $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->type = $type;
         $channel->updatePeriod = $updatePeriod;
         $channel->active = !isset($active) || $active != 0;
         $channel->lastSucess = $lastsucess;
         $params = array();
         foreach(explode("|", $parameters) as $parameter) {
             $pair = explode(",", $parameter);
             $key = urldecode($pair[0]);
             $value = urldecode($pair[1]);
             $params[$key] = $value;
         }
         $channel->parameters = $params;
         $channels[] = $channel;
     }
     return $channels;
     */
 }