protected function processQueueFile($queueFile)
{
$logger = \Swiftriver\Core\Setup::GetLogger();
$logger->log("Core::Modules::TwitterStreamingSearchClient start processing " . $queueFile, \PEAR_LOG_DEBUG);
// Open file
$fp = fopen($queueFile, 'r');
// Check if something has gone wrong, or perhaps the file is just locked by another process
if (!is_resource($fp)) {
$logger->log("Core::Modules::TwitterStreamingSearchClient file: " . $queueFile . " already open, skipping", \PEAR_LOG_DEBUG);
return FALSE;
}
// Lock file
flock($fp, LOCK_EX);
$content = array();
$logger->log("Core::Modules::TwitterStreamingSearchClient: START Looping through content", \PEAR_LOG_DEBUG);
while ($rawStatus = fgets($fp, 4096)) {
try {
$status = \json_decode($rawStatus);
$source_name = $status->user->screen_name;
if ($source_name == null || $source_name == "") {
$source_name = "UNKNOWN";
}
$source = \Swiftriver\Core\ObjectModel\ObjectFactories\SourceFactory::CreateSourceFromIdentifier($source_name, false);
$source->name = $source_name;
$source->link = "http://twitter.com/" . $source_name;
$source->parent = "TWITTERSTREAM";
$source->type = "Twitter Stream";
$source->subType = "Filter";
$source->applicationIds["twitter"] = $status->user->id;
$source->applicationProfileImages["twitter"] = $status->user->profile_image_url;
//Create a new Content item
$item = \Swiftriver\Core\ObjectModel\ObjectFactories\ContentFactory::CreateContent($source);
//Fill the Content Item
$item->text[] = new \Swiftriver\Core\ObjectModel\LanguageSpecificText(null, $status->text, array($status->text));
$item->link = "http://twitter.com/" . $source_name . "/statuses/" . $status->id_str;
$item->date = strtotime($status->created_at);
/* GEO is not yet supported on this streamin feed
if($tweet->geo != null && $tweet->geo->type == "Point" && \is_array($tweet->geo->coordinates))
$item->gisData[] = new \Swiftriver\Core\ObjectModel\GisData (
$tweet->geo->coordinates[1],
$tweet->geo->coordinates[0],
"");
*/
//Sanitize the tweet text into a DIF collection
$sanitizedTweetDiffCollection = $this->ParseTweetToSanitizedTweetDiffCollection($item);
//Add the dif collection to the item
$item->difs = array($sanitizedTweetDiffCollection);
$content[] = $item;
} catch (\Exception $e) {
$logger->log("Core::Modules::TwitterStreamingSearchClient: {$e}", \PEAR_LOG_ERR);
}
}
$logger->log("Core::Modules::TwitterStreamingSearchClient: START Looping through content", \PEAR_LOG_DEBUG);
$workflow = new \Swiftriver\Core\Workflows\ContentServices\ProcessContent();
//Here we are running the workflow without pre processing.
$workflow->RunWorkflow($content, false);
// Release lock and close
flock($fp, LOCK_UN);
fclose($fp);
// All done with this file
$logger->log("Core::Modules::TwitterStreamingSearchClient finshed processing " . $queueFile, \PEAR_LOG_DEBUG);
unlink($queueFile);
}