public function RunWorkflow($key)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::PreProcessingSteps::ListAllPreProcessingSteps::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::Workflows::PreProcessingSteps::ListAllPreProcessingSteps::RunWorkflow [START: Constructing the PreProcessor]", \PEAR_LOG_DEBUG);
     $preProcessor = new \Swiftriver\Core\PreProcessing\PreProcessor();
     $logger->log("Core::Workflows::PreProcessingSteps::ListAllPreProcessingSteps::RunWorkflow [END: Constructing the PreProcessor]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::ListAllPreProcessingSteps::RunWorkflow [START: Listing all preprocessors]", \PEAR_LOG_DEBUG);
     $steps = $preProcessor->ListAllAvailablePreProcessingSteps();
     $logger->log("Core::Workflows::PreProcessingSteps::ListAllPreProcessingSteps::RunWorkflow [END: Listing all preprocessors]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::ListAllPreProcessingSteps::RunWorkflow [START: Finding out which are active]", \PEAR_LOG_DEBUG);
     //Get the currently configured steps
     $config = \Swiftriver\Core\Setup::PreProcessingStepsConfiguration();
     $activeSteps = $config->PreProcessingSteps;
     if ($activeSteps != null && is_array($activeSteps) && $steps != null && is_array($steps)) {
         foreach ($activeSteps as $activeStep) {
             foreach ($steps as $step) {
                 if ($step->Name() == $activeStep->name) {
                     $step->active = true;
                 }
             }
         }
     }
     $logger->log("Core::Workflows::PreProcessingSteps::ListAllPreProcessingSteps::RunWorkflow [END: Finding out which are active]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::ListAllPreProcessingSteps::RunWorkflow [START: Encoding results to JSON]", \PEAR_LOG_DEBUG);
     $json = parent::ParseStepsToJson($steps);
     $logger->log("Core::Workflows::PreProcessingSteps::ListAllPreProcessingSteps::RunWorkflow [END: Encoding results to JSON]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::ListAllPreProcessingSteps::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     return parent::FormatReturn($json);
 }
 public function RunWorkflow($json, $key)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [START: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     try {
         //Call the parent to decode the json
         $preProcessingStepName = parent::ParseJsonToPreProcessingStepName($json);
         $configuration = parent::ParseJsonToPreProcessingStepConfiguration($json);
     } catch (\Exception $e) {
         //Catch and report the exception if one is thrown
         $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [{$e}]", \PEAR_LOG_ERR);
         return parent::FormatErrorMessage($e);
     }
     $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [END: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [START: Listing all available pre processors]", \PEAR_LOG_DEBUG);
     //Build a new pre processor
     $preProcessor = new \Swiftriver\Core\PreProcessing\PreProcessor();
     //list all the availaibel steps
     $steps = $preProcessor->ListAllAvailablePreProcessingSteps();
     $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [END: Listing all available pre processors]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [START: Looking for the pre processor to activate]", \PEAR_LOG_DEBUG);
     //Loop throught the steps looking for one with the same name as came from the JOSN
     foreach ($steps as $s) {
         if ($s->Name() == $preProcessingStepName) {
             $step = $s;
         }
     }
     //If not found, return an error.
     if (!isset($step) || $step == null) {
         $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [No pre processor with a name matching {$preProcessingStepName} was found.]", \PEAR_LOG_DEBUG);
         return parent::FormatErrorMessage("No pre processor matching the name {$preProcessingStepName} could be found");
     }
     $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [END: Looking for the pre processor to activate]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [START: Collecting Configuration properties for Pre Processing Step]", \PEAR_LOG_DEBUG);
     $thisConfig = array();
     foreach ($step->ReturnRequiredParameters() as $param) {
         foreach ($configuration as $key => $value) {
             if ($param->name == $key) {
                 $param->value = $value;
             }
         }
         $thisConfig[] = $param;
     }
     $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [END: Collecting Configuration properties for Pre Processing Step]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [START: Saving configuration properties for Pre Processing Step]", \PEAR_LOG_DEBUG);
     $config = \Swiftriver\Core\Setup::DynamicModuleConfiguration();
     $config->Configuration[$preProcessingStepName] = $thisConfig;
     $config->Save();
     $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [START: Saving configuration properties for Pre Processing Step]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::SavePreProcessingStep::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     parent::FormatMessage("OK");
 }
 public function RunWorkflow($content, $preProcessContent = true)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [START: Running core processing]", \PEAR_LOG_DEBUG);
     if ($preProcessContent) {
         try {
             $preProcessor = new \Swiftriver\Core\PreProcessing\PreProcessor();
             $content = $preProcessor->PreProcessContent($content);
         } catch (\Exception $e) {
             //get the exception message
             $message = $e->getMessage();
             $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
             $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
             $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
             return parent::FormatErrorMessage("An exception was thrown: {$message}");
         }
     }
     $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [END: Running core processing]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [START: Save content to the data store]", \PEAR_LOG_DEBUG);
     try {
         $contentRepository = new \Swiftriver\Core\DAL\Repositories\ContentRepository();
         $contentRepository->SaveContent($content);
         // Raise the event handler that handles the post processing of content
         $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [Raise the Ushahidi Push Event Handler]", \PEAR_LOG_DEBUG);
         $event = new \Swiftriver\Core\EventDistribution\GenericEvent(\Swiftriver\Core\EventDistribution\EventEnumeration::$ContentPostProcessing, $content);
         $eventDistributor = new \Swiftriver\Core\EventDistribution\EventDistributor();
         $eventDistributor->RaiseAndDistributeEvent($event);
         $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [End Ushahidi Push event]", \PEAR_LOG_DEBUG);
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [END: Save content to the data store]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::ContentServices::ProcessContent::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
 }
 /**
  * Selects the next due processing job and runs it through the core
  *
  * @return string $json
  */
 public function RunService()
 {
     //Setup the logger
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [START: Constructing Repository]", \PEAR_LOG_DEBUG);
     //Construct a new repository
     $channelRepository = new \Swiftriver\Core\DAL\Repositories\ChannelProcessingJobRepository();
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [END: Constructing Repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [START: Fetching next processing Job]", \PEAR_LOG_DEBUG);
     //Get the next due channel processign job
     $channel = $channelRepository->SelectNextDueChannelProcessingJob();
     if ($channel == null) {
         $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [INFO: No processing jobs due]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [END: Fetching next processing Job]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatMessage("OK");
     }
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [END: Fetching next processing Job]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [START: Get and parse content]", \PEAR_LOG_DEBUG);
     $SiSPS = new \Swiftriver\Core\Modules\SiSPS\SwiftriverSourceParsingService();
     $rawContent = $SiSPS->FetchContentFromChannel($channel);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [END: Get and parse content]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [START: Running core processing]", \PEAR_LOG_DEBUG);
     $preProcessor = new \Swiftriver\Core\PreProcessing\PreProcessor();
     $processedContent = $preProcessor->PreProcessContent($rawContent);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [END: Parsing channel processing jobs to JSON]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [START: Save content to the data store]", \PEAR_LOG_DEBUG);
     $contentRepository = new \Swiftriver\Core\DAL\Repositories\ContentRepository();
     $contentRepository->SaveContent($processedContent);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [END: Save content to the data store]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [START: Mark channel processing job as complete]", \PEAR_LOG_DEBUG);
     $channelRepository->MarkChannelProcessingJobAsComplete($channel);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [END: Mark channel processing job as complete]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::RunNextProcessingJob::RunService [Method finished]", \PEAR_LOG_INFO);
     return parent::FormatMessage("OK");
 }
 public function RunWorkflow($json, $key)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [START: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     try {
         //Call the parent to decode the json
         $preProcessingStepName = parent::ParseJsonToPreProcessingStepName($json);
     } catch (\Exception $e) {
         //Catch and report the exception if one is thrown
         $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [{$e}]", \PEAR_LOG_ERR);
         return parent::FormatErrorMessage($e);
     }
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [END: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [START: Listing all available pre processors]", \PEAR_LOG_DEBUG);
     //Build a new pre processor
     $preProcessor = new \Swiftriver\Core\PreProcessing\PreProcessor();
     //list all the availaibel steps
     $steps = $preProcessor->ListAllAvailablePreProcessingSteps();
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [END: Listing all available pre processors]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [START: Looking for the pre processor to activate]", \PEAR_LOG_DEBUG);
     //Loop throught the steps looking for one with the same name as came from the JOSN
     foreach ($steps as $s) {
         if ($s->Name() == $preProcessingStepName) {
             $step = $s;
         }
     }
     //If not found, return an error.
     if (!isset($step) || $step == null) {
         $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [No pre processor with a name matching {$preProcessingStepName} was found.]", \PEAR_LOG_DEBUG);
         return parent::FormatErrorMessage("No pre processor matching the name {$preProcessingStepName} could be found");
     }
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [END: Looking for the pre processor to activate]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [START: Constructing the PreProcessingStep Configuration Entry]", \PEAR_LOG_DEBUG);
     //Extract the required data to build a configuration entry
     $className = $step->type;
     $filePath = $step->filePath;
     $name = $step->Name();
     //Construct a new configuration entry
     $preProcessorStep = new \Swiftriver\Core\ObjectModel\PreProcessingStepEntry($name, $className, $filePath);
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [END: Constructing the PreProcessingStep Configuration Entry]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [START: Adding the pre processor to the configuration]", \PEAR_LOG_DEBUG);
     //Get the currently configured steps
     $config = \Swiftriver\Core\Setup::PreProcessingStepsConfiguration();
     $numberOfPreProcessors = count($config->PreProcessingSteps);
     //See if this step is already in there
     for ($i = 0; $i < $numberOfPreProcessors; $i++) {
         if ($config->PreProcessingSteps[$i]->name == $preProcessorStep->name) {
             $index = $i;
         }
     }
     //Add the step to the configuration framework
     if (isset($index)) {
         $config->PreProcessingSteps[$index] = $preProcessorStep;
     } else {
         $config->PreProcessingSteps[] = $preProcessorStep;
     }
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [END: Adding the pre processor to the configuration]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [START: Saving the configuration]", \PEAR_LOG_DEBUG);
     //Save the config to file.
     $config->Save();
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [END: Saving the configuration]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::PreProcessingSteps::ActivatePreProcessingStep::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     parent::FormatMessage("OK");
 }
 /**
  * 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");
 }
 /**
  * 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");
 }