예제 #1
0
 /**
  * Adds the Channel to the ata store
  *
  * @param string $json
  * @return string $json
  */
 public function RunWorkflow($json, $key)
 {
     //Setup the logger
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [START: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     try {
         //Parse the JSON input
         $channel = parent::ParseJSONToChannel($json);
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     if (!isset($channel)) {
         $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [ERROR: Method ParseIncommingJSON returned null]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [ERROR: Registering new processing job with Core]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("There were errors in you JSON. Please review the API documentation and try again.");
     }
     $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [END: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [START: Constructing Repository]", \PEAR_LOG_DEBUG);
     try {
         //Construct a new repository
         $repository = new \Swiftriver\Core\DAL\Repositories\ChannelRepository();
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [END: Constructing Repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [START: Saving Processing Job]", \PEAR_LOG_DEBUG);
     try {
         //Add the channel processign job to the repository
         $repository->SaveChannels(array($channel));
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [END: Saving Processing Job]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::AddChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     //return an OK messagae
     return parent::FormatMessage("OK");
 }
예제 #2
0
 /**
  * Removes a Channel from the DAL
  * 
  * @param string $json
  * @return string 
  */
 public function RunWorkflow($json, $key)
 {
     //Setup the logger
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [START: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     //try to parse the id from the JSON
     try {
         //get the ID from the JSON
         $id = parent::ParseJSONToId($json);
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [END: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [START: Constructing Repository]", \PEAR_LOG_DEBUG);
     try {
         //Construct a new repository
         $repository = new \Swiftriver\Core\DAL\Repositories\ChannelRepository();
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [END: Constructing Repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [START: Deleting the Channel]", \PEAR_LOG_DEBUG);
     try {
         //Delete the Channel from the data store
         $repository->RemoveChannels(array($id));
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [END: Deletig the Channel]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::DeleteChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     //return an OK messagae
     return parent::FormatMessage("OK");
 }
예제 #3
0
 /**
  * List all Channel Processing Jobs in the Data Store
  *
  * @param string $json
  * @return string $json
  */
 public function RunWorkflow($key)
 {
     //Setup the logger
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [START: Constructing Repository]", \PEAR_LOG_DEBUG);
     try {
         //Construct a new repository
         $repository = new \Swiftriver\Core\DAL\Repositories\ChannelRepository();
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [END: Constructing Repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [START: Listing all Channels]", \PEAR_LOG_DEBUG);
     try {
         //Get all the Channels
         $channels = $repository->ListAllChannels();
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [END: Listing all Channels]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [START: Parsing channel processing jobs to JSON]", \PEAR_LOG_DEBUG);
     try {
         //Parse the JSON input
         $json = parent::ParseChannelsToJSON($channels);
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [END: Parsing channel processing jobs to JSON]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::GetAllChannels::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     //return the channels as JSON
     return parent::FormatReturn($json);
 }
 /**
  * List all the Available types of Channels that can be configured in
  * the core
  *
  * @param string $key
  * @return string $json
  */
 public function RunWorkflow($key)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::ServiceAPI::ChannelProcessingJobs::ListAvailableChannelTypes::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobs::ListAvailableChannelTypes::RunWorkflow [START: Constructing SiSPS]", \PEAR_LOG_DEBUG);
     $service = new \Swiftriver\Core\Modules\SiSPS\SwiftriverSourceParsingService();
     $logger->log("Core::ServiceAPI::ChannelProcessingJobs::ListAvailableChannelTypes::RunWorkflow [END: Constructing SiSPS]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobs::ListAvailableChannelTypes::RunWorkflow [START: Getting the list of available parsers]", \PEAR_LOG_DEBUG);
     $parsers = $service->ListAvailableParsers();
     $logger->log("Core::ServiceAPI::ChannelProcessingJobs::ListAvailableChannelTypes::RunWorkflow [END: Getting the list of available parsers]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobs::ListAvailableChannelTypes::RunWorkflow [START: Parsing to return JSON]", \PEAR_LOG_DEBUG);
     $json = parent::ParseParsersToJSON($parsers);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobs::ListAvailableChannelTypes::RunWorkflow [END: Parsing to return JSON]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobs::ListAvailableChannelTypes::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     return parent::FormatReturn($json);
 }
예제 #5
0
 /**
  * Pushes content to a specific channel via its parser
  *
  * @return string $json
  */
 public function RunWorkflow($key)
 {
     //Setup the logger
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [START: Setting time out]", \PEAR_LOG_DEBUG);
     set_time_limit(300);
     $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [Getting the appropriate parser]", \PEAR_LOG_DEBUG);
     $origin = $_GET["origin"];
     $parser = \Swiftriver\Core\Modules\SiSPS\ParserFactory::GetParserByPushOrigin($origin);
     if (is_null($parser)) {
         $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [INFO: No Parser for origin '{$origin}']", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [END: PushToChannel]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("No parser exists for '{$origin}'");
     }
     $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [Extracting raw data]", \PEAR_LOG_DEBUG);
     $raw_content = file_get_contents('php://input');
     $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [END: Fetching next Channel]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [START: Get and parse content]", \PEAR_LOG_DEBUG);
     try {
         $post_content = null;
         if ($_POST) {
             $post_content = $_POST;
         }
         $get_content = null;
         if ($_GET) {
             $get_content = $_GET;
         }
         $file_content = null;
         if ($_FILES) {
             $file_content = $_FILES;
         }
         $SiSPS = new \Swiftriver\Core\Modules\SiSPS\SwiftriverPushParsingService();
         $rawContent = $SiSPS->FetchContentFromChannel($parser, $raw_content, $post_content, $get_content, $file_content);
     } catch (\Exception $e) {
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     if (isset($rawContent) && is_array($rawContent) && count($rawContent) > 0) {
         $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [END: Get and parse content]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [START: Running core processing]", \PEAR_LOG_DEBUG);
         try {
             $preProcessor = new \Swiftriver\Core\PreProcessing\PreProcessor();
             $processedContent = $preProcessor->PreProcessContent($rawContent);
         } catch (\Exception $e) {
             //get the exception message
             $message = $e->getMessage();
             $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
             $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
             $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
             return parent::FormatErrorMessage("An exception was thrown: {$message}");
         }
         $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [END: Running core processing]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [START: Save content to the data store]", \PEAR_LOG_DEBUG);
         try {
             $contentRepository = new \Swiftriver\Core\DAL\Repositories\ContentRepository();
             $contentRepository->SaveContent($processedContent);
             // Raise the event handler that handles the post processing of content
             $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [Raise the Ushahidi Push Event Handler]", \PEAR_LOG_DEBUG);
             $event = new \Swiftriver\Core\EventDistribution\GenericEvent(\Swiftriver\Core\EventDistribution\EventEnumeration::$ContentPostProcessing, $processedContent);
             $eventDistributor = new \Swiftriver\Core\EventDistribution\EventDistributor();
             $eventDistributor->RaiseAndDistributeEvent($event);
             $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [End Ushahidi Push event]", \PEAR_LOG_DEBUG);
         } catch (\Exception $e) {
             //get the exception message
             $message = $e->getMessage();
             $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
             $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
             $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
             return parent::FormatErrorMessage("An exception was thrown: {$message}");
         }
         $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [END: Save content to the data store]", \PEAR_LOG_DEBUG);
     } else {
         $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [END: Get and parse content]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [No content found.]", \PEAR_LOG_DEBUG);
     }
     $logger->log("Core::Workflows::ChannelServices::PushToChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     return parent::FormatMessage("OK");
 }
예제 #6
0
 /**
  * Activates a Channel based on the Channel ID
  * encode in the JSON param
  *
  * @param string $json
  * @return string $json
  */
 public function RunWorkflow($json, $key)
 {
     //Setup the logger
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::ChannelServices::ActivateChannel::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::Workflows::ChannelServices::ActivateChannel::RunWorkflow [START: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     //try to parse the id from the JSON
     try {
         //get the ID from the JSON
         $id = parent::ParseJSONToId($json);
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::ActivateChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::ActivateChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::ActivateChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [END: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [START: Constructing Repository]", \PEAR_LOG_DEBUG);
     try {
         //Construct a new repository
         $repository = new \Swiftriver\Core\DAL\Repositories\ChannelRepository();
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [END: Constructing Repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [START: Getting the Channel from the repository]", \PEAR_LOG_DEBUG);
     try {
         //Get the channel from the repo
         $channel = $repository->GetChannelById($id);
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [END: Getting the Channel from the repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [START: Marking Channel as active and saving to the repository]", \PEAR_LOG_DEBUG);
     try {
         //set the active flag to true
         $channel->active = true;
         //save the channel back to the repo
         $repository->SaveChannel($channel);
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [END: Marking Channel as active and saving to the repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::ActivateChannelProcessingJob::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     //return an OK messagae
     return parent::FormatMessage("OK");
 }
예제 #7
0
 /**
  * Selects the next due processing job and runs it through the core
  *
  * @return string $json
  */
 public function RunWorkflow($key)
 {
     //Setup the logger
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [START: Setting time out]", \PEAR_LOG_DEBUG);
     set_time_limit(300);
     $timeout = ini_get('max_execution_time');
     $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [END: Setting time out to {$timeout}]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [START: Constructing Repository]", \PEAR_LOG_DEBUG);
     try {
         //Construct a new repository
         $channelRepository = new \Swiftriver\Core\DAL\Repositories\ChannelRepository();
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [END: Constructing Repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [START: Fetching next Channel]", \PEAR_LOG_DEBUG);
     try {
         //Get the next due channel processign job
         $channel = $channelRepository->SelectNextDueChannel(time());
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     if ($channel == null) {
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [INFO: No Channel due]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [END: Fetching next Channel]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatMessage("OK");
     }
     $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [END: Fetching next Channel]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [START: Get and parse content]", \PEAR_LOG_DEBUG);
     try {
         $SiSPS = new \Swiftriver\Core\Modules\SiSPS\SwiftriverSourceParsingService();
         $rawContent = $SiSPS->FetchContentFromChannel($channel);
     } catch (\Exception $e) {
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         try {
             $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [START: Mark Channel as in error]", \PEAR_LOG_DEBUG);
             $channel->inprocess = false;
             $channelRepository->SaveChannels(array($channel));
             $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [END: Mark Channel as in error]", \PEAR_LOG_DEBUG);
         } catch (\Exception $innerE) {
             $message = $innerE->getMessage();
             $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
             $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
             $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [This Channel will remain in state - in progress - and will not be run again, manual action must be taken.]", \PEAR_LOG_ERR);
         }
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     if (isset($rawContent) && is_array($rawContent) && count($rawContent) > 0) {
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [END: Get and parse content]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [START: Running core processing]", \PEAR_LOG_DEBUG);
         try {
             $preProcessor = new \Swiftriver\Core\PreProcessing\PreProcessor();
             $processedContent = $preProcessor->PreProcessContent($rawContent);
         } catch (\Exception $e) {
             //get the exception message
             $message = $e->getMessage();
             $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
             $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
             $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
             return parent::FormatErrorMessage("An exception was thrown: {$message}");
         }
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [END: Running core processing]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [START: Save content to the data store]", \PEAR_LOG_DEBUG);
         try {
             $contentRepository = new \Swiftriver\Core\DAL\Repositories\ContentRepository();
             $contentRepository->SaveContent($processedContent);
         } catch (\Exception $e) {
             //get the exception message
             $message = $e->getMessage();
             $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
             $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
             $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
             return parent::FormatErrorMessage("An exception was thrown: {$message}");
         }
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [END: Save content to the data store]", \PEAR_LOG_DEBUG);
     } else {
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [END: Get and parse content]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [No content found.]", \PEAR_LOG_DEBUG);
     }
     $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [START: Mark channel processing job as complete]", \PEAR_LOG_DEBUG);
     try {
         $channel->inprocess = false;
         $channel->lastSucess = time();
         $channelRepository->SaveChannels(array($channel));
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [END: Mark channel processing job as complete]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ChannelServices::RunNextChannel::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     return parent::FormatMessage("OK");
 }