예제 #1
0
 public function crawl()
 {
     $logger = Logger::getInstance();
     $config = Config::getInstance();
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
     $owner_dao = DAOFactory::getDAO('OwnerDAO');
     $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
     $options = $plugin_option_dao->getOptionsHash('youtube', true);
     //get cached
     $max_crawl_time = isset($options['max_crawl_time']) ? $options['max_crawl_time']->option_value : 20;
     //convert to seconds
     $max_crawl_time = $max_crawl_time * 60;
     $developer_key = isset($options['developer_key']) ? $options['developer_key']->option_value : null;
     $max_comments = isset($options['max_comments']) ? $options['max_comments']->option_value : null;
     $current_owner = $owner_dao->getByEmail(Session::getLoggedInUser());
     //crawl youtube users
     $instances = $instance_dao->getActiveInstancesStalestFirstForOwnerByNetworkNoAuthError($current_owner, 'youtube');
     if (isset($options['youtube_client_id']->option_value) && isset($options['youtube_client_secret']->option_value)) {
         foreach ($instances as $instance) {
             $logger->setUsername(ucwords($instance->network) . ' | ' . $instance->network_username);
             $logger->logUserSuccess("Starting to collect data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__);
             $tokens = $owner_instance_dao->getOAuthTokens($instance->id);
             $access_token = $tokens['oauth_access_token'];
             $refresh_token = $tokens['oauth_access_token_secret'];
             $instance_dao->updateLastRun($instance->id);
             $youtube_crawler = new YouTubeCrawler($instance, $access_token, $max_crawl_time, $developer_key, $max_comments);
             $dashboard_module_cacher = new DashboardModuleCacher($instance);
             try {
                 $youtube_crawler->initializeInstanceUser($options['youtube_client_id']->option_value, $options['youtube_client_secret']->option_value, $access_token, $refresh_token, $current_owner->id);
                 $youtube_crawler->fetchInstanceUserVideos();
             } catch (Exception $e) {
                 $logger->logUserError('EXCEPTION: ' . $e->getMessage(), __METHOD__ . ',' . __LINE__);
             }
             $dashboard_module_cacher->cacheDashboardModules();
             $instance_dao->save($youtube_crawler->instance, 0, $logger);
             Reporter::reportVersion($instance);
             $logger->logUserSuccess("Finished collecting data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__);
         }
     }
 }
예제 #2
0
 public function testInitializeInstanceUserExpiredToken()
 {
     $ytc = new YouTubeCrawler($this->instance, 'faux-expired-access-token', 10);
     $ytc->initializeInstanceUser('ci', 'cs', 'valid_token', 'test_refresh_token', 1);
     $user_dao = new UserMySQLDAO();
     $user = $user_dao->getUserByName('Gina Trapani', 'youtube');
     $this->assertTrue(isset($user));
     $this->assertEqual($user->username, 'Gina Trapani');
     $this->assertEqual($user->full_name, 'Gina Trapani');
     $this->assertEqual($user->user_id, '113612142759476883204');
     $this->assertEqual($user->location, "San Diego");
     $this->assertEqual($user->description, 'ThinkUp lead developer, This Week in Google co-host, Todo.txt apps creator, founding editor of Lifehacker');
     $this->assertEqual($user->url, 'https://plus.google.com/113612142759476883204');
     $this->assertFalse($user->is_protected);
 }