public function RunWorkflow($key)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::EventHandlers::ListAllEventHandlers::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::Workflows::EventHandlers::ListAllEventHandlers::RunWorkflow [START: Constructing the Event Distributor]", \PEAR_LOG_DEBUG);
     $eventDistributer = new \Swiftriver\Core\EventDistribution\EventDistributor();
     $logger->log("Core::Workflows::EventHandlers::ListAllEventHandlers::RunWorkflow [END: Constructing the Event Distributor]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::ListAllEventHandlers::RunWorkflow [START: Getting a full list of Event Handlers from the event distributor]", \PEAR_LOG_DEBUG);
     $handlers = $eventDistributer->ListAllAvailableEventHandlers();
     $logger->log("Core::Workflows::EventHandlers::ListAllEventHandlers::RunWorkflow [END: Getting a full list of Event Handlers from the event distributor]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::ListAllEventHandlers::RunWorkflow [START: Finding out which event handlers are active]", \PEAR_LOG_DEBUG);
     $config = \Swiftriver\Core\Setup::EventDistributionConfiguration();
     $activeHandlers = $config->EventHandlers;
     if ($activeHandlers != null && is_array($activeHandlers) && $handlers != null && is_array($handlers)) {
         foreach ($activeHandlers as $activeHandler) {
             foreach ($handlers as $handler) {
                 if ($handler->Name() == $activeHandler->name) {
                     $handler->active = true;
                 }
             }
         }
     }
     $logger->log("Core::Workflows::EventHandlers::ListAllEventHandlers::RunWorkflow [END: Finding out which event handlers are active]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::ListAllEventHandlers::RunWorkflow [START: Parsing the handlers to JSON]", \PEAR_LOG_DEBUG);
     $json = parent::ParseHandlersToJson($handlers);
     $logger->log("Core::Workflows::EventHandlers::ListAllEventHandlers::RunWorkflow [END: Parsing the handlers to JSON]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::ListAllEventHandlers::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     return parent::FormatReturn($json);
 }
 public function RunWorkflow($json, $key)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [START: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     try {
         $name = parent::ParseJsonToEventHandlerName($json);
     } catch (\Exception $e) {
         $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [{$e}]", \PEAR_LOG_ERR);
         return parent::FormatErrorMessage($e);
     }
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [END: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [START: Instanciating the event distributor]", \PEAR_LOG_DEBUG);
     $eventDistributor = new \Swiftriver\Core\EventDistribution\EventDistributor();
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [END: Instanciating the event distributor]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [START: Getting all the availabel event handlers]", \PEAR_LOG_DEBUG);
     $handlers = $eventDistributor->ListAllAvailableEventHandlers();
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [END: Getting all the availabel event handlers]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [START: Looking for a handler with the matching name]", \PEAR_LOG_DEBUG);
     foreach ($handlers as $handler) {
         if ($handler->Name() == $name) {
             $thisHandler = $handler;
         }
     }
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [END: Looking for a handler with the matching name]", \PEAR_LOG_DEBUG);
     if (!isset($thisHandler) || $thisHandler == null) {
         return parent::FormatErrorMessage("No event handler found matching the name {$name}");
     }
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [START: Constructing the configuration entry]", \PEAR_LOG_DEBUG);
     $className = $thisHandler->type;
     $filePath = $thisHandler->filePath;
     $configEntry = new \Swiftriver\Core\ObjectModel\EventHandlerEntry($name, $className, $filePath);
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [END: Constructing the configuration entry]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [START: Extracting the configured event handlers from the config system]", \PEAR_LOG_DEBUG);
     $config = \Swiftriver\Core\Setup::EventDistributionConfiguration();
     $configuredEventHandlers = $config->EventHandlers;
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [END: Extracting the configured event handlers from the config system]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [START: Looking for an existing config entry for this handler]", \PEAR_LOG_DEBUG);
     for ($i = 0; $i < count($configuredEventHandlers); $i++) {
         if ($configuredEventHandlers[$i]->name == $name) {
             $index = $i;
         }
     }
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [END: Looking for an existing config entry for this handler]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [START: Adding a configuration entry for this event handler]", \PEAR_LOG_DEBUG);
     if (isset($index)) {
         $configuredEventHandlers[$index] = $configEntry;
     } else {
         $configuredEventHandlers[] = $configEntry;
     }
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [END: Adding a configuration entry for this event handler]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [START: Saving the configuration]", \PEAR_LOG_DEBUG);
     $config->EventHandlers = $configuredEventHandlers;
     $config->Save();
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [END: Saving the configuration]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::ActivateEventHandlers::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     return parent::FormatMessage("OK");
 }
예제 #3
0
 public function RunWorkflow($json, $key)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [START: Parsing the input JSON]", \PEAR_LOG_DEBUG);
     try {
         $name = parent::ParseJsonToEventHandlerName($json);
         $config = parent::ParseJsonToEventHandlerConfiguration($json);
     } catch (\Exception $e) {
         $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [An Exception was thrown]", \PEAR_LOG_ERR);
         $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [{$e}]", \PEAR_LOG_ERR);
         return parent::FormatErrorMessage($e);
     }
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [END: Parsing the input JSON]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [START: Instanciating the event distributor]", \PEAR_LOG_DEBUG);
     $eventDistributor = new \Swiftriver\Core\EventDistribution\EventDistributor();
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [END: Instanciating the event distributor]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [START: Listing all event handlers]", \PEAR_LOG_DEBUG);
     $handlers = $eventDistributor->ListAllAvailableEventHandlers();
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [END: Listing all event handlers]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [START: Looking for an event handler with matching name]", \PEAR_LOG_DEBUG);
     foreach ($handlers as $handler) {
         if ($handler->Name() == $name) {
             $thisHandler = $handler;
         }
     }
     if (!isset($thisHandler) || $thisHandler == null) {
         $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [No event handler was found matching the name {$name}]", \PEAR_LOG_DEBUG);
         return parent::FormatErrorMessage("No event handler was found matching the name {$name}");
     }
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [END: Looking for an event handler with matching name]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [START: Adding all the configured properties to the event handler]", \PEAR_LOG_DEBUG);
     $thisConfig = array();
     foreach ($thisHandler->ReturnRequiredParameters() as $param) {
         foreach ($config as $key => $value) {
             if ($param->name == $key) {
                 $param->value = $value;
             }
         }
         $thisConfig[] = $param;
     }
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [END: Adding all the configured properties to the event handler]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [START: Saving the configuration]", \PEAR_LOG_DEBUG);
     $configuration = \Swiftriver\Core\Setup::DynamicModuleConfiguration();
     $configuration->Configuration[$name] = $thisConfig;
     $configuration->Save();
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [END: Saving the configuration]", \PEAR_LOG_DEBUG);
     $logger->log("Core::Workflows::EventHandlers::SaveEventHandlers::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     parent::FormatMessage("OK");
 }
예제 #4
0
 /**
  * Given a JSON string describing the pagination and state
  * required, this method will return a set of content items
  *
  * @param string $json
  * @return string
  */
 public function RunWorkflow($json, $key)
 {
     //Setup the logger
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [START: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     $parameters = parent::ParseJSONToLooseParameters($json);
     if (!isset($parameters)) {
         $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [ERROR: Method ParseJSONToPagedContentByStateParameters returned null]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [ERROR: Getting paged content by state]", \PEAR_LOG_INFO);
         parent::FormatErrorMessage("There was an error in the JSON supplied, please consult the API documentation and try again.");
     }
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [END: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [START: Constructing Content repository]", \PEAR_LOG_DEBUG);
     $repository = new \Swiftriver\Core\DAL\Repositories\ContentRepository();
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [END: Constructing Content repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [START: Querying repository]", \PEAR_LOG_DEBUG);
     $results = $repository->GetContentList($parameters);
     if (!isset($results) || !is_array($results) || !isset($results["totalCount"]) || !isset($results["contentItems"]) || !is_numeric($results["totalCount"]) || $results["totalCount"] < 1) {
         $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [No results were returned from the repository]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [END: Querying repository with supplied parameters]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return '{"totalcount":"0"}';
     }
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [END: Querying repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [START: Raising the 'Before Content Sent to Client' event]", \PEAR_LOG_DEBUG);
     $event = new \Swiftriver\Core\EventDistribution\GenericEvent(\Swiftriver\Core\EventDistribution\EventEnumeration::$BeforeContentSentToClient, $results["contentItems"]);
     $eventDistributor = new \Swiftriver\Core\EventDistribution\EventDistributor();
     $returnEvent = $eventDistributor->RaiseAndDistributeEvent($event);
     $contentitems = $returnEvent->arguments;
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [END: Raising the 'Before Content Sent to Client' event]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [START: Parsing content to JSON]", \PEAR_LOG_DEBUG);
     $contentJson = parent::ParseContentToJSON($contentitems);
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [END: Parsing content to JSON]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [START: Parsing navigation to JSON]", \PEAR_LOG_DEBUG);
     $navigationJson = isset($results["navigation"]) && $results["navigation"] != null ? json_encode($results["navigation"]) : "[]";
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [END: Parsing navigation to JSON]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [START: Constructing return JSON]", \PEAR_LOG_DEBUG);
     $returnJson = '{"totalcount":"' . $results["totalCount"] . '","contentitems":' . $contentJson . ',"navigation":' . $navigationJson . '}';
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [END: Constructing return JSON]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::GetContent::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     return $returnJson;
 }
예제 #5
0
 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);
 }
 public function RunWorkflow($json, $key)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [START: Parsing JSON input]", \PEAR_LOG_DEBUG);
     try {
         $contentId = $this->ParseJSONToContentID($json);
         $tagsRemoved = $this->ParseJSONToTags($json, "tagsRemoved");
         $tagsAdded = $this->ParseJSONToTags($json, "tagsAdded");
         if (\count($tagsRemoved) < 1 && \count($tagsAdded) < 1) {
             throw new \InvalidArgumentException("No tagsRemoved or tagsAdded were supplied");
         }
     } catch (\Exception $e) {
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [An exception was thrown:]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [{$e}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         $message = $e->getMessage();
         return parent::FormatErrorMessage("An exception was thrown: {$message})");
     }
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [END: Parsing JSON input]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [START: Constructing the repository]", \PEAR_LOG_DEBUG);
     try {
         //Get the content repository
         $repository = new \Swiftriver\Core\DAL\Repositories\ContentRepository();
     } catch (\Exception $e) {
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [{$e}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         $message = $e->getMessage();
         return parent::FormatErrorMessage("An exception was thrown: {$message})");
     }
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [END: Constructing the repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [START: Getting the subject content]", \PEAR_LOG_DEBUG);
     try {
         //get the content array for the repo
         $contentArray = $repository->GetContent(array($contentId));
         //try and get the first item
         $content = reset($contentArray);
         //check that its not null
         if (!isset($content) || $content == null) {
             throw new \Exception("No content was returned for the ID: {$contentId}");
         }
     } catch (\Exception $e) {
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [{$e}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         $message = $e->getMessage();
         return parent::FormatErrorMessage("An exception was thrown: {$message})");
     }
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [END: Getting the subject content]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [START: Making Tagging Changes]", \PEAR_LOG_DEBUG);
     $originalTags = $content->tags;
     $content->tags = array();
     foreach ($originalTags as $originalTag) {
         $shouldBeRemoved = false;
         foreach ($tagsRemoved as $tagRemoved) {
             if ($tagRemoved->text == $originalTag->text) {
                 $shouldBeRemoved = true;
             }
         }
         if (!$shouldBeRemoved) {
             $content->tags[] = $originalTag;
         }
     }
     foreach ($tagsAdded as $tag) {
         $content->tags[] = $tag;
     }
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [END: Making Tagging Changes]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [START: Saving Content]", \PEAR_LOG_DEBUG);
     try {
         $repository->SaveContent(array($content));
     } catch (\Exception $e) {
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [{$e}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         $message = $e->getMessage();
         return parent::FormatErrorMessage("An exception was thrown: {$message})");
     }
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [END: Saving Content]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [START: Event Distribution]", \PEAR_LOG_DEBUG);
     $eventArguments = array("originalTags" => $originalTags, "tagsAdded" => $tagsAdded, "tagsRemoved" => $tagsRemoved);
     $event = new \Swiftriver\Core\EventDistribution\GenericEvent(\Swiftriver\Core\EventDistribution\EventEnumeration::$UpdateContentTagging, $eventArguments);
     $eventDistributor = new \Swiftriver\Core\EventDistribution\EventDistributor();
     $eventDistributor->RaiseAndDistributeEvent($event);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [END: Event Distribution]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     return parent::FormatMessage("OK");
 }
 public function RunWorkflow($json, $key)
 {
     //Setup the logger
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [START: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     try {
         //call the parser to get the ID
         $id = parent::ParseJSONToContentID($json);
         $markerId = parent::ParseJSONToMarkerID($json);
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [END: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [START: Constructing the repository]", \PEAR_LOG_DEBUG);
     try {
         //Get the content repository
         $repository = new \Swiftriver\Core\DAL\Repositories\ContentRepository();
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [END: Constructing the repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [START: Getting the subject content]", \PEAR_LOG_DEBUG);
     try {
         //get the content array for the repo
         $contentArray = $repository->GetContent(array($id));
         //try and get the first item
         $content = reset($contentArray);
         //check that its not null
         if (!isset($content) || $content == null) {
             throw new \Exception("No content was returned for the ID: {$id}");
         }
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [END: Getting the subject content]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [START: Setting the state to acurate]", \PEAR_LOG_DEBUG);
     //Use the state controller to change the state of the the content to acurate
     $content = \Swiftriver\Core\StateTransition\StateController::MarkContentAcurate($content);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [END: Setting the state to acurate]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [START: Increment source score]", \PEAR_LOG_DEBUG);
     //get the source from the content
     $source = $content->source;
     //if the score is null - not yet rated, then set it
     if (!isset($source->score) || $source->score == null) {
         $source->score = 0;
     }
     //baseline of 0%
     //if the scoure is not already at the maximum
     if ($source->score < 99) {
         $source->score = $source->score + 2;
     }
     //set the scource back to the content
     $content->source = $source;
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [END: Increment source score]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [START: Saving the content and source]", \PEAR_LOG_DEBUG);
     try {
         //save the content to the repo
         $repository->SaveContent(array($content));
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [END: Saving the content and source]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [START: Recording the transaction]", \PEAR_LOG_DEBUG);
     try {
         //get the trust log repo
         $trustLogRepo = new \Swiftriver\Core\DAL\Repositories\TrustLogRepository();
         //get the source id
         $sourceId = $content->source->id;
         //record the new entry
         $trustLogRepo->RecordSourceScoreChange($sourceId, $markerId, 1);
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsAcurate::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [END: Recording the transaction]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [START: Event Distribution]", \PEAR_LOG_DEBUG);
     $event = new \Swiftriver\Core\EventDistribution\GenericEvent(\Swiftriver\Core\EventDistribution\EventEnumeration::$MarkContentAsAccurate, $content);
     $eventDistributor = new \Swiftriver\Core\EventDistribution\EventDistributor();
     $eventDistributor->RaiseAndDistributeEvent($event);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [END: Event Distribution]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsAcurate::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     $return = json_encode(array("sourceId" => $content->source->id, "sourceScore" => $content->source->score));
     return $return;
 }
예제 #8
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");
 }