<?php // example: SERVER_ID=5915 php maintenance/wikia/GoogleWebmasterToolsSync/list_users.php --conf /usr/wikia/docroot/wiki.factory/LocalSettings.php require_once __DIR__ . "/common.php"; GWTLogHelper::notice(__FILE__ . " script starts."); try { $userRepository = new GWTUserRepository(); $users = $userRepository->all(); foreach ($users as $i => $u) { echo "[ id = " . $u->getId() . " ] " . $u->getEmail() . " " . $u->getCount() . "\n"; } } catch (Exception $ex) { GWTLogHelper::error(__FILE__ . " script failed.", $ex); }
<?php // example: SERVER_ID=5915 php maintenance/wikia/GoogleWebmasterToolsSync/list_users.php --conf /usr/wikia/docroot/wiki.factory/LocalSettings.php $freeSlotsWarning = 100; $warningEmails = ["*****@*****.**"]; require_once __DIR__ . "/common.php"; GWTLogHelper::notice(__FILE__ . " script starts."); try { $gwt = new GWTService(null, null, null); $users = $gwt->getAvailableUsers(); $unsyncWikisCount = sizeof($gwt->getWikisToUpload()); $limitPerAccout = $gwt->getMaxSitesPerAccount(); $freeSlots = 0; foreach ($users as $user) { /* @var $user GWTUser */ $freeSlots += $limitPerAccout - $user->getCount(); } GWTLogHelper::notice("FREE SLOTS: {$freeSlots}"); if ($freeSlots < $freeSlotsWarning) { foreach ($warningEmails as $warningEmail) { UserMailer::send(new MailAddress($warningEmail), new MailAddress('*****@*****.**', 'GoogleWebmasterToolsService'), 'GA Webmaster Tools Accounts - ' . $freeSlots . ' slots left', 'There is only ' . $freeSlots . " slots left. Please add new accounts to our database.\n" . 'There is ' . $unsyncWikisCount . ' unsync wikis.', null, 'text/html; charset=ISO-8859-1'); } } } catch (Exception $ex) { GWTLogHelper::error(__FILE__ . " script failed.", $ex); }
$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); } } try { updateUserWikiCount($db, $u->getId(), count($sites)); GWTLogHelper::notice($u->getEmail() . " has " . (int) count($sites) . " (count updated)"); } catch (Exception $e) { GWTLogHelper::error('update ' . $u->getEmail() . " " . (int) count($sites) . " failed.", $e); } } } catch (Exception $ex) { GWTLogHelper::error(__FILE__ . " script failed.", $ex); }
<?php // example: SERVER_ID=5915 php maintenance/wikia/GoogleWebmasterToolsSync/remove_user.php --conf /usr/wikia/docroot/wiki.factory/LocalSettings.php -u example@gmail.com $optionsWithArgs = array('u'); require_once __DIR__ . "/common.php"; GWTLogHelper::notice(__FILE__ . " script starts."); try { if (!isset($options['u'])) { GWTLogHelper::error("Specify email (-u)"); die(1); } $userRepository = new GWTUserRepository(); $userRepository->deleteByEmail($options['u']); GWTLogHelper::notice(__FILE__ . " script end."); } catch (Exception $ex) { GWTLogHelper::error(__FILE__ . " script failed.", $ex); }
<?php // example: SERVER_ID=5915 php maintenance/wikia/GoogleWebmasterToolsSync/add_user.php --conf /usr/wikia/docroot/wiki.factory/LocalSettings.php -u u2 -p pass $optionsWithArgs = array('u', 'p'); require_once __DIR__ . "/common.php"; GWTLogHelper::notice(__FILE__ . " script starts."); try { if (!isset($options['u']) || !isset($options['p'])) { GWTLogHelper::warning("Specify user (-u) and password (-p)"); die; } $userRepository = new GWTUserRepository(); $r = $userRepository->create($options['u'], $options['p']); if ($r == null) { GWTLogHelper::warning("error while inserting user."); die; } GWTLogHelper::notice($r->getId() . " " . $r->getEmail() . "\n"); } catch (Exception $ex) { GWTLogHelper::error(__FILE__ . " script failed.", $ex); }