public static function ReturnAllAvailableParsers() { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::Modules::SiSPS::ParserFactory::ReturnAllAvailableParsers [Method invoked]", \PEAR_LOG_DEBUG); $parsers = array(); $logger->log("Core::Modules::SiSPS::ParserFactory::ReturnAllAvailableParsers [START: Directory Itteration]", \PEAR_LOG_DEBUG); $dirItterator = new \RecursiveDirectoryIterator(dirname(__FILE__) . "/Parsers/"); $iterator = new \RecursiveIteratorIterator($dirItterator, \RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file) { if ($file->isFile()) { $filePath = $file->getPathname(); if (strpos($filePath, ".php") && !strpos($filePath, "IParser")) { try { $typeString = "\\Swiftriver\\Core\\Modules\\SiSPS\\Parsers\\" . $file->getFilename(); $type = str_replace(".php", "", $typeString); $object = new $type(); if ($object instanceof Parsers\IParser) { $logger->log("Core::Modules::SiSPS::ParserFactory::ReturnAllAvailableParsers [Adding type {$type}]", \PEAR_LOG_DEBUG); $parsers[] = $object; } } catch (\Exception $e) { $logger->log("Core::Modules::SiSPS::ParserFactory::ReturnAllAvailableParsers [error adding type {$type}]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::ParserFactory::ReturnAllAvailableParsers [{$e}]", \PEAR_LOG_ERR); continue; } } } } $logger->log("Core::Modules::SiSPS::ParserFactory::ReturnAllAvailableParsers [END: Directory Itteration]", \PEAR_LOG_DEBUG); return $parsers; }
/** * Implementation of IParser::GetAndParse * @param \Swiftriver\Core\ObjectModel\Channel $channel * @param datetime $lassucess */ public function GetAndParse($channel) { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::Modules::SiSPS::Parsers::IMAPParser::GetAndParse [Method invoked]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::IMAPParser::GetAndParse [START: Extracting required parameters]", \PEAR_LOG_DEBUG); //Extract the IMAP parameters $imapHostName = $channel->parameters["IMAPHostName"]; $imapUserName = $channel->parameters["IMAPUserName"]; $imapPassword = $channel->parameters["IMAPPassword"]; if (!isset($imapHostName) || $imapHostName == "") { $logger->log("Core::Modules::SiSPS::Parsers::IMAPParser::GetAndParse [the parameter 'IMAPHostName' was not supplied. Returning null]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::IMAPParser::GetAndParse [Method finished]", \PEAR_LOG_DEBUG); return null; } if (!isset($imapUserName) || $imapUserName == "") { $logger->log("Core::Modules::SiSPS::Parsers::IMAPParser::GetAndParse [the parameter 'IMAPUserName' was not supplied. Returning null]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::IMAPParser::GetAndParse [Method finished]", \PEAR_LOG_DEBUG); return null; } if (!isset($imapPassword) || $imapPassword == "") { $logger->log("Core::Modules::SiSPS::Parsers::IMAPParser::GetAndParse [the parameter 'IMAPPassword' was not supplied. Returning null]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::IMAPParser::GetAndParse [Method finished]", \PEAR_LOG_DEBUG); return null; } $logger->log("Core::Modules::SiSPS::Parsers::IMAPParser::GetAndParse [END: Extracting required parameters]", \PEAR_LOG_DEBUG); //Create the Content array $contentItems = array(); $logger->log("Core::Modules::SiSPS::Parsers::IMAPParser::GetAndParse [START: Parsing IMAP items]", \PEAR_LOG_DEBUG); //Get information regarding the source $contentItems = $this->GetIMAPContent($imapHostName, $imapUserName, $imapPassword, $channel); $logger->log("Core::Modules::SiSPS::Parsers::IMAPParser::GetAndParse [END: Parsing IMAP items]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::IMAPParser::GetAndParse [Method finished]", \PEAR_LOG_DEBUG); //return the content array return $contentItems; }
/** * Returns all the classes that implment the IPreProcessor interface * @return IPreProcessingStep[] */ public function ListAllAvailablePreProcessingSteps() { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::PreProcessing::PreProcessor::ListAllAvailablePreProcessingSteps [Method invoked]", \PEAR_LOG_DEBUG); $steps = array(); $modulesDirectory = \Swiftriver\Core\Setup::Configuration()->ModulesDirectory; $dirItterator = new \RecursiveDirectoryIterator($modulesDirectory); $iterator = new \RecursiveIteratorIterator($dirItterator, \RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file) { if ($file->isFile()) { $filePath = $file->getPathname(); if (strpos($filePath, "PreProcessingStep.php")) { try { include_once $filePath; $typeString = "\\Swiftriver\\PreProcessingSteps\\" . $file->getFilename(); $type = str_replace(".php", "", $typeString); $object = new $type(); if ($object instanceof IPreProcessingStep) { $logger->log("Core::PreProcessing::PreProcessor::ListAllAvailablePreProcessingSteps [Adding type {$type}]", \PEAR_LOG_DEBUG); $object->filePath = str_replace($modulesDirectory, "", $filePath); $object->type = $type; $steps[] = $object; } } catch (\Exception $e) { $logger->log("Core::PreProcessing::PreProcessor::ListAllAvailablePreProcessingSteps [error adding type {$type}]", \PEAR_LOG_DEBUG); $logger->log("Core::PreProcessing::PreProcessor::ListAllAvailablePreProcessingSteps [{$e}]", \PEAR_LOG_ERR); continue; } } } } $logger->log("Core::PreProcessing::PreProcessor::ListAllAvailablePreProcessingSteps [Method finished]", \PEAR_LOG_DEBUG); return $steps; }
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($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 static function CreateChannel($json) { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::ObjectModel::ObjectFactories::ChannelFactory::CreateChannel [Method invoked]", \PEAR_LOG_DEBUG); $logger->log("Core::ObjectModel::ObjectFactories::ChannelFactory::CreateChannel [Calling json_decode]", \PEAR_LOG_DEBUG); $data = json_decode($json); $logger->log("Core::ObjectModel::ObjectFactories::ChannelFactory::CreateChannel [Extracting data from the JSON objects]", \PEAR_LOG_DEBUG); if (!isset($data) || !$data) { throw new \InvalidArgumentException("There was an error in the JSON. No Channel can be constructed."); } $logger->log("Core::ObjectModel::ObjectFactories::ChannelFactory::CreateChannel [Extracting values from the data]", \PEAR_LOG_DEBUG); $logger->log("Core::ObjectModel::ObjectFactories::ChannelFactory::CreateChannel [Constructing Channel object]", \PEAR_LOG_DEBUG); $channel = new \Swiftriver\Core\ObjectModel\Channel(); $channel->id = isset($data->id) ? $data->id : null; $channel->type = $data->type; $channel->updatePeriod = $data->updatePeriod; $channel->active = isset($data->active) ? $data->active : true; $channel->lastSucess = isset($data->lastSucess) ? $data->lastSucess : null; $channel->inprocess = isset($data->inprocess) ? $data->inprocess : false; $params = array(); foreach ($data->parameters as $key => $value) { $params[$key] = $value; } $channel->parameters = $params; //set key values if they have not been set $channel = ChannelFactory::SetValuesIfNotSet($channel, array("id" => md5(uniqid(rand(), true)), "active" => true, "nextrun" => time() + $channel->updatePeriod * 60)); $logger->log("Core::ObjectModel::ObjectFactories::ChannelFactory::CreateChannel [Method finished]", \PEAR_LOG_DEBUG); return $channel; }
/** * Function that when called with appropriate json will * initiate an Analytics call that may return data that * can be used by the calling class. * * @param string $json * @param string $key * @return string */ public function RunQuery($json, $key) { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::Workflows::Analaytics::RunAnalyticsQuery::RunQuery [Method invoked]", \PEAR_LOG_INFO); $logger->log("Core::Workflows::Analaytics::RunAnalyticsQuery::RunQuery [START: Parsing input JSON]", \PEAR_LOG_DEBUG); try { $requestType = parent::ParseJSONToRequestType($json); $parameters = parent::ParseJSONToRequestParameters($json); $request = new \Swiftriver\Core\Analytics\AnalyticsRequest(); $request->RequestType = $requestType; $request->Parameters = $parameters; } catch (\Exception $e) { $logger->log("Core::Workflows::Analaytics::RunAnalyticsQuery::RunQuery [An Exception was thrown]", \PEAR_LOG_ERR); $logger->log("Core::Workflows::Analaytics::RunAnalyticsQuery::RunQuery [{$e}]", \PEAR_LOG_ERR); $logger->log("Core::Workflows::Analaytics::RunAnalyticsQuery::RunQuery [Method finished]", \PEAR_LOG_INFO); return parent::FormatErrorMessage("An exception was thrown: " . $e->getMessage()); } $logger->log("Core::Workflows::Analaytics::RunAnalyticsQuery::RunQuery [END: Parsing input JSON]", \PEAR_LOG_DEBUG); $logger->log("Core::Workflows::Analaytics::RunAnalyticsQuery::RunQuery [START: Running Analytics Query]", \PEAR_LOG_DEBUG); try { $analyticsEngine = new \Swiftriver\Core\Analytics\AnalyticsEngine(); $response = $analyticsEngine->RunAnalyticsRequest($request); $return = \json_encode($response->Result); } catch (\Exception $e) { $logger->log("Core::Workflows::Analaytics::RunAnalyticsQuery::RunQuery [An Exception was thrown]", \PEAR_LOG_ERR); $logger->log("Core::Workflows::Analaytics::RunAnalyticsQuery::RunQuery [{$e}]", \PEAR_LOG_ERR); $logger->log("Core::Workflows::Analaytics::RunAnalyticsQuery::RunQuery [Method finished]", \PEAR_LOG_INFO); return parent::FormatErrorMessage("An exception was thrown: " . $e->getMessage()); } $logger->log("Core::Workflows::Analaytics::RunAnalyticsQuery::RunQuery [END: Running Analytics Query]", \PEAR_LOG_DEBUG); $logger->log("Core::Workflows::Analaytics::RunAnalyticsQuery::RunQuery [Method finished]", \PEAR_LOG_INFO); return parent::FormatReturn($return); }
/** * Implementation of IParser::GetAndParse * @param \Swiftriver\Core\ObjectModel\Channel $channel * @return Swiftriver\Core\ObjectModel\Content[] contentItems */ public function GetAndParse($channel) { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::Modules::SiSPS::Parsers::FrontlineSMSParser::GetAndParse [Method invoked]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::FrontlineSMSParser::GetAndParse [END: Extracting required parameters]", \PEAR_LOG_DEBUG); //Create the Content array $contentItems = array(); switch ($channel->subType) { case "Remote": $logger->log("Core::Modules::SiSPS::Parsers::FrontlineSMSParser::GetAndParse [START: Parsing SMS items from Remote API]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::FrontlineSMSParser::GetAndParse [START: Extracting required parameters]", \PEAR_LOG_DEBUG); //Extract the Server URL $serverURL = $channel->parameters["ServerURL"]; if (!isset($serverURL)) { $logger->log("Core::Modules::SiSPS::Parsers::FrontlineSMSParser::GetAndParse [the parameter 'ServerURL' was not supplied. Returning null]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::FrontlineSMSParser::GetAndParse [Method finished]", \PEAR_LOG_DEBUG); return null; } $contentItems = $this->getRemoteContentItems($channel, $logger, $serverURL); $logger->log("Core::Modules::SiSPS::Parsers::FrontlineSMSParser::GetAndParse [END: Parsing SMS items from Remote API]", \PEAR_LOG_DEBUG); break; case "Local": $logger->log("Core::Modules::SiSPS::Parsers::FrontlineSMSParser::GetAndParse [START: Parsing SMS items from Local DB]", \PEAR_LOG_DEBUG); $contentItems = $this->getLocalContentItems($channel, $logger); $logger->log("Core::Modules::SiSPS::Parsers::FrontlineSMSParser::GetAndParse [END: Parsing SMS items from Local DB]", \PEAR_LOG_DEBUG); break; } //return the content array return $contentItems; }
public function ParseStepsToJson($steps) { $modulesConfig = \Swiftriver\Core\Setup::DynamicModuleConfiguration(); $return; $return->steps = array(); foreach ($steps as $step) { $s; $s->name = $step->Name(); $s->description = $step->Description(); $s->configurationProperties = $step->ReturnRequiredParameters(); if (array_key_exists($s->name, $modulesConfig->Configuration)) { $configuration = $modulesConfig->Configuration[$s->name]; if ($configuration != null) { foreach ($s->configurationProperties as $property) { foreach ($configuration as $key => $config) { if ($property->name == $key) { $property->value = $config->value; } } } } } $s->active = isset($step->active); $return->steps[] = $s; unset($s); } return json_encode($return); }
/** * Activates the channel processing job * * @param string $json * @return string $json */ public function RunService($json) { //Setup the logger $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ActivateChannelProcessingJob::RunService [Method invoked]", \PEAR_LOG_INFO); $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ActivateChannelProcessingJob::RunService [START: Parsing the JSON input]", \PEAR_LOG_DEBUG); //Parse the JSON input $channel = parent::ParseJSONToChannel($json); if (!isset($channel)) { $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ActivateChannelProcessingJob::RunService [ERROR: Method ParseIncommingJSON returned null]", \PEAR_LOG_DEBUG); $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ActivateChannelProcessingJob::RunService [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::ServiceAPI::ChannelProcessingJobClasses::ActivateChannelProcessingJob::RunService [END: Parsing the JSON input]", \PEAR_LOG_DEBUG); $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ActivateChannelProcessingJob::RunService [START: Constructing Repository]", \PEAR_LOG_DEBUG); //Construct a new repository $repository = new \Swiftriver\Core\DAL\Repositories\ChannelProcessingJobRepository(); $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ActivateChannelProcessingJob::RunService [END: Constructing Repository]", \PEAR_LOG_DEBUG); $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ActivateChannelProcessingJob::RunService [START: Activatin Processing Job]", \PEAR_LOG_DEBUG); //Activate the channel processing job $repository->ActivateChannelProcessingJob($channel); $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ActivateChannelProcessingJob::RunService [END: Activating Processing Job]", \PEAR_LOG_DEBUG); $logger->log("Core::ServiceAPI::ChannelProcessingJobClasses::ActivateChannelProcessingJob::RunService [Method finished]", \PEAR_LOG_INFO); //return an OK messagae return parent::FormatMessage("OK"); }
public static function Toolbox() { //if not the first time this is called if (isset(self::$toolbox)) { return self::$toolbox; } //else set up the RedBean toolbox require_once \Swiftriver\Core\Setup::Configuration()->ModulesDirectory . "/RedBean/redbean.inc.php"; //get the url of the url of the db server $url = (string) Setup::$Configuration->DataBaseUrl; //Get the db username $username = (string) Setup::$Configuration->UserName; //get the password $password = (string) Setup::$Configuration->Password; //get the db name $database = (string) Setup::$Configuration->Database; //set the db type $typeofdatabase = "mysql"; //Assemble a database connection string (DSN) $dsn = "{$typeofdatabase}:host={$url};dbname={$database}"; //Construct a new Red Bean Toolbox, if it has not been set in the mean time if (!isset(self::$toolbox)) { self::$toolbox = \RedBean_Setup::kickstartDev($dsn, $username, $password); } //return it return self::$toolbox; }
/** * Constructor Method * @param string $uri */ public function __construct($uri) { $this->uri = $uri; $this->proxy = \Swiftriver\Core\Setup::Configuration()->ProxyServer; $this->proxyUsername = \Swiftriver\Core\Setup::Configuration()->ProxyServerUserName; $this->proxyPassword = \Swiftriver\Core\Setup::Configuration()->ProxyServerPassword; }
function mongo_analytics($request) { $logger = \Swiftriver\Core\Setup::GetLogger(); $parameters = $request->Parameters; $yearDay = (int) \date('z'); $timeLimit = 5; if (\is_array($parameters)) { if (\key_exists("TimeLimit", $parameters)) { $timeLimit = (int) $parameters["TimeLimit"]; } } $date = \strtotime("-{$timeLimit} days"); $channel_array = array(); $request->Result = null; try { $db_content = parent::PDOConnection($request); $db_sources = parent::PDOConnection($request); $db_channels = parent::PDOConnection($request); $db_content->where(array("date" => array('$gte' => $date))); $content_items = $db_content->get("content"); $logger->log("Swiftriver::AnalyticsProviders::TotalContentByChannelAnalyticsProvider::ProvideAnalytics [Selected date: {$date}]", \PEAR_LOG_INFO); $logger->log("Swiftriver::AnalyticsProviders::TotalContentByChannelAnalyticsProvider::ProvideAnalytics [" . \count($content_items) . " number of content items retrieved]", \PEAR_LOG_INFO); $channel_array = array(); foreach ($content_items as $content_item) { $source_id = $content_item["source"]["id"]; $source_items = $db_sources->get_where("sources", array("id" => $source_id)); $logger->log("Swiftriver::AnalyticsProviders::TotalContentByChannelAnalyticsProvider::ProvideAnalytics [" . \count($source_items) . " number of source items retrieved]", \PEAR_LOG_INFO); foreach ($source_items as $source_item) { $channel_id = $source_item["channelId"]; if (!\in_array($channel_id, $channel_array)) { $channel_array[$channel_id] = array(); } $channels = $db_channels->get_where("channels", array("id" => $channel_id)); $logger->log("Swiftriver::AnalyticsProviders::TotalContentByChannelAnalyticsProvider::ProvideAnalytics [" . \count($channels) . " number of channels retrieved]", \PEAR_LOG_INFO); foreach ($channels as $channel) { $channel_array[$channel_id]["channelId"] = $channel_id; $channel_array[$channel_id]["channelName"] = $channel["name"]; if (!\in_array($channel_id, $channel_array[$channel_id]["numberOfContentItems"])) { $channel_array[$channel_id]["numberOfContentItems"] = 1; } else { $channel_array[$channel_id]["numberOfContentItems"] += 1; } $channel_array[$channel_id]["channelType"] = $content_item["source"]["type"]; $channel_array[$channel_id]["channelSubType"] = $content_item["source"]["subType"]; } } } } catch (\MongoException $e) { $logger->log("Swiftriver::AnalyticsProviders::ContentByChannelOverTimeAnalyticsProvider::ProvideAnalytics [An exception was thrown]", \PEAR_LOG_ERR); $logger->log("Swiftriver::AnalyticsProviders::ContentByChannelOverTimeAnalyticsProvider::ProvideAnalytics [{$e}]", \PEAR_LOG_ERR); } foreach ($channel_array as $channel_array_item) { if ($request->Result == null) { $request->Result = array(); } $request->Result[] = $channel_array_item; } return $request; }
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"); }
/** * This method redords the fact that a marker (sweeper) has changed the score * of a source by marking a content items as either 'acurate', 'chatter' or * 'inacurate' * * @param string $sourceId * @param string $markerId * @param int $change */ public function RecordSourceScoreChange($sourceId, $markerId, $change, $reason = null) { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::DAL::Repositories::TrustLogRepository::RecordSourceScoreChange [Method invoked]", \PEAR_LOG_DEBUG); $dc = new $this->dataContext(); $dc::RecordSourceScoreChange($sourceId, $markerId, $change, $reason); $logger->log("Core::DAL::Repositories::TrustLogRepository::RecordSourceScoreChange [Method Finished]", \PEAR_LOG_DEBUG); }
public function RunWorkflow($key) { $filename = \Swiftriver\Core\Setup::Configuration()->CachingDirectory . "/TwitterStreamingController.go"; if (!\file_exists($filename)) { return parent::FormatReturn('{"IsActive":false}'); } return parent::FormatReturn('{"IsActive":true}'); }
/** * The constructor for this repository * Accepts the fully qulaified type of the IContentDataContext implemting * data context for this repository * * @param string $dataContext */ public function __construct($dataContext = null) { if (!isset($dataContext)) { $dataContext = \Swiftriver\Core\Setup::DALConfiguration()->DataContextType; } $classType = (string) $dataContext; $this->dataContext = new $classType(); }
/** * Removes a registered API key * Returns true on sucess * * @param string $key * @return bool */ public function RemoveRegisteredAPIKey($key) { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::DAL::Repositories::APIKeyRepository::RemoveRegisteredAPIKey [Method invoked]", \PEAR_LOG_DEBUG); $dc = $this->dataContext; $dc::RemoveRegisteredCoreAPIKey($key); $logger->log("Core::DAL::Repositories::APIKeyRepository::RemoveRegisteredAPIKey [Method finished]", \PEAR_LOG_DEBUG); }
public function test() { include_once dirname(__FILE__) . "/../../../Setup.php"; include_once dirname(__FILE__) . "/../../../Modules/UshahidiAPIInterface/UshahidiAPIEventHandler.php"; $event->arguments = new \Swiftriver\Core\ObjectModel\Content(); $configuration->ModulesDirectory = dirname(__FILE__) . "/../../../Modules/"; $handler = new \Swiftriver\EventHandlers\UshahidiAPIEventHandler(); $handler->HandleEvent($event, $configuration, \Swiftriver\Core\Setup::GetLogger()); }
/** * Lists all the current Source in the core * @return \Swiftriver\Core\ObjectModel\Source[] */ public function ListAllSources() { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::DAL::Repositories::SourceRepository::ListAllSources [Method invoked]", \PEAR_LOG_DEBUG); $dc = $this->dataContext; $sources = $dc::ListAllSources(); $logger->log("Core::DAL::Repositories::SourceRepository::ListAllSources [Method Finished]", \PEAR_LOG_DEBUG); return $sources; }
/** * Interface method that all PrePorcessing Steps must implement * * @param \Swiftriver\Core\ObjectModel\Content[] $contentItems * @param \Swiftriver\Core\Configuration\ConfigurationHandlers\CoreConfigurationHandler $configuration * @param \Log $logger * @return \Swiftriver\Core\ObjectModel\Content[] */ public function Process($contentItems, $configuration, $logger) { try { $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [Method invoked]", \PEAR_LOG_DEBUG); $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [START: Loading module configuration]", \PEAR_LOG_DEBUG); $config = \Swiftriver\Core\Setup::DynamicModuleConfiguration()->Configuration; if (!key_exists($this->Name(), $config)) { $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [The SiCDS Pre Processing Step was called but no configuration exists for this module]", \PEAR_LOG_ERR); $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [Method finished]", \PEAR_LOG_DEBUG); return $contentItems; } $config = $config[$this->Name()]; foreach ($this->ReturnRequiredParameters() as $requiredParam) { if (!key_exists($requiredParam->name, $config)) { $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [The SiCDS Pre Processing Step was called but all the required configuration properties could not be loaded]", \PEAR_LOG_ERR); $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [Method finished]", \PEAR_LOG_DEBUG); return $contentItems; } } $apiKey = (string) $config["API Key"]->value; $serviceUrl = (string) $config["Service Url"]->value; $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [END: Loading module configuration]", \PEAR_LOG_DEBUG); $uniqueContentItems = array(); $parser = new \Swiftriver\SiCDSInterface\Parser(); $serviceInterface = new \Swiftriver\SiCDSInterface\ServiceInterface(); $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [START: Looping through the content items]", \PEAR_LOG_DEBUG); foreach ($contentItems as $item) { try { $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [START: Parsing content item into JSON]", \PEAR_LOG_DEBUG); $jsonForService = $parser->ParseItemToRequestJson($item, $apiKey); $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [END: Parsing content item into JSON]", \PEAR_LOG_DEBUG); $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [START: Calling the SiCDS]", \PEAR_LOG_DEBUG); $jsonFromService = $serviceInterface->InterafceWithService($serviceUrl, $jsonForService, $configuration); $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [END: Calling the SiCDS]", \PEAR_LOG_DEBUG); if ($parser->ContentIsUnique($jsonFromService, $item->id)) { $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [Content with Id: {$item->id} is unique]", \PEAR_LOG_DEBUG); $uniqueContentItems[] = $item; } else { $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [Content with Id: {$item->id} a duplicate]", \PEAR_LOG_DEBUG); } } catch (\Exception $e) { $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [An exception was thrown]", \PEAR_LOG_ERR); $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [{$e}]", \PEAR_LOG_ERR); $uniqueContentItems[] = $item; } } $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [END: Looping through the content items]", \PEAR_LOG_DEBUG); $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [Method finished]", \PEAR_LOG_DEBUG); return $uniqueContentItems; } catch (\Exception $e) { $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [An exception was thrown]", \PEAR_LOG_ERR); $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [{$e}]", \PEAR_LOG_ERR); $logger->log("Swiftriver::PreProcessingSteps::SiCDSPreProcessingStep::Process [Method finished]", \PEAR_LOG_DEBUG); return $contentItems; } }
public function ListAvailableParsers() { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::Modules::SiSPS::SwiftriverPushParsingService::ListAvailableChannels [Method invoked]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::SwiftriverPushParsingService::ListAvailableChannels [START: Getting All Parsers from the ParserFactory]", \PEAR_LOG_DEBUG); $parsers = ParserFactory::ReturnAllAvailablePushParsers(); $logger->log("Core::Modules::SiSPS::SwiftriverPushParsingService::ListAvailableChannels [END: Getting All Parsers from the ParserFactory]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::SwiftriverPushParsingService::ListAvailableChannels [Method finished]", \PEAR_LOG_DEBUG); return $parsers; }
public function test() { include_once dirname(__FILE__) . "/../../../Setup.php"; include_once dirname(__FILE__) . "/../../../Modules/SiLCCInterface/SiLCCPreProcessingStep.php"; $service = new ServiceInterface(); $uri = "http://opensilcc.com/api/tag"; $text = urlencode("In 1972, a crack commando unit was sent to prison by a military court for a crime they didn't commit. They promptly escaped from a maximum security stockade to the Los Angeles underground. Today, still wanted by the government, they survive as soldiers of fortune. If you have a problem, if no-one else can help, and if you can find them, maybe you can hire the A-Team."); $config = \Swiftriver\Core\Setup::COnfiguration(); $json = $service->InterafceWithService($uri, $text, $config); $this->assertEquals('["crack", "commando", "unit", "prison", "court", "crime", "commit", "maximum", "security", "stockade", "Los", "Angeles", "underground", "Today", "government", "soldier", "fortune", "problem", "A-Team"]', $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"); }
/** * This function should allow calling classes to run basic sql select * statements and switch the implmentation based on the data content * type. * * @param string $sql * @return array["results","errors"] */ public function RunGenericQuery($sql) { $dataContext = \Swiftriver\Core\Setup::DALConfiguration()->DataContextType; switch ($dataContext) { case "\\Swiftriver\\Core\\Modules\\DataContext\\MySql_V2\\DataContext": $db = \Swiftriver\Core\Modules\DataContext\MySql_V2\DataContext::PDOConnection(); $statement = $db->prepare($sql); $result = $statement->execute(); return $result == false ? array("results" => array(), "errors" => $statement->errorInfo()) : array("results" => $statement->fetchAll(), "errors" => null); } }
public function RunWorkflow($key) { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::ServiceAPI::TwitterStreamingServices::StopTwitterStreamer::RunWorkflow [Method invoked]", \PEAR_LOG_INFO); $filename = \Swiftriver\Core\Setup::Configuration()->CachingDirectory . "/TwitterStreamingController.go"; if (\file_exists($filename)) { \unlink($filename); } $logger->log("Core::ServiceAPI::TwitterStreamingServices::StopTwitterStreamer::RunWorkflow [Method finished]", \PEAR_LOG_INFO); return '{"message":"OK"}'; }
public function test() { include_once dirname(__FILE__) . "/../../../Setup.php"; include_once dirname(__FILE__) . "/../../../Modules/TagTheNetInterface/Setup.php"; include_once dirname(__FILE__) . '/../../../Modules/TagTheNetInterface/ServiceInterface.php'; $service = new ServiceInterface(); $uri = "http://tagthe.net/api/"; $text = urlencode("In 1972, a crack commando unit was sent to prison by a military court for a crime they didn't commit. They promptly escaped from a maximum security stockade to the Los Angeles underground. Today, still wanted by the government, they survive as soldiers of fortune. If you have a problem, if no-one else can help, and if you can find them, maybe you can hire the A-Team."); $config = \Swiftriver\Core\Setup::COnfiguration(); $json = $service->InterafceWithService($uri, $text, $config); $this->assertEquals(true, 0 != strpos($json, '"dimensions":{"topic":["unit","prison","crack","crime","maximum","stockade","court","commando","security","underground"],"location":["Los Angeles"],"language":["english"]}}]}')); }
/** * Adds the pre processing job to the DAL * * @param string $json * @return string $json */ public function RunWorkflow($json, $key) { //Setup the logger $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [Method invoked]", \PEAR_LOG_INFO); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::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::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [{$message}]", \PEAR_LOG_ERR); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [Method finished]", \PEAR_LOG_INFO); return parent::FormatErrorMessage("An exception was thrown: {$message}"); } if (!isset($channel)) { $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [ERROR: Method ParseIncommingJSON returned null]", \PEAR_LOG_DEBUG); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::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::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [END: Parsing the JSON input]", \PEAR_LOG_DEBUG); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [START: Constructing Repository]", \PEAR_LOG_DEBUG); try { //Construct a new repository $repository = new \Swiftriver\Core\DAL\Repositories\ChannelProcessingJobRepository(); } catch (\Exception $e) { //get the exception message $message = $e->getMessage(); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [{$message}]", \PEAR_LOG_ERR); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [Method finished]", \PEAR_LOG_INFO); return parent::FormatErrorMessage("An exception was thrown: {$message}"); } $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [END: Constructing Repository]", \PEAR_LOG_DEBUG); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [START: Saving Processing Job]", \PEAR_LOG_DEBUG); try { //Add the channel processign job to the repository $repository->SaveChannelProgessingJob($channel); } catch (\Exception $e) { //get the exception message $message = $e->getMessage(); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [{$message}]", \PEAR_LOG_ERR); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [Method finished]", \PEAR_LOG_INFO); return parent::FormatErrorMessage("An exception was thrown: {$message}"); } $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [END: Saving Processing Job]", \PEAR_LOG_DEBUG); $logger->log("Core::ServiceAPI::ChannelProcessingJobs::RegisterNewProcessingJob::RunWorkflow [Method finished]", \PEAR_LOG_INFO); //return an OK messagae return parent::FormatMessage("OK"); }
/** * Implementation of IParser::GetAndParse * @param \Swiftriver\Core\ObjectModel\Channel $channel * @param datetime $lassucess */ public function GetAndParse($channel) { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::Modules::SiSPS::Parsers::EventfulParser::GetAndParse [Method invoked]", \PEAR_LOG_DEBUG); $contentItems = array(); $logger->log("Core::Modules::SiSPS::Parsers::EventfulParser::GetAndParse [START: Extracting required parameters]", \PEAR_LOG_DEBUG); //Extract the required variables $apikey = $channel->parameters["APIKEY"]; if (!isset($apikey) || $apikey == "") { $logger->log("Core::Modules::SiSPS::Parsers::EventfulParser::GetAndParse [the parameter 'APIKEY' was not supplied. Returning null]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::EventfulParser::GetAndParse [Method finished]", \PEAR_LOG_DEBUG); return null; } $logger->log("Core::Modules::SiSPS::Parsers::EventfulParser::GetAndParse [END: Extracting required parameters]", \PEAR_LOG_DEBUG); try { $json = \file_get_contents("http://api.eventful.com/rest/demands/members/list?app_key=" . $apikey); $object = \json_decode($json); $source_name = "Eventful"; $source = \Swiftriver\Core\ObjectModel\ObjectFactories\SourceFactory::CreateSourceFromIdentifier($source_name, $channel->trusted); $source->name = $source_name; $source->link = "http://eventful.com"; $source->parent = $channel->id; $source->type = $channel->type; $source->subType = $channel->subType; foreach ($object->members as $event) { if (!isset($event->time_stamp) || !isset($event->longitude) || !isset($event->latitude) || !isset($event->location) || !isset($event->unique_id)) { $logger->log("Core::Modules::SiSPS::Parsers::EventfulParser::GetAndParse [One event did not have the required parameters]", \PEAR_LOG_ERR); continue; } $contentdate = \strtotime($event->time_stamp); if (isset($channel->lastSuccess) && is_numeric($channel->lastSuccess) && isset($contentdate) && is_numeric($contentdate)) { if ($contentdate < $channel->lastSuccess) { $textContentDate = date("c", $contentdate); $textlastSuccess = date("c", $channel->lastSuccess); $logger->log("Core::Modules::SiSPS::Parsers::EventfulParser::GetAndParse [Skipped feed item as date {$textContentDate} less than last sucessful run ({$textlastSuccess})]", \PEAR_LOG_DEBUG); continue; } } $item = \Swiftriver\Core\ObjectModel\ObjectFactories\ContentFactory::CreateContent($source); //Fill the Content Item $item->text[] = new \Swiftriver\Core\ObjectModel\LanguageSpecificText(null, "Eventful event in " . $event->location, array("Eventful event in " . $event->location)); $item->link = "http://eventful.com"; $item->date = $contentdate; $item->gisData[] = new \Swiftriver\Core\ObjectModel\GisData($event->longitude, $event->latitude, $event->location); $contentItems[] = $item; } } catch (\Exception $e) { $logger->log("Core::Modules::SiSPS::Parsers::EventfulParser::GetAndParse [{$e}]", \PEAR_LOG_ERR); } $logger->log("Core::Modules::SiSPS::Parsers::EventfulParser::GetAndParse [Method finished]", \PEAR_LOG_DEBUG); //return the content array return $contentItems; }
/** * Returns all the classes that implment the IPreProcessor interface * * @return IPreProcessingStep[] */ public function ListAllAvailablePreProcessingSteps() { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::PreProcessing::PreProcessor::ListAllAvailablePreProcessingSteps [Method invoked]", \PEAR_LOG_DEBUG); //set up the array to hold the steps $steps = array(); //Get the path of the modules directory $modulesDirectory = \Swiftriver\Core\Setup::Configuration()->ModulesDirectory; //Create a recursive directory ittorator $dirItterator = new \RecursiveDirectoryIterator($modulesDirectory); $iterator = new \RecursiveIteratorIterator($dirItterator, \RecursiveIteratorIterator::SELF_FIRST); //Itterate over all the files in all the directories foreach ($iterator as $file) { //If not a file continue if (!$file->isFile()) { continue; } //get the full file path $filePath = $file->getPathname(); //If not a pre processing step then continue if (!strpos($filePath, "PreProcessingStep.php")) { continue; } try { //Include the file include_once $filePath; //create a type string for the pre processing step $typeString = "\\Swiftriver\\PreProcessingSteps\\" . $file->getFilename(); //remove the .php extension $type = str_replace(".php", "", $typeString); //instanciate the pre processing step $object = new $type(); //Check that the object implements the IPreProcessingStep if (!$object instanceof IPreProcessingStep) { continue; } $logger->log("Core::PreProcessing::PreProcessor::ListAllAvailablePreProcessingSteps [Adding type {$type}]", \PEAR_LOG_DEBUG); //Add the file name to the step element $object->filePath = str_replace($modulesDirectory, "", $filePath); //Add the type to the step element $object->type = $type; //Add the object to the array $steps[] = $object; } catch (\Exception $e) { $logger->log("Core::PreProcessing::PreProcessor::ListAllAvailablePreProcessingSteps [error adding type {$type}]", \PEAR_LOG_DEBUG); $logger->log("Core::PreProcessing::PreProcessor::ListAllAvailablePreProcessingSteps [{$e}]", \PEAR_LOG_ERR); continue; } } $logger->log("Core::PreProcessing::PreProcessor::ListAllAvailablePreProcessingSteps [Method finished]", \PEAR_LOG_DEBUG); return $steps; }