Created
July 15, 2015 20:17
-
-
Save cesargalindo/5185312541034204818d to your computer and use it in GitHub Desktop.
Display list of Edge Users missing from Dev Portal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This script presumes that you place the following in composer.json: | |
* { | |
* "require": { | |
* "guzzlehttp/guzzle": "~4.0" | |
* } | |
* } | |
* and then run composer install in that directory. | |
*/ | |
use GuzzleHttp\Client; | |
/* ==== CONFIGURATION SECTION ==== */ | |
// What org do you want to sync? | |
$org = 'ADD-ORG-NAME-HERE'; | |
// What are the credentials for an orgadmin within that org? | |
$user = 'ADDHERE'; | |
$pass = 'ADDHERE'; | |
// What's the connection string for the database? | |
// Hint: look in ~/.drush/pantheon.aliases.drushrc.php | |
//$connection = 'mysql://pantheon:[email protected]:31337/pantheon'; | |
$connection = 'mysql://USERNAME:PASSWORD@localhost/DATABASE'; | |
/* ==== END CONFIGURATION ==== */ | |
$parts = parse_url($connection); | |
$db_user = $parts['user']; | |
$db_pass = $parts['pass']; | |
$db_host = $parts['host']; | |
$db_port = $parts['port']; | |
$db_name = ltrim($parts['path'], '/'); | |
$dsn = "mysql:host=$db_host;port=$db_port;dbname=$db_name"; | |
$PDO = new PDO($dsn, $db_user, $db_pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); | |
require_once 'vendor/autoload.php'; | |
$client = new Client([ | |
'base_url' => ['https://api.enterprise.apigee.com/v1/o/{org}/', ['org' => $org]], | |
'defaults' => [ | |
'headers' => ['Accept' => 'application/json'], | |
'auth' => [$user, $pass], | |
'allow_redirects' => true, | |
], | |
]); | |
// Export missing mint developers | |
$tmp_file = '/tmp/missing-mint-developers.txt'; | |
exec('echo "Contains missing developers - ' . date("F j, Y, g:i a") .'" > '. $tmp_file); | |
// Retrieve list of all users in local db "mail" | |
try { | |
$emails = $PDO->query('SELECT mail FROM users WHERE uid > 0 ORDER by uid DESC')->fetchAll(); | |
foreach ($emails as $row) { | |
$local_users[$row["mail"]] = 1; | |
} | |
} | |
catch (PDOexception $e) { | |
echo "Error is: " . $e-> etmessage(); | |
} | |
// start with first user in the system | |
$response = $client->get('developers'); | |
$edge_developers = json_decode($response->getBody(), TRUE); | |
$total = count($edge_developers); | |
while ($total > 1) { | |
$j = 0; | |
$drupal_developers = array(); | |
foreach ($edge_developers as $edge_developer) { | |
$j++; | |
if (!$local_users[$edge_developer]) { | |
exec('echo ' . $edge_developer . ' >> '. $tmp_file); | |
echo "Missing developer: " . $edge_developer . "\n"; | |
} | |
$last_developer = $edge_developer; | |
} | |
// Get new developer list - count | |
$response = $client->get('developers?count=9999&startKey=' . $last_developer); | |
$edge_developers = json_decode($response->getBody(), TRUE); | |
$total = count($edge_developers); | |
echo "\n ###### NEW TOTAL: $total #######\n"; | |
} | |
echo "Done!\n"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment