Exemplo n.º 1
0
 /**
  * Get all users that don't have to much sites added.
  * @return GWTUser[]
  */
 function getAvailableUsers()
 {
     $users = $this->userRepository->allCountLt($this->getMaxSitesPerAccount());
     $resultUsers = array();
     foreach ($users as $i => $u) {
         /* @var $u GWTUser */
         $sites = $this->webmasterToolsUtil->getSites($u);
         if ($u->getCount() != count($sites)) {
             $u->setCount(count($sites));
             $this->userRepository->update($u);
         }
         if ($u->getCount() < $this->getMaxSitesPerAccount()) {
             $resultUsers[] = $u;
         }
     }
     return $resultUsers;
 }
Exemplo n.º 2
0
<?php

$optionsWithArgs = array('u');
require_once __DIR__ . "/common.php";
GWTLogHelper::notice(__FILE__ . " script starts.");
try {
    $userRepository = new GWTUserRepository();
    if (!isset($options['u'])) {
        GWTLogHelper::error("Specify user (-u).");
        die(1);
    }
    $user = $userRepository->getByEmail($options['u']);
    if ($user == null) {
        GWTLogHelper::error("No such user. Try add_user.php.");
        die(1);
    }
    $util = new WebmasterToolsUtil();
    $sites = $util->getSites($user);
    foreach ($sites as $i => $s) {
        echo $s->getUrl() . " " . $s->getVerified() . "\n";
    }
} catch (Exception $ex) {
    GWTLogHelper::error(__FILE__ . " script failed.", $ex);
}
Exemplo n.º 3
0
         throw new Exception("Failed to update " . $userId . " " . $wikiId);
     }
 }
 function updateUserWikiCount(DatabaseBase $db, $userId, $wikiCount)
 {
     $res = $db->update("webmaster_user_accounts", array("wikis_number" => $wikiCount), array("user_id" => $userId));
     if (!$res) {
         throw new Exception("Failed to update User id=" . $userId . " count = " . $wikiCount);
     }
 }
 $count = 0;
 $service = new WebmasterToolsUtil();
 $userRepository = new GWTUserRepository($db);
 $accounts = $userRepository->all();
 foreach ($accounts as $i => $u) {
     $sites = $service->getSites($u);
     foreach ($sites as $j => $s) {
         $site = $s->getUrl();
         $count++;
         try {
             tryInsertWiki($db, $site);
             tryUpdateWiki($db, $site, $u);
             GWTLogHelper::notice("Insert: {$site} as " . $u->getEmail());
             if ($count % 50 == 0) {
                 sleep(1);
             }
             // slow down
             //echo $u->getEmail() . " " . $site . " success \n";
         } catch (Exception $e) {
             GWTLogHelper::error($u->getEmail() . " " . $site . " failed.", $e);
         }