/**
  * 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;
 }
 public function RunWorkflow($json, $key)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::ServiceAPI::TwitterStreamingServices::StartTwitterStreamer::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $parameters = parent::ParseTwitterStreamingStartParametersFromJson($json);
     if (!isset($parameters)) {
         $logger->log("Core::ServiceAPI::TwitterStreamingServices::StartTwitterStreamer::RunWorkflow [ERROR: Method ParseTwitterStreamingStartParametersFromJson returned null]", \PEAR_LOG_DEBUG);
         parent::FormatErrorMessage("There was an error in the JSON supplied, please consult the API documentation and try again.");
     }
     //create a channel for the streamed content
     $channelJson = '{"id":"TWITTERSTREAM","type":"Twitter Stream","subType":"Filter","name":"Twitter Stream","active":false}';
     $channel = \Swiftriver\Core\ObjectModel\ObjectFactories\ChannelFactory::CreateChannelFromJSON($channelJson);
     $channelRepository = new \Swiftriver\Core\DAL\Repositories\ChannelRepository();
     $channelRepository->SaveChannels(array($channel));
     $filename = \Swiftriver\Core\Setup::Configuration()->CachingDirectory . "/TwitterStreamingController.tmp";
     $fp = \fopen($filename, "w");
     $done = false;
     while (!$done) {
         if (\flock($fp, \LOCK_EX)) {
             $searchArray = "";
             foreach ($parameters["SearchTerms"] as $term) {
                 $searchArray .= $term . "~";
             }
             $searchArray = \rtrim($searchArray, '~');
             \fwrite($fp, $parameters["TwitterUsername"] . "|" . $parameters["TwitterPassword"] . "|" . $searchArray);
             \flock($fp, \LOCK_UN);
             $done = true;
         } else {
             \sleep(1);
         }
     }
     \fclose($fp);
     $command = "php " . \dirname(__FILE__) . "/../../Modules/Phirehose/starttwitterstreamer.php";
     $this->execInBackground($command);
     $logger->log("Core::ServiceAPI::TwitterStreamingServices::StartTwitterStreamer::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     return;
 }
Exemplo n.º 3
0
 /**
  * Lists all the current Channel in the core
  * @return \Swiftriver\Core\ObjectModel\Channel[]
  */
 public static function ListAllChannels()
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannels [Method invoked]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannels [START: Querying the data store]", \PEAR_LOG_DEBUG);
     try {
         //Attempt to query the data store
         $dbResults = RedBeanController::Finder()->where("channel", "deleted != 1");
         //If the db returns noting then throw an exception
         if (!$dbResults || $dbResults == null || !is_array($dbResults) || count($dbResults) < 1) {
             throw new \Exception("No sources returned from the data store, it may be because none have been added?");
         }
     } catch (\Exception $e) {
         $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannels [An exception was thrown, returning empty array]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannels [{$e}]", \PEAR_LOG_ERR);
         $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannels [Method finished]", \PEAR_LOG_DEBUG);
         return array();
     }
     $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannels [END: Querying the data store]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannels [START: Creating Channel objects]", \PEAR_LOG_DEBUG);
     $channels = array();
     foreach ($dbResults as $dbResult) {
         $json = $dbResult->json;
         try {
             $channels[] = \Swiftriver\Core\ObjectModel\ObjectFactories\ChannelFactory::CreateChannelFromJSON($json);
         } catch (\Exception $e) {
             $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannels [An exception was thrown: {$e}]", \PEAR_LOG_ERR);
             $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannels [No Channel could be constructed from the DB content]", \PEAR_LOG_DEBUG);
             continue;
         }
     }
     $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannels [END: Creating Channel objects]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Modules::DataContext::MySQL_V1::DataContext::ListAllChannels [Method finished]", \PEAR_LOG_DEBUG);
     return $channels;
 }
Exemplo n.º 4
0
 /**
  * Lists all the current Channel in the core
  * @return \Swiftriver\Core\ObjectModel\Channel[]
  */
 public static function ListAllChannels()
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [Method Invoked]", \PEAR_LOG_DEBUG);
     $channels = array();
     $sql = "CALL SC_ListAllChannels()";
     try {
         $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [START: Connecting via PDO]", \PEAR_LOG_DEBUG);
         $db = self::PDOConnection();
         $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [END: Connecting via PDO]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [START: Preparing PDO statement]", \PEAR_LOG_DEBUG);
         $statement = $db->prepare($sql);
         $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [END: Preparing PDO statement]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [START: Executing PDO statement]", \PEAR_LOG_DEBUG);
         $result = $statement->execute();
         if ($result === false) {
             $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [An Exception was thrown by the PDO framwork]", \PEAR_LOG_ERR);
             $errorInfo = $statement->errorInfo();
             $errorMessage = $errorInfo[2];
             $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [{$errorMessage}]", \PEAR_LOG_ERR);
         }
         $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [END: Executing PDO statement]", \PEAR_LOG_DEBUG);
         if (isset($result) && $result != null && $result !== 0) {
             $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [START: Looping over results]", \PEAR_LOG_DEBUG);
             foreach ($statement->fetchAll() as $row) {
                 $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [START: Constructing Channel Object from json]", \PEAR_LOG_DEBUG);
                 $json = $row['json'];
                 $channel = \Swiftriver\Core\ObjectModel\ObjectFactories\ChannelFactory::CreateChannelFromJSON($json);
                 $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [END: Constructing Channel Object from json]", \PEAR_LOG_DEBUG);
                 $channels[] = $channel;
             }
             $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [END: Looping over results]", \PEAR_LOG_DEBUG);
         }
         $db = null;
     } catch (\PDOException $e) {
         $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [An Exception was thrown:]", \PEAR_LOG_ERR);
         $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [{$e}]", \PEAR_LOG_ERR);
     }
     $logger->log("Core::Modules::DataContext::MySQL_V2::DataContext::ListAllChannels [Method Finished]", \PEAR_LOG_DEBUG);
     return $channels;
 }
Exemplo n.º 5
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;
     */
 }