/** * @return string */ public function consume() { $logger = Logger::getInstance('stream_log_location'); $logger->logInfo("in StreamCollect2->consume()", __METHOD__ . ',' . __LINE__); if ($this->argc != 4) { $logger->logError("error: wrong number of args for StreamCollect2", __METHOD__ . ',' . __LINE__); return; } $instance_id = $this->argv[1]; $user_email = $this->argv[2]; $pw = $this->argv[3]; $output = ""; $pwd_match = false; $owner_dao = DAOFactory::getDAO('OwnerDAO'); $owner = $owner_dao->getByEmail($user_email); $passcheck = $owner_dao->getPass($user_email); if ($passcheck == $pw) { $pwd_match = true; } else { $logger->logError("ERROR: Incorrect username and password.", __METHOD__ . ',' . __LINE__); return; } if ($pwd_match && $instance_id) { $logger->logInfo("working on stream for {$user_email}", __METHOD__ . ',' . __LINE__); if (isset($instance_id)) { $logger->logInfo("setting up stream for instance {$instance_id}", __METHOD__ . ',' . __LINE__); $oid = DAOFactory::getDAO('OwnerInstanceDAO'); $tokens = $oid->getOAuthTokens($instance_id); if (isset($tokens['oauth_access_token']) && $tokens['oauth_access_token'] != '' && isset($tokens['oauth_access_token_secret']) && $tokens['oauth_access_token_secret'] != '') { $stream = ConsumerUserStream::getInstance($tokens['oauth_access_token'], $tokens['oauth_access_token_secret']); if ($stream) { $stream->setKey($user_email, $instance_id); $stream->consume(); } else { return "Error: could not create stream object for instance {$instance_id}\n"; } } else { return "Error: could not get oauth information for user {$user_email}.\n"; } } else { return "Could not find a twitter instance for user {$user_email}.\n"; } } }
/** * @param $owner * @return */ public function consume($owner) { // This version will run just for (first) twitter instance of the given (admin) owner $instance_dao = DAOFactory::getDAO('InstanceDAO'); $instances = $instance_dao->getByOwnerAndNetwork($owner, 'twitter', true); $logger = Logger::getInstance('stream_log_location'); if (isset($instances[0])) { $instance = $instances[0]; $oid = DAOFactory::getDAO('OwnerInstanceDAO'); $tokens = $oid->getOAuthTokens($instance->id); if (isset($tokens['oauth_access_token']) && $tokens['oauth_access_token'] != '' && isset($tokens['oauth_access_token_secret']) && $tokens['oauth_access_token_secret'] != '') { $stream = ConsumerUserStream::getInstance($tokens['oauth_access_token'], $tokens['oauth_access_token_secret']); $stream->consume(); } else { $logger->logError("Error: could not get oauth information for user.", __METHOD__ . ',' . __LINE__); return; } } else { $logger->logError("Error: could not get twitter instance for user.", __METHOD__ . ',' . __LINE__); return; } }
public function testEnqueueStatusMySQL() { $stream_data = $this->setUpData(); $twitter_data = $this->setUpTwitterData(); $consumer_user_stream = new ConsumerUserStream('username', 'password'); $consumer_user_stream->setKey('*****@*****.**', 1); $procs_data = FixtureBuilder::build('stream_procs', array('process_id' => getmypid(), 'email' => '*****@*****.**', 'instance_id' => 1)); $consumer_user_stream->enqueueStatus("string1"); $consumer_user_stream->enqueueStatus("string2"); $sql = "select * from " . $this->table_prefix . "stream_data"; $stmt = PluginOptionMysqlDAO::$PDO->query($sql); $data = $stmt->fetchAll(); $this->assertIdentical($data[0][0], '1'); $this->assertIdentical($data[0][1], 'string1'); $this->assertIdentical($data[0][2], 'twitter'); $this->assertIdentical($data[1][0], '2'); $this->assertIdentical($data[1][1], 'string2'); $this->assertIdentical($data[1][2], 'twitter'); $sql = "select process_id, email, instance_id, unix_timestamp(last_report) as last_report from " . $this->table_prefix . "stream_procs"; $stmt = PluginOptionMysqlDAO::$PDO->query($sql); $data = $stmt->fetchAll(); $process_id = getmypid(); $this->assertIdentical($data[0]['process_id'], $process_id . ''); $recent_time = time() - 50; $this->assertTrue($data[0]['last_report'] > $recent_time); }