public function testReturnAllAvailableParsers() { $service = new \Swiftriver\Core\Modules\SiSPS\SwiftriverSourceParsingService(); $parsers = $service->ListAvailableParsers(); $this->assertEquals(2, count($parsers)); $RSSTypes = $parsers[0]->ListSubTypes(); $this->assertEquals("Blogs", $RSSTypes[0]); }
/** * Tests that, given a channel configured to use the Test parser, * the SiSPS can return a list of content items */ public function testFetchContentFromChannelWithTestParser() { $channel = new \Swiftriver\Core\ObjectModel\Channel(); $channel->type = "Test"; $service = new \Swiftriver\Core\Modules\SiSPS\SwiftriverSourceParsingService(); $contentItems = $service->FetchContentFromChannel($channel, null); $this->assertEquals(true, is_array($contentItems)); $this->assertEquals(1, count($contentItems)); $this->assertEquals("testId", $contentItems[0]->id); }
/** * 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); }
/** * 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"); }
/** * 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"); }