CreateChannelFromJSON() публичный статический Метод

public static CreateChannelFromJSON ( $json )
 public function ParseJSONToChannel($json)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::ChannelServices::ChannelServicesBase::ParseJSONToChannel [Method invoked]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::ChannelServicesBase::ParseJSONToChannel [START: Creating new Channel]", \PEAR_LOG_DEBUG);
     try {
         //Try and get a Channel from the factory
         $channel = \Swiftriver\Core\ObjectModel\ObjectFactories\ChannelFactory::CreateChannelFromJSON($json);
     } catch (\Exception $e) {
         //If exception, get the mesasge
         $message = $e->getMessage();
         //and log it
         $logger->log("Core::Workflows::ChannelServices::ChannelServicesBase::ParseJSONToChannel [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::ChannelServicesBase::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::Workflows::ChannelServices::ChannelServicesBase::ParseJSONToChannel [END: Creating new Channel]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::ChannelServicesBase::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;
 }
Пример #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;
 }
Пример #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;
 }